Salesforce to Salesforce Connector :(salesforce connect)
This built-in feature provided by Salesforce enables integration and data
synchronization between multiple Salesforce org.
It simplifies,eliminating the need for complex configurations and external tools
and providing a standardized method for easy data sharing and collaboration.
It simplifies salesforce 2 salesforce connect, ensuring a unified view of customer
information.
APIs:
-----
REST API
BULK API
SOAP API
META API
Middleware/Integration Platforms :
=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Middleware/Integration platforms like MuleSoft Anypoint platform, Dell Bhoomi,
Jitterbit, Informatica Cloud, and SnapLogic assist with
Salesforce to Salesforce Integration by providing connectors .
1. Enable the Salesforce Connector
Outbound :
For any kind of integration from vf page/Apex /LWC or Aura Js page/flow/custom
button to an external site, the site must be registered in the Remote site
setting.(endpoint)
Due to security reasons try not to integrate from JS rathen we apex callouts are
mostly recommended
1>Configure the Remote site settings with Endpoint
2>Named Credential
Inbound :
1>Connected App :
To integrate external app with salesforce
To integrate service providers with salesforce
To set security policies to control what data a third party app can access from
your otg.
To provide authorization for external APi
Create your own API for complex scenarios ,which are not provided by SALesforce
standard API:
-----------------------------------------------------------
@RestReaource(URLMapping='/Accountmgmt /')
global class Accountmgmt {
@httpget
global static list<account> getTopAccounts(){
// to accept the parameters
Map<string,string> ParamsMap = RestContext.request.params;
string accIndustry = paramaMap.get('Industry'); //
list<account> accList= [select id,name,Industry,rating,annual revenue from
account where annualRevenue!= null and industry =: accIndustry orderby
annualrevenue desc limit 10];
return accList ;
}
}
------------------------------------------
Also we have to get the related contact and cases we will take help of wrapper
class
@RestReaource(URLMapping='/Accountmgmt /')
global class Accountmgmt {
@httpget
global static AccountWrapper getTopAccounts(){
// to accept the parameters
Map<string,string> ParamsMap = RestContext.request.params;
/// set<id> accountIdset= new set<id>();
string accIndustry = paramaMap.get('Industry'); //
list<account> accList= [select id,name,Industry,rating,annual revenue from
account where annualRevenue!= null and industry =: accIndustry orderby
annualrevenue desc limit 10];
/// for(account acc : accList){ ..here we can also use the relationship
query to get the data instead of using wrapper class
accountIdset.add(acc.id);
}
list<contact> conlist=[select id,lastname,firstname,email from contact where
accountId in =: accountidset];
list<contact> caselist=[select id,priority,subject from case where accountId in
=: accountidset];
accountwrapper accWrapper = new AccountWrapper();
accwrapper.accList=acclist;
accwrapper.conlist= conlist;
accwrapper.caseList= caseList;
return accWrapper ;
}
global class AccountWrapper {
global list<account> accList ;
global list<contact> ConList ;
global list<case> CaseList ;
}
}
===================================================
POST METHOD
@RestReaource(URLMapping='/Accountmgmt /')
global class Accountmgmt {
@httpPost
global static string CreateAccount(string accName,string AccRating,String
accIndustry ){
account acc= new account();
acc.name= accName;
acc.rating=accRating;
acc.Industry= accIndustry;
try{
insert acc;
return 'Account Created Successfully';
}catch(exception ex){
return ex.getMessage();
}
}
global class AccountWrapper {
global list<account> accList ;
global list<contact> ConList ;
global list<case> CaseList ;
}
}
Specify the Body is the Body section of POST in POSTman tool
'accname':'Account created for RestService',
'accrating': 'HOT',
'accIndustry' : 'Banking'
then click on send and check the account records a new account record will be
created
======================================================================
For multiple object operation
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
@RestReaource(URLMapping='/Accountmgmt /')
global class Accountmgmt {
@httpPost
global static string CreateAccount(string accName,string AccRating,String
accIndustry ){
account acc= new account();
acc.name= accName;
acc.rating=accRating;
acc.Industry= accIndustry;
try{
insert acc;
return 'Account Created Successfully';
}catch(exception ex){
return ex.getMessage();
}
}
///global static string createAccountandContact(Account Information Infromation){
account accRecord = information.accountRecord;
contact conRecord = information.accountRecord ;
try {
insert accRecord;
conRecord.accountId= accRecord.id;
insert conRecord;
return 'Account and contact created successfully'
}catch {
return ex.getMessage();
}
}///
global class AccountWrapper {
global list<account> accList ;
global list<contact> ConList ;
global list<case> CaseList ;
}
\\\global class AccountInformation {
global account accountRecord{get;set;} //here we use gettrs and settrs because
we need to collect the data from the 3rd party as we are using POST
global contact contactRecord{get;set;} ///
}
}
In Postman :
"Information":{
"accountRecord" :{
"Name" : "Created complex Account with Rest Service",
"Industry" : "Energy",
"Rating" : "Hot"
},
"contactRecord" : {
"LastName" : "Contact from Rest Service",
"FirstName" : "Test",
"Email" : "abc@gmail.com"
}
}
==================================================
Delete :
@httpdelete
global static string deleteAccount(){
Map<string,string>ParamaMap= RestContext.Request.params;
string accountId= paramsMap.get('accId');
list<account> accList= [select id from account where id=: accountId];
if(!accList.isEmpty){
try{
delete accList;
return 'Record delete Successfully';
}Catch(exception ex){
return ex.getMessage();
}
}
}