JQuery 'Sticky Notes' integration with 'Salesforce Tasks'

Saturday, December 4, 2010 by Aslam - The Alexendra
Hi All,
Here i came up again with something interesting stuffs. I found recently one cool JQuery Sticky Notes plugin here Tutorialzine [http://tutorialzine.com/2010/01/sticky-notes-ajax-php-jquery/]. Then i came up with an idea to integration this cool feature with Salesforce Tasks.



Sorry, this time i can't share a Force.com sites link to show you a demo because this project inloves with Tasks and Users objects, that has Public Site access limitation, thats why, Here is a simple Screencast demo i created, check it out.

Click and View:
Sticky_notes_salesforce

Sticky Dashboard:


Add Note Screen:

I created this complete stuff in couple of hours so it may have many flaws. I am thinking to improve this on following points:

1) Need to push more fields (Status, Priority etc on Add note and dashboard screen for Sticky Tasks Page)
2) Reassign a task to other
3) Also, thinking to integrate this with my previous stuff (VFTalkie), which is voice enabled.
4) Thinking to integrate this with Twilio voice system also, so you no need to write your task, just call and your task will be created on Sticky home :) (Isn't it cool).
5) And many more....

If you need the code just mail me, and As always, provide me your valuable suggestions.

Thanks
Aslam Bari

Easy SF Portlets With jQuery (Project)

Tuesday, October 12, 2010 by Aslam - The Alexendra
Hi All,
With my previous experience with many projects it seems "one special" kind of requirement comes always and that always needs me and my team to build every time from scratch and takes time to complete. Yes, this is "Portlets Home" page for clients with a drag and drop boxes on a single page, each box contains different information section bla bla. Yes, requirements for different clients always differ from each other, but the BASIC building blocks are same for all. All needed a Home page with 3 or 4 column boxes with title and information. All boxes must be draggable etc. These building blocks every time needs attest 30-50 hours to complete. Some people uses ExtJs to build it, some uses jQuery and other JS Framework.



So, here i have come up with a "SF Portlets" project. The beauty of this project is , it is configurable , easy to install/setup, and you don't need to think about BASIC BUILDING BLOCKS, all is created and ready to use for you, you just need to concentrate on client extra requirement From that point where this project Ends.


I have shared this project on Code Share here:-
http://developer.force.com/codeshare/project/sf-portlets

You can also directly install the App from the below link:-
https://login.salesforce.com/?startURL=%2Fpackaging%2FinstallPackage.apexp%3Fp0%3D04t90000000Pl0v


Portlet Configuration Screen:-

You need to create at least one Portlet Config record with all given flags and fields. Also create your portlets and one Attachment for your portlet logo as shown below in this screen.


You can choose multiple themes from the Portlet Config picklist as below:



Default Theme



Redmond Theme



Black-Tie Theme



Create Different Types of Portlets as per your need
HTML
Will render whatever html you provided here as it is.



Text
Will show your text simply on screen.



URL
Will load the external data from given url (It must be Public accessible url). If you give WAP url then it must be good because that is perfect for a small porlet screen.



Query
Will run your SOQL query and show your data in tabular format (Please provide optimized and limit in your query for better load data). Query example:-

SELECT Name, Email, Phone FROM Contact ORDER BY LastModifiedDate DESC LIMIT 10



Activate/Deactivate Portlets
You can also set Activate or De-Activate any portlet which is you want or not to show on the Portlet Home using "Active" field flag(checkbox)



Here is the working demo for your view, it is hosted on Salesforce Public Sites.
http://labsprojects-developer-edition.ap1.force.com/

Future of the Project

Save Portlets State
Right now I am not storing user's drag and drop of the portlet on particular position. Right now all portlets comes as per last modified date desc order. I am planning to store their states also.


More Portlet Types
In my view, it must be very useful for basic portlets implementation with given options. I am thinking to extend it in terms of many aspects like support for more Portlet Types like:

Report
Will accept Report link and will show report details in portlet

Chart
Will accept Report link and will show its chart in portlet

Dashboard
Will accept Dashboard name and its component, and it will show that component in Portlet

Image
Will accept one Resource, Document name or link and will show that image

Attachment
Will accept one link of the attachment and will show in Portlet

Detail
Will accept a Id of the Record (Account, contact or opportunity), and will show that detail in this area

