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(); req.setObjectId(someRecord.Id); Approval.process(req);
You can read more about it in Apex Approval Processing Example.