How to do Integration of Salesforce with Ruby on Rails?
- 6 minutes
- 3082
Salesforce integration with ROR creates a Connected app in our salesforce org.
How to Create Connected Apps in Salesforce
To create Connected Apps in Salesforce, do the following:
Log in to Salesforce as an administrator.
In the drop-down list of the account (in the upper-right corner), select Setup.
In the left-hand pane, go to App Setup > Create >Apps.
In the Connected Apps panel, click the New button.
On the New Connected App page, fill the following required fields under Basic Information:
Connected App Name. For example, REST Integration.
API name. For example, REST_ Integration.
Contact Email.
Go to API (Enable OAuth Settings), and select Enable OAuth Settings.
In the Callback URL field, enter https://login.salesforce.com/services/oauth2/token
In the Selected OAuth Scopes field, select Access and manage your data (api), Full Access (Full), Perform request on your behalf at any time (refresh_token, offline_access) and then click Add.
Click the Save button to save the new Connected App.
In the Connected Apps list, find the App that you just created, and then click Manage.
On the page that opens, click the Edit button.
Under OAuth policies, select All users may self-authorize in the Permitted Users list, and then click the Save button.
Click on Custom Apps. Go back to the Connected Apps list, and click the App that you just created.
Go to API (Enable OAuth Settings), and note down the Consumer Key and Consumer Secret, which will be used for the configuration of Credential in REST_ Integration.
Now Generate Access Token using POSTMAN Application
Select POST Method and Pass URLhttps://login.salesforce.com/services/oauth2/token
Select Body and Select x-www-from-urlencoded
Pass KEY and VALUE as below and Where Red characters in VALUE, pass actual values
KEY VALUE
grant_type – password
client_id – consumer key
client_secret – consumer secret key
username – user name
password – password+security token without space
How to get security token in Salesforce Org :-
User Menu> My Setting>Personal>Rest My Security Token and click on Reset Security Token
You get Security Token on your email id
When you Click on Send you get Access_Token as below which will be help to update your data on Contact object
1. How to rubby on rail create access_token of salesforce
2. Create REST services apex class in our org.
- Create Require JSON to update Contact object’s Fields
Create Require JSON to update Contact object’s Fields
{
"completed_at" : "complete at on",
"distribution_link" : "https://www.google.com/",
"Email" : "george1234@gmail.com",
"loyalty_level" : "text level",
"Name" : "John Methw",
"seq_test_nps_level_c" : "test score nps level",
"seq_nps_score" : 987,
"seq_score" : "test score"
}
Create REST API @HttpPost using below link example
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_rest_code_sample_basic.htm
Create Test class for REST API
Now How to update data using POSTMAN Application
Select POST Method and Pass URL
Instacne_url which we generate +/services/apexrest/+ url mapping which we use in REST API in our class
Example:- https://ns123.salesforce.com/services/apexrest/updateContact
Pass KEY and VALUE as below and Where Red characters in VALUE, pass actual values
KEY VALUE
Authorization Bearer and pass access_token with one space
Content-Type application/json
Now Select Body and pass in Body require json. Select row and Select JSON(application/json)
Click on Send
You get success message of post request