YouTube
Will accept a YouTube url and show that video in this portlet.

Feeds
Will accept any RSS Feed and show the details here.

And Much Much More…

View/Download complete documentation here:-

SF Portlets

So, give it a try, install and test it. Let me know for any feedback so that i can enhance it.



Thanks
Aslam Bari

Cool Dock Menu for your Salesforce Site

Monday, August 16, 2010 by Aslam - The Alexendra
Hi All,
Yesterday i was exploring some jQuery menus and found some cool jqDock top menu which can be used in your Salesforce Site.
Here is the link for jqDock Menu.



Here is the link for working demo which uses this jqDock menu.

jqDockDemo link

Mail me if you need its code :)

Thanks
Aslam Bari

VFTalkie : Enable your Visual Force pages to speak !!!

Monday, August 2, 2010 by Aslam - The Alexendra
Hi All,
Yesterday i was searching for some jQuery related plugins and found two very useful web services / plugins on net. Then i decided to integrate both of this services to Salesforce to get something useful.

jTalk :- Speech-enable your website!. It provides you much useful API to convert your text to speech on the fly. Go for more info here http://www.jtalkplugin.com/.

Dewplayer :- Dewplayer lecteur mp3 en flash! It provides a very cool flash mp3 player . Go for more info here http://www.alsacreations.fr/dewplayer.html.



The idea is simple. Whatever output data you have on your vf screen (Output Fields). Convert that into MP3 on run time using jTalk API and Pass it to a supporting player like Dewplayer.

Isn't it cool :)

Here is the simple demo for this integration:-

VF Talkie Account Detail

Here is the more interactive demo for this integration:-
VF Talkie Contact List

For integrating this into your VF page you just need to add VFTalkie component on your page with text as below:-

<c:vftalkie val="{!accRecord.Description}">

For getting complete project code click here.

So, make sure your speaker is on then give it a try :)

If any questions, mail me at aslam.bari@gmail.com

Hope you enjoyed.

Thanks
Aslam Bari

Salesforce Solutions Browsing in Interactive JQuery Way

Wednesday, July 28, 2010 by Aslam - The Alexendra
Hi All,
Hope you all aware of Saleforce Solutions Feature. Each solution is associated with one or more Categories which is called 'Solution Category'. Salesforce provide some basic solution browsing feature. I was thinking to implement something more Interactive UI perspective.

Then i found one jQuery solution for this here by filamentgroup.
I found it is very useful for Hierarchical Data representation. It actually an iPod style browsing categories. So i used this idea and implemented Solutions Browsing in Salesforce using this jQuery menu way But i think this can be used to implement any object records hierarchical data like Account and parent accounts, Users and their managers etc.


Here is the working demo for this:-
http://labsprojects-developer-edition.ap1.force.com/solutions_menu_demo

Try to browse AllCategory->Entertainment->Movies OR
All Category -> Breaking News -> Politics

You will see on demand filter results. For rest of the menu items i just provided all records for demo purpose.

If you need the complete code for this demo then mail me at: aslam.bari@gmail.com

Thanks
Aslam Bari

Simple Search Highlighter

Thursday, May 20, 2010 by Aslam - The Alexendra
Hi All,
Recently i faced one issue where i need to use a simple search on some table and fetch the results on screen. But the main problem i faced that how to highlight the search word in the screen in some color format. So here is the solution for that. (It is inspired from one PHP Code blog: http://www.phpro.org/articles/Highlight-Search-Words.html).

For SFDC work around, here is the solution with code:

1) Apex Class:- I used the contact for my searching example. Here is the code:-

public class ContactSearchHighlight{
public string srchArg{get;set;}
public List<Contact> lstcontact {get;set;}
public ContactSearchHighlight(){
lstContact
= [select id, name, details__c from contact where details__c != null];
}

public PageReference search(){
string srchPhrase = '%' + srchArg + '%';
lstContact
= [select id, name, details__c from contact where details__c like :srchPhrase];

for(Contact cnt: lstContact){
cnt.details__c
= highlightPhrase(cnt.details__c, srchArg);
}

return null;
}

public string highlightPhrase(string mainString, string phrase){
mainString
= mainString.toLowerCase().replaceAll(phrase.toLowerCase(), '<span class="highlight_word">' + phrase + '</span>');
return mainString;
}

}





