0

I have a requirement where I want Approval Submitted date for existing data.

I tried Field Update on Approval process, and put formula Today() and apparently I got the Approval Date but it is working only for new data not for the existing one.

How can I achieve this for existing data.

Tia,

4
  • Can't you just write one time script and execute from developer console that will update the all the existing records?
    – Ratan Paul
    Dec 2, 2015 at 6:13
  • I tried that option. Some records are already Approved and became locked which I'm unable to update (throwing an error).
    – SfdcPro
    Dec 2, 2015 at 6:20
  • So first question. you need to update the record with Approved date.? 2. After record approved it is still locked?
    – Ratan Paul
    Dec 2, 2015 at 6:24
  • Answer of your both the questions is YES. Practically when record is submitted for approval it gets locked. n it can not be updated. n I want to update all of my data with Approval Submitted Date.
    – SfdcPro
    Dec 2, 2015 at 6:31

1 Answer 1

2

Ask your admin to execute following code snippet. As admins can update records, even when they are locked.

This is for Account, but make changes for your object and replace fieldName with your respective field

    Map<id,Account> accounts = new Map<ID,Account>([Select {fieldName}, id From Account]);

Map<ID,Date> approvalTimeStampMap = new Map<ID,Date>();
For(ProcessInstance approval : [Select createdDate,TargetObjectId From ProcessInstance Where TargetObjectId IN:accounts.keySet()){
    approvalTimeStampMap.put(approval.TargetObjectId, approval.createdDate);
}

List<Account> accountsSubmittedForApproval = new List<Account>();
for(Account acc : accounts.values()){
    acc.{fieldName} = approvalTimeStampMap.get(acc.id); // Do string conversion if your field is a String
    //Keep a track of number of records you are processing
    accountsSubmittedForApproval.add(acc);
}

//Size should be less than 10k
update accountsSubmittedForApproval;

Hope this helps :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .