+ Start a Discussion
Shannon Andreas 21Shannon Andreas 21 

Time-dependent workflow help

Hello friends!

I need your assistance asap. I am trying to write a workflow rule (or trigger, or process flow,etc.).

I need a workflow that recognizes a change in a field on a Customer Account record and depending on the change, updates the account type to Prospect.

The scenario is this:

1.) There is a nightly batch job that runs and feeds 3 fields on the account record with a number. There is also a formula field that sums these 3 fields called Total Fleet#. This field is the one I will be using for this scenario.
2.) Before the batch job runs, there is another job that zeroes out the fields. So the Fleet Total# before job = 7, Fleet Total# after job = 0.
3.) The next batch job then fills in the values again.
4.) If the new values equal 0 after the batch job and had a non-zero value originally, we need the workflow to update the account type to Prospect.

So basically, when the fleet total field is 0, the account is a prospect. 

The problem is that all of the accounts will turn to 0 because of the first batch job. So I need a way to flag these accounts and have the workflow kicks in AFTER the second batch job.

I hope you can follow this! If not, let me know and I will try to explain in another way.

Thanks so much for your help!

Shannon
 
Rajneesh Ranjan 23Rajneesh Ranjan 23
Hi Shannon,

Greetings!!!!

Can you add one additional field on the same object that will work behind the scene? What I think if you can create a text field called "Batch2 Indicator" (Y/N) on Account and Batch job1 will update it to "N" and Batch job2 will always update it to "Y".

In the next step an BEFORE UPDATE trigger can help you. This before trigger will check if Batch2 Indicator is set to Y then using Trigger.oldMap you can validate your formula field Total# and if it is meeting your criteria then update the Account Type.

A sample trigger I tried on my custom object is here:
Oject: Student__c
Formula Field: MSUM__c = M1__c + M2__c
trigger trgAfterBatch on Student__c (Before Update) {
    for(Student__c c : Trigger.New){      
        if(c.Batch_Indicator__c == 'Y'){
            if(c.MSUM__c > 0){
                c.Status__c = 'Good';
        }        
    }
}
Please let me know if it works for you.

Thanks,
Rajneesh
 
Shannon Andreas 21Shannon Andreas 21
Thanks Rajneesh! I will discuss with my dev counterpart in IT and give it a shot!

Appreciate the response and will mark it the best once I can put it in to play.

Thanks,

Shannon
Tolga SunarTolga Sunar
Referencing Rajneesh's proposed solution, it can be done by a simple workflow as well without consulting custom coding. 

As Rajneesh stated, you should use a background field (type Boolean) that turns true when first job kicks in and back to false then second job kicks in. You create a process or workflow such that triggers when this Boolean field updates from true to false (when second job kicks in).

Your process' formula criteria should look like this:
PRIORVALUE(BooleanField__c) = true && BooleanField__c = false && FormulaSumField__c = 0
And set the account to prospect as the immedite action.

However, if your jobs handle a high amount of account records, sticking to Trigger solution would be more healthy I think, though I am not totally sure about it. I'm open for suggestions on this specific topic.