2) VisualForce page and code for Search and highlight

<apex:page controller="ContactSearchHighlight" showHeader="false" sidebar="false">
<apex:sectionHeader title="Search Contacts" subtitle="Highlighter"/>
<style type="text/css">
h1
{
font-size
:16px;
}
.highlight_word
{
background-color
: PaleGreen;
font-weight
:bold;
font-style
:italic;
}
.searchbox
{
border
:1px solid #ccc;
font-family
:verdana;
padding
:10px;
}
.searchbox p
{
text-transform
: capitialize;
}
.hrstyle
{
color
: #f00;
background-color
: #f00;
height
: 1px;
}
</style>
<apex:form>
<apex:inputtext value="{!srchArg}"/>
<apex:commandButton value="Search" action="{!search}"/>
</apex:form><br/>
<div class="searchbox">
<apex:repeat value="{!lstContact}" var="cnt">
<h1>{!cnt.Name}</h1>
<p><apex:outputText value="{!cnt.details__c}" escape="false" />
<div style="text-align:center;color:#ccc;">
-----------------------------------------------
</div>
</p>

</apex:repeat>
</div>
</apex:page>



3) And finally here is the link to check it right now online. Just try to search something like "park", or "usa', or "and"

http://labsprojects-developer-edition.ap1.force.com/ContactSearchHighlight



Is it nice!!!


Thanks
Aslam Bari

Best way to notify your parents

Wednesday, May 5, 2010 by Aslam - The Alexendra
Hi,
Today I want to discuss you about one scenario which I came across recently and how I find the best way to do it. Here is the scenario:-

Scenario:
Suppose you have Case object which have two parent records, One is Contact Lookup and another is "MyCustomObject" object lookup. All three objects have one 'Email' field each. There is one another Custom Object called 'ChildObject' which is the child of Case object. The object structure is as below.



What we want to do is. On Insert of a new 'ChildObject' record we need to Notify Parent 'Case' Record using 'Workflow'. But the email should go to as logic below:-

If Contact.Email is filled then send email to that, otherwise if MyCustomObject.Email__c is filled then send email to that, Otherwise send email to Case.Email__c field.

Suggested Solutions and Problems:
1) Sending mail using Trigger on 'ChildObject'. Either do bunch of SOQL on all parent records and use final email to send mail within 'Trigger' OR you can use one custom email field on ChildObject it self to set email from parent in trigger and use workflow to use that email field to send emails but you can't avoid SOQLs.

2) One Before insert/update trigger on Parent Case Object. Which will set one extra Email field based on our conditions but for that you need again bunch of SOQL and logics. You can do same thing for ChildObject also.

3) Formula field on either ChildObject or Parent Case object which will filled our Email according to our logic. It is good way, it will avoid all SOQL and Logics. BUT main problem with this is that Formula Field CAN NOT be used in workflows.

My Solution (Somehow Better).

1) Create one Formula Field 'Formula_Email__c' on 'ChildObject which have following condition for fill this field

If(Case__r.Contact.Email != null, Case__r.Contact.Email, if(Case__r.MyCustomObject__r.Email__c != null, Case__r.MyCustomObject__r.Email__c, Case__r.Email__c));

2) Create one Email type field 'Case_Email__c' on 'ChildObject which will have the value from above formula field as below:

trigger on ChildObject (before insert, before update){

for(Case c: Trigger.NEW){

c.Case_Email__c = c.Formula_Field__c;

}
}

3) Thats it. See you saved so many SOQL and complex logic. Now used this final 'Case Email' field on 'ChildObject' workflow to send emails.

Is it good!!!

Thanks
Aslam Bari

Too many SOQL queries: 21

Thursday, April 22, 2010 by Aslam - The Alexendra
Hi,
Here i am going to tell you about some good practice to avoid "Too many SOQL queries: 21" error on Triggers. I got this approach from one of my good colleague "Prakash Gyamlani" (Thanks for him).

Here is some background what problem i faced:-

