Salesforce Integration Target Vs Source
Target Screen1: Manage Connected Apps
Go to the App Manager
- Click the down arrow next to
your app
- Click View
- Copy the Consumer Key
and Consumer Secret for OAuth flows
Step:1
Step:2
Endpoint Details
- URL Mapping: /receiveAccount/*
- HTTP Method: POST
- Class Name: OrgB_AccountReceiver
- Method Name: receiveAccount()
@RestResource(urlMapping='/receiveAccount/*')
global class OrgB_AccountReceiver {
@HttpPost
global static String
receiveAccount() {
RestRequest req =
RestContext.request;
String requestBody =
req.requestBody.toString();
System.debug('Received body: '
+ requestBody);
try {
Account acc = (Account)
JSON.deserialize(requestBody, Account.class);
// Clear ID if present to
avoid insert error
acc.Id = null;
insert acc;
return 'Account inserted:
' + acc.Id;
} catch (Exception e) {
return JSON.serialize(new
Map<String, Object>{
'errorCode' =>
'APEX_ERROR',
'message' =>
e.getMessage()
});
}
}
}
Step 1: Navigate to Auth. Providers
- Go to Setup in your
Salesforce org.
- In the Quick Find box,
search for and click "Auth. Providers".
- Click the "New"
button.
Step 2: Configure Auth. Provider Details
In the New
Auth. Provider screen, set the following fields:
|
Field |
Value |
|
Provider
Type |
Salesforce |
|
Name |
SSO From Partner Org (or any name you choose) |
|
URL
Suffix |
Auto-filled
(can be customized, e.g., SalesforceSSO) |
|
Consumer
Key |
(Copy
from the Connected App in the other org — explained below) |
|
Consumer
Secret |
(From
the same Connected App as above) |
|
Authorize
Endpoint URL |
https://login.salesforce.com/services/oauth2/authorize |
|
Token
Endpoint URL |
https://login.salesforce.com/services/oauth2/token |
|
User
Info Endpoint URL |
https://login.salesforce.com/services/oauth2/userinfo |
|
Default
Scopes |
openid profile email or leave blank |
|
Registration
Handler |
Create
or select a registration handler Apex class (explained below) |
|
Execute
Registration As |
Select
an admin user |
|
Icon
URL |
(Optional) |
|
Custom
Logout URL |
(Optional) |
Click Save.
Step 3: Copy Callback URL
After
saving, Salesforce generates a Callback URL (e.g.,
https://yourDomain.my.salesforce.com/services/authcallback/SalesforceSSO).
Create Named Credential (Target Org)
Step 1: Navigate to Named Credentials
- In Setup, search and
click “Named Credentials”
- Click “New Named
Credential”
Step:2
Step:3
Step:4
Sync Account Data from Org A to Org B via Named Credential and Apex
To send Account record data from Salesforce Org A to Salesforce
Org B using:
- @future(callout=true) method for async execution
- Named Credential (OrgB_API) for secure endpoint access
- REST API call to a custom Apex REST
service in Org B
Step 2: Create Apex Class in Org A
public class AccountSync {
@future(callout=true)
public static void sendToOrgB(Id
accId) {
Account acc = [SELECT Id,
Name, Phone, Website, Email__c FROM Account WHERE Id = :accId LIMIT 1];
HttpRequest req = new
HttpRequest();
req.setEndpoint('callout:OrgB_API/services/apexrest/receiveAccount/');
req.setMethod('POST');
req.setHeader('Content-Type',
'application/json');
req.setHeader('Accept',
'application/json');
req.setBody(JSON.serialize(acc));
req.setTimeout(120000);
Http http = new Http();
try {
HttpResponse res =
http.send(req);
System.debug('Org B
Response: ' + res.getBody());
} catch(Exception e) {
System.debug('Error
sending Account to Org B: ' + e.getMessage());
}
}
}
Source Org :-
Target :-