[SalesForce] updating parent object after record approval

I'm trying to update parent record when current record is 'finally approved'. I've master-detail relationship between parent child

was trying to achieve this in following ways :

1) Firing Cross object field update when record is finally approved- Found this is not possible

2) Writing trigger on child, which query processIntance object ProcessInstance
somethng like this :

Select ID, Status, TargetObject.Name From ProcessInstance Where
TargetObjectID = '' AND Status in ('Approved',
'Rejected')

TargetObjectID -> current record ID

But seems like status of record is still not approved , when trigger is firing.so query is not returning anything

3) Thinking to writer a scheduler which will fire same code i'm writing in trigger.
I'm going to implement this which I think, will work
But just thinking If community has any other efficient way to achieve same

Thanks !

Best Answer

I an confused why you are querying ProcessInstance. Are you not setting a status field when the record is approved? If you have one, just use an after trigger to look for it changing to Approved (or whatever) then query for the parent and update that.

Strictly speaking a status field isn't necessary, but I have never implemented an approval process where the business didn't want a status field on the object. I suppose your proposed way would work, but I hope you have a strong reason to avoid adding a status field. If not, you are just creating a headache for yourself!

Related Topic