In one of my organization i had 7 triggers on Case. Some triggers are "before update", some triggers are on "after update". In some triggers i was also updating Case object itself based on some criteria. So it generally again calls some Triggers ( I have taken care of Recursion, that's not the problem).
After some days when i tried to save one case record i started getting "Too many SOQL queries: 21" error. I search debug logs and found that my queries are going beyond the 20. After some research i found the area which was causing the root problem.

Root Problem:-

There was one "Before Update" trigger on Case which was querying Record Types on top of the trigger like below:-

trigger SendEmailsOnCaseComment on Case (before update) {

Map<id,RecordType>mapRecordTypes = new Map<id,RecordType>([SELECT Id, Name from RecordType WHERE SObjectType = 'Case']);

for(Case cs: Trigger.NEW){
//logic
}
//extra code
}

The problem in the above code is that the query on top will always be executed whenever our control comes in this trigger. Suppose because of 7 triggers, on Case update (and inner updates), this trigger is called 6 times then we have 5 time SOQL queries extra. We only interested to execute this query one time only within the execution of a Trigger Thread.

How to solve this:-

So we should code our trigger in this way that if there are any queries which are general, not dependent on any conditions, then put those queries in a place where they can be executed only once. And Whenever we need the results we get our results always in single execution of Trigger Thread.


Code:-
The solution for above problem is to code like this:-

Make one utility class for getting record types and initialize that (Fire SOQL) in a "Static" block. In this way we will always have that soql fired only once.

public class CaseManagementUtility{
public static Map<id,RecordType> mapRecordTypes = null;
static {
mapRecordTypes = new Map<id,RecordType>([SELECT Id, Name from RecordType WHERE SObjectType = 'Case']);
}

public static Map getRecordTypeMap(){
return mapRecordTypes;
}
}


Now, in our trigger use this code like this:-
trigger SendEmailsOnCaseComment on Case (before update) {

Map<id,RecordType> mapRecordTypes = CaseManagementUtility.getRecordTypeMap();


for(Case cs: Trigger.NEW){
//logic
}

//extra code
}

Now, suppose above trigger is called 10 times (in a single execution), but SOQL query will be fired only once.


Quite simple. Isn't it.

Thanks
Aslam Bari

Twitter Search Widget Integrate With Salesforce

Monday, April 19, 2010 by Aslam - The Alexendra
Hi,
I recently came across with 'Twitter Search Widget', which is very useful for getting recent tweets for in which topic you are interested and you can embed this widget anywhere you like for example your salesforce org, public site, blogger etc.

I created one search widget for Salesforce Business Tweets and Embedded this to Sidebar of the salesforce org. See below:-



For Getting the Search Widget For your Site try this:-

1) Go To this link Twitter Widget
2) Set your search preferences
3) Get the Code and Paste into your side or blog

Thanks
Aslam Bari

PhoneML - Teleku. Lets Explore It!!!

Tuesday, March 30, 2010 by Aslam - The Alexendra
Hi,
Last day I Explored PhoneML by Teleku. It is very good "Phone Web Service API". Enterprise-grade, cloud-based RESTful Phone Web Service API for building speech & touch tone Voice and SMS phone applications! Control any phone with simple & open PhoneML XML or JSON Web responses that work with all Web programming languages.



The best part i found with Teleku is that i can easily test my application built on Teleku using "Skype" without need of any Phone etc. (My last experience was with Twilio, a very advance and cool TwiML APIs. But the applications i built on Twilio, i had to test it using a Phone, by that time they do not provide Skype support, as per my knowledge. Dont know, now they have provided or not).

So, it is very easy to build your extension applications on Teleku and test it on Skype. Here are the steps:-

1) Register for free on Teleku.
2) Make your sample application using <Speak> PhoneML as below
<phoneml><speak>Hello Dear, how are you</speak></phoneml>

3) Now you will be provided one extension number.
4) After saving your application , you will be provide some numbers to call including Skype. Just click on Skype call and you will be prompted for entering Extension number. After entering you will listen you message. Isn't it good.

Teleku Provide folloing PhoneML commands:-

i) <speak>
<speak> allows you to speak or read text-to-speech (TTS) sentences and data to the caller

ii) <play>
<play> allows you to play MP3, WAV, or VOX audio files to the caller.

iii) <input>
<input> allows you to specify input options (grammars) to collect from the caller. These options can include both numeric touch tone options or words for speech recognition (ASR). Values are separated by commas. If you are interested in allowing the caller to enter or say a string of digits, you may specify free form entry as <input>digits<input>.

