A company wants to incorporate a third-party web service to set the Address fields when an Account is inserted, if they have not already been set. What is the optimal way to achieve this?
A.
Create a Process, call an Apex @future(callout=true) method from it, and make the callout from that Apex method.
B.
Create a Process, call an Apex @InvocableMethod from it, and make the callout from that Apex method.
C.
Create an after insert trigger, call an Apex @InvocableMethod method from it, and make the callout from that Apex method.
D.
Create an after insert trigger, call an @future(callout=true) method from it, and make the callout from that Apex method.
D can be done from an after insert trigger + @future annotation. Ensures that account exists in Salesforce before doing the callout.
A is not correct: @future methods can only be invoked from Apex classes, not declarative automation like Process Builder
B is not correct: Incorrect, because Process Builder executes synchronously, and callouts are not allowed synchronously within a transaction. @InvocableMethod does not support callouts directly unless it is executed asynchronously, which is not the case here.
C is not correct: A trigger calling an @InvocableMethod directly would still run synchronously and fail due to the callout restriction. @InvocableMethod does not support asynchronous execution unless explicitly handled with Queueable or Future methods
C and D can't update Address field in After context
A use @future annotation =>It's made async function, so that we can't catch value of Address field by sycn way
I'll will go for B answer, which the best choice I considered.
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
Rocky_sfdc
Highly Voted 3 years, 9 months agoBrainMelt12
Most Recent 1 month, 1 week agoAnjindal
4 months, 4 weeks agoNot_Nam
1 year, 3 months agoKK13
2 years, 9 months agoabhichauhan
3 years, 9 months ago