+ Start a Discussion
Kevin18064832Kevin18064832 

Running a trigger in (near) real time to evaluate a formula field and start a workflow

Hi

Disclosure: not a developer..

I want to have a field update workflow start, but it is based on a formula field and it does not seem that a formula field can start a workflow.

Essentially, I have a formula field on Opportunities called Paid (Paid__c) and when this evaluates to True, I want the Stage (StageName) field to update to Closed Won.  I'd like this to happen in as near to real time as possible - every 15 min?  More frequent, if it wouldn't be problematic...

Is this something that is simple for someone that knows what they are doing or can someone point me in the right direction?
Ashish_SFDCAshish_SFDC
Hi Kevin, 


This is currently not possible. 

https://success.salesforce.com/ideaView?id=08730000000Bpd7AAC


Regards,
Ashish

vbsvbs
How does the Paid__c field get updated. Assuming there's a WF on Opportunities that has a criteria trcking the Paid__c field the updated to StageName should be instant. If you are looking at updating Paid field at regular intervals what you could do is setup time dependent workflows on creation/updates of the WF that then check the Paid__c field and update.
Another alternative would be using scheduled class. These are the only standard known ways to invoke time dependent processing.
Kevin18064832Kevin18064832
Paid_c field is a formula field

if( Related_Invoice__r.Paid__c = true, True, False)
Ashish_SFDCAshish_SFDC
Hi Kevin, 

So is it possible to have another field update in the Same formula when it updates Paid__c then itself update Stage = Closed (Additional workflow trigger).

Regards,
Ashish

Kevin18064832Kevin18064832
Hi Ashish,

I am not sure how I would have another field update with the Paid__c formula field.  My guess is that an Apex trigger will be needed, but as I am not a developer, I am trying to find a solution that works for my skill set!

Cheers
Kevin
Ashish_SFDCAshish_SFDC
Hi Kevin, 


The way the formula field updates the value - the same way you can create a WOrkflow which will update 2 fields - it will update Paid and Status both on that validated event.

If you are using a workflow, to validate the criteria, then you have 1 field update actions based on the same criteria.


Regards,
Ashish
Thomas Bille RasmussenThomas Bille Rasmussen
Just run your workflow rule off the actual field "Related_Invoice__r.Paid__c" instead of the formula field. Or am I missing something? What does the workflow rule do?
Kevin18064832Kevin18064832
Hi Thomas,

There is no workflow currently.  I would have liked to set up a workflow so that the paid field that I have on the custom object: Invoices would kick off the process.  However, as it is a custom object, I can't seem to start a workflow that would work across to the opportunity.  

So, if I mark the invoice as Paid on the Invoice Screen (custom object) the only way I can seem to initiate a change to the associated opportunity that I have created is to use the formula field update that I mentioned previously.  However, since the formula field update does not actually trigger a record change in Salesforce, I cannot start any workflows automatically off of the Paid__c field evaluating the formula to True.

Cheers
Kevin
Ashish_SFDCAshish_SFDC
Hi Kevin, 


What is the relationship between the Opportunity Object and the Invoice - Custom object?

We can update the Field through workflow only on a parent record.

To update a related record on a unrelated object you have to use a Trigger with APEX.


Regards,
Ashish 


Thomas Bille RasmussenThomas Bille Rasmussen
Hey Kevin, ok I think I had your workflow in referse. So what you're trying to do is kickoff a change to the opportunity based on a change to a child custom object field changing, is that correct?
Kevin18064832Kevin18064832
Hi Ashish,

I believe that it is an unrelated object.  the only relationship from is a lookup relationship from Opportunity to Invoice, as per the schema below:

User-added image

Again, maybe I am missing something from your  question - I am relatively new to this.

Hi Thomas,

I think that it is unrelated...but how would I check?  Sorry for the (dumb) question!

Cheers
Kevin
Thomas Bille RasmussenThomas Bille Rasmussen
Hey Kevin, it's related because you have a lookup relationsship. You should be able to do a Workflow rule on the custom object and as one of the criteria do a lookback to the opportunity trigger on a field changing. Eg: Your scenario, trigger something on your custom object if field on opportunity is changed. See my screenshot below as I have the exact same scenario in my instance:

User-added image
Ashish_SFDCAshish_SFDC
Hi Kevin, 


Post again if you have any further questions, 

Thanks Thomas!


Regards,
Ashish