iv) <record>
<record> allows you to record an audio file and post it to your desired URL.

v) <transfer>
<transfer> allows you to transfer the call to another number. Note: ";postd=ppp1234" or simply "x" can be added to the dial string to represent pauses in dialing.

vi) <goto>
<goto> allows you redirect the flow of the voice application to another URL for processing.

vii) <hangup>
disconnects the call. You may specify a URL of your application to call for processing within the tags.

So go and Explore yourself:-

Teleku


Now my next plan is to integrate this with Salesforce Off Course !!!

Thanks
Aslam Bari


RSS Feed Power With Salesforce

Tuesday, March 9, 2010 by Aslam - The Alexendra
Hi All,

Here i am again with something interesting thing with Salesforce.

Do you think how it is cool if our Salesforce Organiztion's information will be displayed on variety of Adhoc Web clients. For example I want to display my open cases from my organiztion on iGoogle Home page as a Gadget, my Blackberry or iPhone mobile or My Gmail , Yahoo page or GTalk or Google Reader and so on .... at the same time and same information. Isn't it cool!!!


Yes this is the Power of RSS Feed.


What Is RSS and Why to use it.

RSS was designed to show selected data.

Without RSS, users will have to check your site daily for new updates. This may be too time-consuming for many users. With an RSS feed (RSS is often called a News feed or RSS feed) they can check your site faster using an RSS aggregator (a site or program that gathers and sorts out RSS feeds).

Since RSS data is small and fast-loading, it can easily be used with services like cell phones or PDA's.

Web-rings with similar information can easily share data on their web sites to make them better and more useful.

So, here in this tutorial i am going tell you how you can convert Case Information like your case number with priority and a small Case summary from your Salesforce Organization into RSS Feed and then how you can consume these feeds into your iGoogle/My Yahoo home page or any variety of consumers.

1) Make a contoller with following code (RssFeedController):-

public class RssFeedController{
public List<Case> caseList {get;set;}
public RssFeedController(){
caseList = [SELECT Id, CaseNumber, Subject, Priority from Case];
}
}

2) Make a Visual Force with following code (RssFeedGenerator):-
<apex:page contenttype="text/xml" sidebar="false" showheader="false" controller="RssFeedController">
<rss version="2.0">
<channel>
<title>SFDC Case List</title>
<description>The List gives you all cases open in Your SFDC Org</description>
<link>https://ap1.salesforce.com/500?fcf=00B90000001SEXr</link>
<apex:repeat value="{!caseList}" var="cnt">
<item>
<title>{!cnt.CaseNumber} - {!cnt.Priority}</title>
<description>{!cnt.Subject}</description>
<link>https://ap1.salesforce.com/{!cnt.Id}</link>
</item>
</apex:repeat>
</channel>
</rss>
</apex:page>

3) Enable sites in your organization and add VF page/Contoller to you sites. Also provide read permission on Case object for sites.

4) Now open your sites with our VF page like this:-
http://labsprojects-developer-edition.ap1.force.com/rssfeedgenerator

5) What you see on the page? Your page is converted to a RSS Feed Generator. Isn't it good!!!.
See the above section is for RSS Feed subscribtion area. The below is your feeds.


6) Now you can subscribe this page to variety of Feed Readers like google, yahoo , blogs etc.
For example click on My Yahoo or google from the top dropdown and click on subscribe. It automatically add one Feed Gadgets to your My Yahoo or iGoogle page like below:-



7) Now you can also play with it and add the above rss feed url to any consumer which support RSS Reading like blackberry, iPhone, GTalk, blogs or even your custom RSS Reader for you website.
For Example:-
a. iGoogle





b. My Yahoo


c. GTalk: There are many variety of free available bots which you can add into your gtalk for RSS Feed reading.

d. BlackBerry and iPhone: You can easily consume your rss feeds into your blackberry and iphone

e. Google Reader: Its easy to embed your rss feed into your Google Reader and let the worlds know about it

f. SMS: You can make one Google Channel with your RSS Feed. Then make it SMS enabled and whoever subscribe it , will get notified whenever a new feed comes via SMS.

g. Blog: There are many gadgets which are available for feed reading and you can just plug them into your blog easily into sidebar etc.

