Development questions
Write a SOQL query to fetch ProcessInstance and ProcessInstanceWorkitem records to find all pending Approval requests assigned to the current user (UserInfo.getUserId()).
Pending approvals are ProcessInstanceWorkitem records linked to a ProcessInstance. Filter by the actor and pending status.
apex
List<ProcessInstanceWorkitem> items = [
SELECT Id, ProcessInstanceId, ProcessInstance.TargetObjectId, ProcessInstance.Status, ActorId, CreatedDate
FROM ProcessInstanceWorkitem
WHERE ActorId = :UserInfo.getUserId() AND ProcessInstance.Status = 'Pending'
];
ProcessInstance.TargetObjectId is the record being approved.
soqlscenarioapprovalsetup-objects
More Development questions
- What is an Apex Trigger in Salesforce and when should you use it over Flows?
- What is the difference between before triggers and after triggers?
- Explain all Trigger context variables (isInsert, isUpdate, isDelete, isUndelete, isBefore, isAfter, isExecuting, size, operationType).
- What is the difference between Trigger.new and Trigger.old?
- In which trigger events are Trigger.new and Trigger.newMap available?
- In which trigger events are Trigger.old and Trigger.oldMap available?