0

I have two sales-force org (org 1 and org 2).I am insert a new account in my org 1 now i want that every time a org 1 account created then org 2 will automatically update its account with org 1 data using rest API .

  • 1
    hv u looked into salesforce to salesforce : help.salesforce.com/… – Vamsi Krishna Sep 8 '15 at 12:32
  • yes i want this feature for my two developer org .kindly help me – sheetal Sep 8 '15 at 12:33
  • This is called "Salesforce-to-Salesforce" integration. Salesforce provides it. – Ashwani Sep 8 '15 at 12:56
  • how can i achieve this ? – sheetal Sep 8 '15 at 13:00
1

You can make your own rest api callouts from the account create trigger in org1 to the salesforce standard api of org2. or alternatively you can set up salesforce to salesforce

Salesforce to Salesforce is a Force.com feature that lets you configure two Force.com environments (orgs) so that they share data records in real time.

This Feature will allow you to sync records between the 2 orgs without the need to write additional callouts in apex.

Writing a custom rest api is something I would only do in a scenario where I have additional logic that needs to be executed or when additional abstraction is preferred in the API.

0

You can build a custom REST API using APEX REST or SOAP API with Apex webservice methods download the WSDL expose it to the other system.

My suggestion is build a REST API using Apex REST with @RestResource

Pls refer to this link below on how to create REST API using Apex and testing it out using postman/Workbench application.

https://forceadventure.wordpress.com/2013/01/31/creating-a-custom-rest-api-in-salesforce/

You need to share the URL with external applications to access you API:

https://Instance.salesforce.com/services/apexrest/case/rest_api/

They need to send a request to you as {"case_number":"1234"}

Based on this account name posted it will query and send the reponse as JSON.

HTTP Class:

@RestResource(urlMapping='/case/rest_api/*')
global class RestTestController {
@HttpPost
global static void getTestAccount() {

RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
res.addHeader('Content-Type', 'application/json');
String jsonResponse = '';
String CaseNo= req.params.get('case_number');

// No account_name parameter was found; return status 400
if(CaseNo== null) {
    res.statusCode = 400;
    jsonResponse = '{"response": {"status": "Failure", "message": "MissingRequiredQueryParameter case_number"}}';
    res.responseBody = blob.valueOf(jsonResponse);
    return;
}

// Get the list of cases that match the case_number sent in the request.
List<case> cases = [SELECT Id, CaseNumber, Account.Name
                          FROM case
                          WHERE CaseNumber=: CaseNo];

// No accounts with matching case_number
if( cases.isEmpty()) {
    res.statusCode = 400;
    jsonResponse = '{"response": {"status": "Failure", "message": "No case matching case_number was found"}}';
    res.responseBody = blob.valueOf(jsonResponse);
    return;
}

 // At least 1 account was found, JSON serialize it and send it back.
try {
    res.statusCode = 200;
    jsonResponse = Json.serialize(cases[0]);
    res.responseBody = blob.valueOf(jsonResponse);
    return;
} catch ( Exception ex ) {
    res.statusCode = 500;
    jsonResponse = '{"response": {"status": "Failure", "message": "' + ex + '"}}';
    res.responseBody = blob.valueOf(jsonResponse);
    return;
}
}
}
  • i want this thing using rest api only – sheetal Sep 9 '15 at 5:03
  • Do you wanna build a custom REST API using apex and expose it to other org? or Do you wanna make an asynchronous callout using an apex trigger? – Salesforce Learner Sep 9 '15 at 14:28
  • I wanna build a custom REST API using apex and expose it to other org – sheetal Sep 10 '15 at 3:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.