h. Website: Of course you can parse your rss feed with any language and add to your website.

So without login or not much code we can view useful information from our salesforce org to any of our client consumers. so, Play with this Good Feature.

Thanks
Aslam Bari

Salesforce JQuery AutoComplete Dropdown

Thursday, March 4, 2010 by Aslam - The Alexendra
Hi All
In previous 3 months i came across same type of Task in different projects. That is "AutoComplete Dropdown Textbox" for Account, Contact or different types of SObjects (Custom Objects).

I used JQuery Autocomplete plugin for this task here. It was working perfectly. But i was tired to do same stuff again and again from scratch like uploading jquery resources (js, css), making component, making class, integrate etc.

Then i decided to make it as a installable Package so that anybody can install it easily and do changes according their needs. You can install package from here

https://login.salesforce.com/?startURL=%2Fpackaging%2FinstallPackage.apexp%3Fp0%3D04t40000000U2VX

This package contains following components:-

1) Resources:- JQueryDialog, popupcss, popupjs
2) VF Page:- Search, AutocompleteTest
3) Apex Class:- ACSearchController
4) Component:- AutoComplete

The "AutoComplete" VF Component is main part and contains all js, css and client side login. Search page and ACSearchContoller is your Database related stuff means which SObject you need to query and output format etc. There is a Test VF Page "AutocompleteTest". After installing you can run this VF page, it contains one simple sample for Autocomplete Example for Contact object.

Give it a try!!!

Thanks
Aslam Bari

SFDC Multilingual Page Now Easy

Tuesday, March 2, 2010 by Aslam - The Alexendra
Hi All,
Today I am going to show you quick way by using small piece of code you can turn you complete page in the language you want for end user. There is no need of any Translation configuration or anything...etc. I am going to do this using simply google translation apis. Lets go together:-

1) Identify elements on your page which you want to translate. For example label, h2, div, p tags etc.
<label>First Name<label>

2) Use below code to translate all "Label" on your page. The below code is converting english to french:-


<script src="http://www.google.com/jsapi" type="text/javascript">
</script>
<script type="text/javascript">

google.load("language", "1");

function initialize() {
allLabels = document.getElementById("maindiv").getElementsByTagName("label");
for(var i = 0; i < allLabels.length; i++){
translate(allLabels[i]);
}

}

function translate(lbl){
var text = lbl.innerHTML;
google.language.translate(text, "en", "fr", function(result) {
if (!result.error) {
lbl.innerHTML = result.translation;
}
});
}
google.setOnLoadCallback(initialize);
</script>

3) Now make one Dropdown with the language list you want to show user to select and convert:-


<select onChange="changelanguage()" id="languagelist">
<option value="en">English</option>
<option value="de">deutsch</option>
<option value="pt">português</option>
<option value="fr">français</option>
<option value="ja">日本語</option>
<option value="ar">عَرَبيْ</option>
<option value="it">italiano</option>
<option value="ru">pусский</option>
<option value="po">polski</option>
<option value="zh-CN">中文</option>
<option value="es">español</option>
<option value="ko">한국어</option>
<option value="nl">nederlands</option>
<option value="hi">हिन्दी </option>
<option value="el">Ελληνική</option>
<option value="ro">română</option>
</select>

4) JS method to trigger the this:-

<script>
function changelanguage(){
var language = document.getElementById("languagelist").value;
window.location.href = "/apex/Translator?language=" + language;
}
var lang = "{!$CurrentPage.parameters.language}";
var language = document.getElementById("languagelist");
language.value = lang;
</script>


5) Conclusion and Full Example:-
Suppose you want to make a customer Contact (Standard Object) form, see the below code of Visual Force Page and screenshot for example:-


<!--
Name : Translator
Author : Aslam Bari
Last Modified : 02-March-2010
Version : 1.0
Description :
-->
<apex:page standardController="Contact">
<!-- Transalator Code -->
<script src="http://www.google.com/jsapi" type="text/javascript">
</script>
<script type="text/javascript">

google.load("language", "1");

function initialize() {
allLabels = document.getElementById("maindiv").getElementsByTagName("label");
for(var i = 0; i < allLabels.length; i++){
translate(allLabels[i]);
}

allH2 = document.getElementById("maindiv").getElementsByTagName("h2");
for(var i = 0; i < allH2.length; i++){
translate(allH2[i]);
}

allH1 = document.getElementById("maindiv").getElementsByTagName("h1");
for(var i = 0; i < allH1.length; i++){
translate(allH1[i]);
}
}

