Change Email Utility - Salesforce

Thursday, October 11, 2012 by Aslam - The Alexendra
Hi All,
Here i am introducing one utility created by me. It is used to change the email address of salesforce org. You must have username, password and security token for the org. 




How to access utility?
You can access this utility from my site, here is the url:

Why and When you need this?
I recently came across one situation when i deadly need this utility. One of my colleague recently setup one new salesforce org. He given his username, password, email for the org. He completed his work and sent me details about username, password, security token as well. After couple of hours, when i tried to login and test from my home, i was unable to login because my IP is not white listed. I called my colleague, but his phone was off, and its DEADLINE for me to give this info to client to show him all the work. My IP was not white listed so i can't login, the email address assigned to org was for my colleague , so i even can't get the activation code. What to do?
Then i thought to create this utility.

Benefits:
You can change email address of the user of the salesforce org. You must know username, password and security token. This utility only send you a Email Change notification. You will get one email. You can accept that verification email change. After that when you try to login from browser using username and password, then you can easily get verification code of the org as your email address is now changed for given org.

Let me know your thoughts on this utility.

Thanks
Aslam Bari

OAuth Token as Salesforce SessionId in SOAP API (PHP)

Sunday, October 7, 2012 by Aslam - The Alexendra
Hi All,
Most of the time developers who write applications in php/java or any other language, using salesforce soap APIs (partner wsdl or enterprise wsdl), they hard-code the username/password and security token in their code or in a property file. But there is one issue in this approach, anytime, if your org password or security token get change, your application may down. You have to update the credentials in your code or property file on server to get your application work.

One alternate solution for this issue is to use OAuth token in your code and write one automated code which will refresh your oauth token whenever it gets expired. The approach which i am going to tell in few moments has a benefit that you don't have to modify your code much. The place where you setting your sessionid, you just need to change that place, instead of getting sessionid from login method, you simply need to change with oauth token way.

Here is a complete process to achieve this:


1) Go to your org, Setup->Remote Access, make New remote access entry there for your application. Give return url for the file which will get oauth code returned. In my example, i used this url
http://localhost/oauthsample/tokenprint.php




You will notice that you will get Consumer key and Consumer secret.

2) Make one php file at this location oauthsample/tokenprint.php with below code. The purpose of this code is simply print the oauth code.
<?php var_dump($_REQUEST); ?>


3) Now use your browser, prepare this url and invoke from address bar of browser
https://login.salesforce.com/services/oauth2/authorize?response_type=code&client_id=<your_consumer_key>&redirect_uri=http://localhost/oauthsample/tokenprint.php
 

As soon you invoke this url, you will see the generated oauth code on screen, copy the "GENERATED CODE" from the browser window.

4) Now use following html code, run it in your browser, by simply double click, fill the values in each field.


<form method="post" action="https://login.salesforce.com/services/oauth2/token"> <input type="hidden" name="grant_type" value="authorization_code"/> <table> <tr> <td> GENERATED CODE </td> <td> <input type="text" name="code" /> </td> </tr> <tr> <td> CONSUMER KEY </td> <td> <input type="text" name="client_id" value=""/> </td> </tr> <td> CONSUMER SECRET </Td> <td> <input type="text" name="client_secret" value=""/> </td> </tr> <tr> <td> REDIRECT URL </td> <td> <input type="text" name="redirect_uri" value="http://localhost/oauthsample/tokenprint.php"/> </td> </tr> </table> <input type="submit" /> </form>











5) After you execute this, you will get xml output on screen something like this:





Here you will get two important things, one Refresh Token and second "access token".

6) Now, in your PHP/Java code you need to replace your session id with this access token. There is another thing in your code "server url", this you need to hard code something like below (make sure to use instance url of your org) :

$mySoapClient = $sfConnection->createConnection('partner.wsdl'); $serverUrl = "https://ap1.salesforce.com/services/Soap/u/25.0/00D90000000Abcd"; $sessionId = "<<ACCESS TOKEN>>"; $mylogin = $sfConnection->attach($serverUrl, $sessionId);



7) Now, how to deal with expired token? For that you need to either make a separate method for it, or simply you need enclosed you code in try, catch block and look for INVALID SESSION exception. That exception will come whenever you try to access server contents and your token is expired. So the idea is, whenever that happen , simply catch that exception and use below code to get new access token. In below code, simply replace the different fields with your org info like consumer key, secret and important "REFRESH TOKEN" which we got in step #5.


