I know how to get the Object Id for a custom object through the UI, but if I was trying to get the Object Id in Apex without hardcoding, how would I go about that? I am trying to use the Approval.ProcessSubmitRequest function to invoke an Approval Process, and need to use the object Id for the setObjectId() function. Any help or clarification would be greatly appreciated.



It's just the ID field of the record, which you can access generically:

SObject someRecord = [SELECT Id FROM Account LIMIT 1];
Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();

You can read more about it in Apex Approval Processing Example.

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.