function translate(lbl){
var text = lbl.innerHTML;
google.language.translate(text, "en", "{!$CurrentPage.parameters.language}", function(result) {
if (!result.error) {
lbl.innerHTML = result.translation;
}
});
}
google.setOnLoadCallback(initialize);
</script>

<!-- Transalator Code -->



<apex:form>

<div style="width:90%;text-align:left" id="maindiv">
<apex:sectionHeader title="Contact Form" subtitle="Multilingual Contact Form"/>
<label>Please select a language for translation the page: </label>
<select onChange="changelanguage()" id="languagelist">
<option value="en">English</option>
<option value="de">deutsch</option>
<option value="pt">português</option>
<option value="fr">français</option>
<option value="ja">日本語</option>
<option value="ar">عَرَبيْ</option>
<option value="it">italiano</option>
<option value="ru">pусский</option>
<option value="po">polski</option>
<option value="zh-CN">中文</option>
<option value="es">español</option>
<option value="ko">한국어</option>
<option value="nl">nederlands</option>
<option value="hi">हिन्दी </option>
<option value="el">Ελληνική</option>
<option value="ro">română</option>
</select>
</select><br/>
<label>This is a demo page to show the power of Google Transation API with Force.com :-</label>
<apex:pageBlock title="Please fill the form">
<apex:pageBlockSection>
<apex:inputField value="{!Contact.FirstName}"/>
<apex:inputField value="{!Contact.LastName}"/>
<apex:inputField value="{!Contact.Email}"/>
<apex:inputField value="{!Contact.Phone}"/>
<apex:inputField value="{!Contact.Title}"/>
<apex:inputField value="{!Contact.Birthdate}"/>
<apex:inputField value="{!Contact.Address__c}"/>
<apex:inputField value="{!Contact.Description}"/>
</apex:pageBlockSection>
</apex:pageblock>
</div>

</apex:form>
<script>
function changelanguage(){
var language = document.getElementById("languagelist").value;
window.location.href = "/apex/Translator?language=" + language;
}
var lang = "{!$CurrentPage.parameters.language}";
var language = document.getElementById("languagelist");
language.value = lang;
</script>
</apex:page>


Screen Shots:-
Form in Hindi---

Form in Arabic---


And many more....

Isn't it a quick way to do interesting thing :)

Aslam Bari

Getting Salesforce Organization Server Url

Tuesday, February 23, 2010 by Aslam - The Alexendra
Hi All,
Recently i faced a situation where i need to get Current Org Server URL (Host Url) in Trigger. I know we can get it easily in VF or Apex Class, but what about in Trigger or some future method? One of my colleague Mr. Yogesh Rankawat suggested me a very good way to do this easily (Thanks to him). So here i am going to tell you this method.

1) Create a simple class with following code:-
public class HostUrl{
public string url {get;set;}
public HostUrl(){
url = ApexPages.currentPage().getHeaders().get('Host');
}
}


2) Create a even simple VF page with following code:-
<apex:page sidebar="false" showHeader="false" controller="HostUrl" contentType="text">{!url}</apex:page>

3) Now just simply use below code to get the Server URL

PageReference pg = Page.HostUrl;
String SERVER_URL = pg.getContent().toString();

Isn't it too simple!!! If you know even better way, then please share.

Thanks
Aslam Bari

Latest From My Blogs

Tuesday, February 16, 2010 by Aslam - The Alexendra
Hi Friends,
Here are my some latest blogs on my projects related to Salesforce:-

1. Salesforce Pinger
Link

2. Salesforce Bot
Link

Thanks

Python Integration with Salesforce (Windows)

Thursday, January 28, 2010 by Aslam - The Alexendra
Hi,

Recently I was challenged to access Salesforce from a Python script. Like any Python beginner I had some problems setting the Python environment up correctly and then connecting to Salesforce. However, after much trial and error I succeeded, so I am here to share my Python-Salesforce journey. Lets walk through it together :)

Step 1: Get the latest Python code (I used Python2.6) and install it on your disk at "c:\Python26"

