0

When we post a Box record we also send it an External Id from another side. How to to make it in HttpPost method?

I have an object1 in Org1. In Org1 are all my callouts. object1 has a button POST. When I press it - I create the object2 in Org2, but object2 has also an External Id field, and this field == Id from object1.

My code:

@HttpPost
global static Box__c postBox(String title){
    RestRequest req = RestContext.request;

    Box__c b = new Box__c(
        Title__c = title,
        );
    insert b;
    return b;
}
  • 1
    It is really unclear what you are trying to ask here. – Adrian Larson Oct 7 '18 at 17:52
  • I have an object1 in Org1. In Org1 are all my callouts. object1 has a button POST. When I press it - I create the object2 in Org2, but object2 has also an External Id field, and this field == Id from object1. – user60684 Oct 7 '18 at 18:10
  • Okay, I've seen your questions pop up all weekend, and I'm just wondering why you're not using the standard REST API, which looks like exactly what you should be using in this case. – sfdcfox Oct 7 '18 at 18:14
  • I need to my post-service. – user60684 Oct 7 '18 at 19:26
0

Excluding other options like the native REST API that sfdxfox suggested, you could perform the upsert from Apex.

E.g.

@HttpPost
global static Box__c postBox(String title, Id org1BoxId) {
    RestRequest req = RestContext.request;

    Box__c b = new Box__c(
        Title__c = title,
        ExternalId_From_Org1__c = org1BoxId
        );

    // Specify the ExternalId_From_Org1__c field as the external ID
    upsert b ExternalId_From_Org1__c;
    return b;
}

Here ExternalId_From_Org1__c is an additional field in Org 2 that is marked as an external ID.

See also:

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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