Friday, January 25, 2013

To integrate Salesforce with an External database

Scenario :-

To interact Salesforce with any external database like SQL server to get the real time data into the Salesforce for the Sql server database.

There is no facility to connect directly to your database with salesforce. However, using an integration service (or web-services, REST API, etc.), you can connect or sync to an external database.

Please refer to 2 below mentioned points :-

1. Integrate the data into and store the data using the Web Services API and then build your Visualforce page on that data as needed or you could use the Data Loader to update the data. More Info

2. Web-service enable your backend data and have apex make "callouts" (web service calls) to retrieve the data. There are some constraints about request and response size so please refer to below mentioned links for better understanding :-

2.1) If your web service provides a WSDL, you can try to import it to Apex and Apex will auto-generate the apex classes. More Info here


2.2) You can construct the web service message using the HTTP (RESTful) apex classes.More Info Here

Other APIs which can be referred to integrate Salesforce with other databases :-

  • Salesforce Web Services API 
  • Salesforce Bulk API 
  • Salesforce Rest API 
8 different APIs, click on it to find out which API should you use?

Following are the mentioned list of integration services:

1) Informatica Cloud
2) Cast Iron
3) SnapLogic
4) Boomi
5) JitterBit
6) Sesame Relational Junction

Wednesday, October 3, 2012

To insert image into Rich Text Area field dynamically using Apex

I would like to give you a brief that whenever a user wants to upload any file (Image) and wants that it directly get inserted into the Rich Text Area field.

So I have developed a code wherein any user can upload any image file and provides the document name where it will stored and get dynamically inserted onto the Rich Text Area field.

Kindly refer this & modify it according to your requirement and test it before deploying it in your Org.

***************Apex Class***************

public class ImagInsertionIntoRichText

public String naam{get;set;}
public ID folderid{get;set;}
public Blob file{get;set;}

public void insrt()

Document d= new Document(); = naam;
d.body=file; // body field in document object which holds the file.
d.folderid='00l90000000inFEAAY'; //folderid where the document will be stored insert d;
insert d;

Case cs = new Case();
cs.FirstExample__Comments__c = '<img src="''" width="500" height="281"></img>'; //FirstExample is namespace & Comments__c is Rich Text Area field
cs.Status = 'New';
cs.Origin = 'Web';
insert cs;
***************VF page***************

<apex:page controller="ImagInsertionIntoRichText">
<apex:outputLabel value="Document Name"></apex:outputLabel>
<apex:inputText id="name" value="{!naam}"/>

<apex:outputLabel value="Upload Document"></apex:outputLabel>
<apex:inputfile value="{!file}"></apex:inputfile>

<apex:commandButton value="Save" action="{!insrt}" id="save"/>
NOTE :- If you have a existing image stored in the Document, then you can only refer to below mentioned snippet of code only :-

Case cs = new Case();
cs.FirstExample__Comments__c = '<img src="" width="500" height="281"></img>';
cs.Status = 'New';
cs.Origin = 'Web';
insert cs;

Monday, October 1, 2012

To invoke Apex using the AJAX toolkit & to remove the HTTP 500 error when showHeader="false"

The AJAX toolkit includes built-in support for invoking Apex, so I have tried to call a webservice method through sforce.apex.execute . The execute method takes primitive data types, sObjects, and lists of primitives or sObjects.

To call a webService method with no parameters, use {} as the third parameter.

I have developed a sample code, kindly refer this:-

---------------------------VF page ------------------------------------

<apex:page sidebar="false" showHeader="true" >
         <script src="/soap/ajax/15.0/connection.js" type="text/javascript"></script>
         <script src="/soap/ajax/15.0/apex.js" type="text/javascript"></script>

<script type="text/javascript"> 
function sendUserName(){
                      //FirstExample is namespace
                     //Additionthrughsforce is ClassName
                    //addition is methodname
                   //third parameters are the argument sent to the method
var res = sforce.apex.execute("FirstExample.Additionthrughsforce","addition",{numOne:4,numTwo:5});
return false;
<apex:commandButton onclick="sendUserName();" value="Call"/>

----------------------------Apex Class----------------------

global class Additionthrughsforce {
webservice static Integer addition(integer numOne, integer numTwo){
return numOne + numTwo;

****Please Note****

When showHeader="true " ,it was successful to call an public webservice method but when showHeader="false" , it fails with the status code as 500.

I have received an 500 (Internal Server Error) in the javascript console (Chrome) when invoking Apex from sforce.apex.execute.

Workaround when showHeader="false" would be to add
**var __sfdcSessionId = '{!GETSESSIONID()}';**

Tuesday, September 25, 2012

To get "probability" field values assigned automatically when selecting "Stage" field on opportunity through VF page

When selecting the "Stage" field on creating new Opportunity record through standard page , "probability" field get values automatically.

But when you access both the fields using inputField in VF page ; it do not gives the values automatically .

For e.g :- just copy\paste this code in VF page and try to select the "Stage" field ; it will not render the value of Probability field.

<apex:page standardController="Opportunity">

<apex:inputField value="{!Opportunity.StageName}"/>
<apex:inputField value="{!Opportunity.Probability}"/>