Step 2: Download the suds from https://fedorahosted.org/suds Extract suds in a folder such as "C:\Python26\suds"

Step 3: Download the latest setuptools for your python(2.6) from here http://pypi.python.org/pypi/setuptools#downloads. Choose the "setuptools-0.6c11.win32-py2.6.exe (md5)" for windows and install it in your python directory (Default C:\Python26)

Step 4: Open the command prompt, go to the suds directory and issue this command:-

c:\Python26\suds> C:\Python26\python.exe ./setup.py install

Suds will install successfully

Step 5: Now install Apache or use your existing apache server if you have one. The only important thing here is the httpd.conf file. So do the following main changes in your apache httpd.conf file:-

a) Find the line "Options Indexes FollowSymLinks" and replace it with

Options Indexes FollowSymLinks +ExecCGI


b) Find the line "AddHandler cgi-script" and replace it with

AddHandler cgi-script .cgi .py


I think that's it. If you still have issues setting up your Apache server properly then email me and I'll be happy to provide you my httpd.conf.

Step 5: Now start your Apache server and test a simple python script. Create a file test.py and put it on your server such as at "C:\wamp\www".

-------------------------------------------------------------
#!c:/Python26/python.exe -u
import datetime
import re
import string
import sys
import unittest
import logging
import test_config


logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)



print "Content-type: text/html"
print

print "Hello1"


------------------------------------------------------------


open browser and hit the url like
http://localhost/test.py

Hurray!!! you have seen "Hello1". (If not :(, try again being careful with each step)


Step 6: Download your Enterprise WSDL from your Salesforce organization and put it on your server folder where you can access it easily

http://localhost/pythontest/enterprise.wsdl.xml

Step 7: Download "salesforce-python-toolkit" from http://code.google.com/p/salesforce-python-toolkit/downloads/list .

Extract it to a folder like "sforce". You must put it in your classpath for python. However, as I was new I didn't spend much time on this and for the sake of expediency I put this "sforce" folder into "C:\Python26\Lib".

Open the test_config.py file from this folder and put your organization's Username and Password properly. Save this file.

Open your test.py file again and now let's perform some basic query examples:

---------------------------------------------------------------------------

#!c:/Python26/python.exe -u
import datetime
import re
import string
import sys
import unittest
import logging
import test_config


logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)

from sforce.enterprise import SforceEnterpriseClient

from suds import WebFault

print "Content-type: text/html"
print

h = SforceEnterpriseClient('http://localhost/pythontest/enterprise.wsdl.xml')
h.login(test_config.USERNAME, test_config.PASSWORD, test_config.TOKEN)

result = h.queryAll('SELECT Account.Name, FirstName, LastName FROM Contact LIMIT 2')
for record in result.records:
print record.FirstName, record.LastName
print record.Account.Name

result = h.logout()
---------------------------------------------------------------------------------------

In the above example, we queryed the Contact object. The important thing to note here is that the enterprise wsdl xml is referenced in your script. Python accepts the filename in full url format, so please specify it as either http:// or file:/// format.

Open browser and run the code. The results will appear on your screen.

Hope you enjoyed our little journey....

For any further questions email me aslam.bari@gmail.com


Thanks
Aslam Bari

IE6 Select Ovelapping Dynamic popup Div Solution

Tuesday, January 19, 2010 by Aslam - The Alexendra
Hi All,
Many times i found the problem with Dynamic popup on js event showing on page in IE6. If you have any Select element on the page, your div will not come on top of this Select. So here is the IFrame hack for this problem:-

// Outer Div -->
<div id="popupParent" style="background-color:#fefdb9;
width:346px;
position:absolute;
display:none;
top:0px;
overflow:hidden;
z-index:20;
">

// IFRAME HACK -
<iframe id="menu4iframe" src="javascript:'';" marginwidth="0" marginheight="0" align="bottom" scrolling="no" frameborder="0" style="position:absolute; left:0; top:0px; display:block; filter:alpha(opacity=0);height:300px"></iframe>

// INNER DIV FOR YOUR COntents -->
<div id="popup" style="border:thin solid #ffa500;padding:2px;overflow:hidden;background-color:#fefdb9;"/>
</div>

On any js event you just need to set your inner html in 'popup' and set the display property of 'popupParent' div.
Thats It.

Thanks