Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Salesforce by (11.9k points)

The trigger given below is built to pull the most recent 'assigned to' user (or OriginalActorId) from the approval process list. The Approval_started__c field is ticked off as an initial submission action from a specific approval process.

My issue that the system.debug statement below is not showing the most recent assigned to user in the last pending Approval request but shows the most recent request assigned to user before the user clicks on submit for approval, so it skips the "approval request submitted step" that the user has done by clicking on Submit for approval and the initial submission action pending Step (where the approver is selected by the user) which is pending approval/rejection and it returns the old request that was right before these 2.

My goal here is to pull the latest pending request "assigned to" user or the OriginalActorId value.

Any thoughts? Thanks.

Here, I am providing a screenshot of the approval process list. Given in black is the value I fetched with this trigger on the debug log line, and given in blue is the expected value.

Approval process List

trigger Assigned2testTrigger on LLC_BI__Product_Package__c(after update) {

    list < LLC_BI__Product_Package__c > listpp = new list < LLC_BI__Product_Package__c > ();

    for (LLC_BI__Product_Package__c pp: trigger.new) {

        If(!checkRecursive.SetOfIDs.contains(pp.Id)) {

            if (pp.Approval_started__c == true) {

            system.debug('---------> My ProcessInstance           ' + string.valueof([Select Id, (Select TargetObjectId, SystemModstamp, StepStatus, RemindersSent, ProcessInstanceId, OriginalActorId, IsPending, IsDeleted, Id, CreatedDate, CreatedById, Comments, ActorId From ProcessSteps order by SystemModstamp desc) from LLC_BI__Product_Package__c where Id =: pp.id].ProcessSteps[0].OriginalActorId));

            }

            checkRecursive.SetOfIDs.add(pp.Id);

        }

    }

}

1 Answer

0 votes
by (26.7k points)

Use this query to find the process instance :

SELECT Id

     , SystemModStamp

     , Status

     , (SELECT SystemModstamp

             , StepStatus

             , ProcessInstanceId

             , OriginalActorId

             , Id

             , CreatedDate

             , CreatedById

             , Comments

             , ActorId

        From Steps

        ORDER BY SystemModstamp DESC)

FROM ProcessInstance

WHERE TargetObjectId = :pp.Id

ORDER BY SystemModStamp DESC

In order to fire this trigger, you need to perform an update action on the record itself. By default, it is not available. If you create different checkbox fields, you need to start the trigger firing after each and every step.

One field update for the each step, need to check the checkbox so that it triggers fire to the object related to it.

I hope this will help.

Want to become an Salesforce Expert? Join Salesforce certification now!!

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jul 15, 2019 in Salesforce by Kartik12234 (11.9k points)
0 votes
1 answer

Browse Categories

...