0

I have a custom object in Salesforce with a set of fields. Some of the fields I sent over by an invocable method which calls a future method to send the first set of fields to entity in an external system.

I want to send the rest of the fields from the same Salesforce object to a second entity in the external system once I get the external Id back from the first set of Fields, since the second external entity is a child of the first entity.

In my put callout I call a invocable method for the first set of fields and from this same invocable method call a second method for the other fields since I already have an external id. How do I achieve this for the Post callout since I have to wait for the external id?

Is there a function for this I can use (like send until external id true) or do I need to write a separate trigger(with flag on first run) on update external Id to send the second set of fields for the post callout?

0

It sounds like you already have all the required field data stored in the custom sObject.

You could use a trigger on the custom sObject to detect when the external ID is written back into Salesforce. The trigger could then initiate an asynchronous process that would perform the last remaining callout that depended on the external ID being populated.

One way to do this is with a future method that supports callouts.

@future(callout=true)
public static void syncWithExternalId(List<Id> recordsToSync) {
    // Sync the records in question
}

Another approach is to have a Queueable class that supports callouts.

public class ExternalSyncQueueable implements Queueable, Database.AllowsCallouts { 

    private recordsToSync;

    public ExternalSyncQueueable (List<Id> recordsToSyncParam) {
        this.recordsToSync = recordsToSyncParam;
    }

    public void execute(QueueableContext context) {
        // Do the sync callout
    }
}
  • @DannielBallinger Could you explain further since I encountered that calling a future callout from a trigger is not possible. For now I crated a scheduler that checks every 2 minutes if the external id isn't empty and then performs the remaining callout. – Thomas Jan 22 at 3:12
  • @Thomas ensure that your future method or queueable class are marked as supporting callouts. – Daniel Ballinger Jan 22 at 18:25

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.