Apex Toolkit for Salesforce

Saturday, July 16, 2011 by Aslam - The Alexendra
Hi All,
Its a long time since I last posted :). So i am back with something interesting and useful contents again.
Most of us known that whenever we want to connect with any salesforce org and do query the data with any langugae, salesforce gives us some toolkit like PHP toolkit, Java toolkit, Ruby Toolkit, Flex Toolkit etc. But what when we want to connect with a remote Salesforce instance within salesforce only, using native Apex language. People use many alternate to achieve it, some uses partner wsdl to generate apex or some uses javascript toolkit. But I find them not easy to use and not easy to setup and they did not fit in my need.
So I come up with my own Apex Toolkit for Salesforce :)




Its easy to install package. You can install it from here:
https://login.salesforce.com/packaging/installPackage.apexp?p0=04t90000000Priq

For successful connectivity to any remote instance one entry for that salesforce server TYPE must be there in your remote site setting. I have by default included in package (NA1 to NA7) server url for salesforce. You can add more like (CS1 - CS9, NA1 - NA11, AP1 - AP10). For example see the below screen shot how i added most likely used server instances in my remote site settings. There must be 20-25 possible entries at most in my opinion.



It is very easy to use with only simple some lines of code to login and do a query to remote instance as below:

SFConnectionController controller = new SFConnectionController();
LoginResult loginResult
= controller.login(username, password, securityToken);
Response response
= controller.query('select Name, Email, Phone, MailingCity, MailingCountry from Contact', loginResult);
for(Record row: response.data.records){
string Name
= row.getFieldValue('Name');
string Email
= row.getFieldValue('Email');
string Phone
= row.getFieldValue('Phone');
string MailingCity
= row.getFieldValue('MailingCity');
string MailingCountry
= row.getFieldValue('MailingCountry');
}


There is one demo page and controller in package which shows how to use this functionality.
SFConnectionDemo
SFConnectionDemoController

The toolkit is just a start and gives users facility to do login and do simple queries on objects. One can easily extend this for better version. If you want to contribute in this, i have shared this project as open source here:

http://code.google.com/p/apex-toolkit-for-salesforce/

Here is one running online demo which shows how this package works. Just give your developer/production org's username, password (or securityToken as well), and click on search button. It will fetch the contact records from your organization and will display in table below.

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

Hope you will like it :)
Mail me for any configuration or setup issues and for feedback.

Thanks
Aslam Bari

15 comments:

YoAfzal said...

Nice idea!

Afzal

Abdul Vahid said...

hmmm Really Good :)

李京海 said...

that's something I've been waiting for..., a question, how did you work out the Salesforce soap/xml request/response structure ? Thanks

Chris O said...

Salute Aslam,

I've Just used the demo, this is really good!

-Chris O Davies

Abhay said...

Hi Aslam,

Good Work... Keep it up...

Abhinav Gupta said...

Creative work Aslam, I liked it. Seems you are doing something similar to Ajax Toolkit in Apex ?

Aslam - The Alexendra said...

Hi All,
Thanks for all your compliments. It seems people waiting for this long time and its a good start to make this toolkit mature and rich for all of your help.

Thanks

harveer said...

its very helpful thanx dear

Pete 'Fifedog' Fife said...

Hum... yet again something that makes my head hurt but I see the value of this. Ability to connect to your instance without the need for always downloading the WSDL of your own instance.

Reena said...

Hey Aslam .. Great job boss

Unknown said...

Very nice of writing - I appreciate your efforts

Find of Salesforce finding in here

http://www.forcelabs.net

Reena said...

Hey Aslam,

Its really helpful... I recently had such requirement and this worked like a bang.......

Great work .

Thanks,

Anonymous said...

Hi Aslam,

this is very helpful code.. now i am stucked with how to insert record using your class like here you have shown for 'select' query. Can you please help me in this with some sample 2-3 line code..just push me :)

Unknown said...

Hi Alsam,

we dont have the security token enabled to our org,
i am not able to login since andgetting error.

can you help me with this
thanks

P@L@K said...

Hi Aslam,

Does this support child queries as well?

Thanks & Regards,
Palak

Post a Comment