<?php function getNewToken(){ try{ $url = 'https://login.salesforce.com/services/oauth2/token'; $fields = array( 'grant_type' => "refresh_token", 'client_id' => "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 'client_secret' => "xxxxxxxxxxx", 'refresh_token' => "xxxxxxxxxxxxxxxxxxxxxxxxxxxx" ); foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } $ch = curl_init($url); //set the url, number of POST vars, POST data curl_setopt($ch,CURLOPT_POST, true); curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //execute post $result = curl_exec($ch); //close connection curl_close($ch); $json_a=json_decode($result,true); return $json_a; }catch(Exception $e){ var_dump($e); } } ?>

You can simply call this method getNewToken() to make new token whenever needed.

You are now all set, now you don't have to worry about user credentials updation or revealing it.

Let me know if you face issue in any step.

Thanks
Aslam Bari

Easy SF Pagination Tool

Sunday, July 22, 2012 by Aslam - The Alexendra
Hi All,
As most of you must know that Salesforce recently introduced "OFFSET" keyword in SOQL. This feature makes implementation of pagination very easy and effective. Now there is no need to query and store all the records in memory. So it is truly a light weight. So here i have implemented one pagination tool here which is made on "Contact" object. If you want to make it for your custom object, then it is very easy to modify code to work with any object.





You can see demo here for this implementation.
http://labsprojects-developer-edition.ap1.force.com/sf_Pagination

Here is the link for download the package.
https://login.salesforce.com/packaging/installPackage.apexp?p0=04t90000000QEP0

Let me know if you think some kind of enhancement in this.

Thanks
Aslam Bari

FTP Images in Salesforce Lookup Dialog

Friday, July 6, 2012 by Aslam - The Alexendra
Hi All,
Recently one of my clients needed one product selection lookup dialog with product images in it. The requirements were as below:

1) Images must not be stored in Salesforce, they want to store images in their own FTP server
2) When user click on create new record, user can select Product from lookup dialog, the same time, in product dialog, user can see the images respective to that particular image. So that it will be easy for user to judge the selection.

So, here is the solution i came up with.

1) Store your images in remote FTP server in a folder, for example, i saved my product images at following location:
http://labs.aslambari.com/products/

2) Give images some unique name similar to ProductCode field of your products like CM_111.jpg, CM_222.jpg, CM_333.jpg etc







3) Now create one "Product Image" formula (text) field on product object like below:

IMAGE("http://labs.aslambari.com/products/" & ProductCode & ".jpg", ProductCode)

4) Add this field into your product lookup dialog layout (Search layouts)

5) Now, whenever you will click on any Product lookup field in your org, you will simply see the product image of that particular product code.

Please check the live demo here.
http://labsprojects-developer-edition.ap1.force.com/Product_Selection

Click on Product lookup field, Select "Product Family" filter , equals to , "Camera" value. You will see all products with images. See below screen shot.



Hope this will help some developers to achieve this kind of requirement sometime.

Thanks
Aslam Bari

Google Transliteration component for Salesforce

Wednesday, March 21, 2012 by Aslam - The Alexendra
Hi All,
Recently I had a requirement where client needs easy way to type details in both English/Hindi language in Standard Salesforce screens. For example, there are call center agent users. They use Salesforce Case screen to type whatever detail they get from end customer. Client needs that agent can type details or resolution in both English and Hindi language. So, i come up with one solution here. I used "Google Transliteration" JS API to achieve it and attached this to standard description field for Case Edit screen.



I found this is useful for many others people or developers. So I come up with one common component solution for this. Here is a screen cast you can see this in Action.

http://screencast.com/t/J5OrRMAR

How to install:

1) Download the "Google Transliteration Support" Home page component code from here http://labs.aslambari.com/google_transliteration_support.txt
2) Make one "Narrow Side Bar" html component in your SFDC org and put the code there.
3) Enable this component to Active Home page layout (Make sure it will be visible on all pages in sidebar)
4) Some settings you need to take care (or need to change)

Language: You can see the line of code "google.elements.transliteration.LanguageCode.HINDI". This is the target language. You can change it if you want the native language according to your need.

Field Id: You can see the line of code "opp14". This is the field id of "description" field of Opportunity Edit Screen. You can find the any field id (textarea/text) of the object which you want to make transliteration support. And you need to give that id here.

Extra feature: There is one extra hidden feature here. While you are typing you can toggle between language "Ctrl + g" shortcut keys. But be sure this is not synch with Button on left side (I did not get much time for that, so left that). But this is very convenient for a agent to switch between two language using shortcut keys.

Let me know your thoughts once you able to use it.

Thanks
Aslam Bari

TechShare Cloud Forum Launched

Tuesday, March 13, 2012 by Aslam - The Alexendra
Hi All,
I am pleased to inform that I have created a very nice and simple forum where you can post your questions regarding Salesforce and other technology.



Please post your questions there to get answers quickly.

forum.aslambari.com


Thanks
Aslam Bari

Light Weight SF force.com chat plugin for sites

Tuesday, February 14, 2012 by Aslam - The Alexendra
Hi All,
Here, I am going to introduce the "Light Weight SF force.com chat plugin for sites".

This is easy to install and setup in your force.com site and easy to use. The positive thing is that it saves data in your native salesforce object for your review. This is just a demo app, if one want, he can extend this app to make more robust.



1) You can simply install it from here:
https://login.salesforce.com/packaging/installPackage.apexp?p0=04t90000000Q0Re

2) After deploy, you can simply access the first page by /apex/JoinChat It will ask you to click on join now link, if you already logged in before in chat room, you will be redirect to chathome page

3) If you not logged in, you will be redirected to /apex/chatlogin page, here you can give a name for yourself to use in chat room

4) To go chat room, you can call this page /apex/chathome Here you can see existing public people who are logged into same chat room To best use , you need to setup all 3 pages on public force.com site.

Here is a demo hosted on my site:
i)JoinChat
http://labsprojects-developer-edition.ap1.force.com/JoinChat

ii) ChatLogin
http://labsprojects-developer-edition.ap1.force.com/chatlogin

iii) ChatHome
http://labsprojects-developer-edition.ap1.force.com/chathome

Note: For automatic updates, due to too much request i have set 30 seconds auto update for chat

There are chances of more enhancements, but its just a start :)

Thanks
Aslam Bari