function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vishalg89Vishalg89 

Make API call after DML operation

Hi all, 

 

I have a situation in which I need to make a API call after insert operation and in that API method I need to pass the ID of inserted object. Can it be possible? If yes then how? Please provide a solution urgently.

 

Thanks-

Vishal Gupta

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

By API call, it sounds like you mean a REST or SOAP function call. You can't do this directly because of limitations on callouts. Instead, call a @future method that can accept the ID values of the created records and pass that to the REST or SOAP endpoint instead. See asynchronous code functions in the documentation.

All Answers

RocketRocket

All I can say is that since object has been inserted theat means record id is available which can be passed to functions.Maybe try to put your code so that somebody can help you.

evgoldevgold

Use Database.SaveResult:

 

Database.SaveResult dsr = Database.insert(OBJECT,false); //Replace OBJECT with what you are inserting
if(dsr.IsSuccess()) { //make sure there were no errors
	system.debug(dsr.getId());  //This is the inserted ID
}

 

sfdcfoxsfdcfox

By API call, it sounds like you mean a REST or SOAP function call. You can't do this directly because of limitations on callouts. Instead, call a @future method that can accept the ID values of the created records and pass that to the REST or SOAP endpoint instead. See asynchronous code functions in the documentation.

This was selected as the best answer
Vishalg89Vishalg89

yes.. that works, thank you...

Vishalg89Vishalg89

It works but in this case how should I get the response on VF page after completing the apex job?