1

My trigger fires if I edit/save Account only but I want it to fire once the Contract_End__c == Today_10_Trigger__c. The Today_10_Trigger__c is a formula. I'm getting the impression that triggers will not execute on an internal query,if that's the correct phase for a formula field. If this is the case does anyone have a suggestion for me.

Here's my trigger:

trigger RenewalUpdates on Account (before insert,before update) {

    List<Account > needsUpdate = new List<Account >();  

 for( Account accountId : Trigger.new)
 {
//  if( Trigger.oldMap.get( accountId ).Contract_End__c== Trigger.newMap.get( accountId ).Today_10_Trigger__c)
  if(accountId.Contract_End__c== accountId.Today_10_Trigger__c && accountId.Record_Type_Hidden__c== 'Agent' && accountId.Status__c == 'Active')
  {


        // do something here because your field are equal

        //accountId.End_Date_Trigger__c=system.today();
        accountId.Renewal_In_Progress__c=true;
        accountId.Status__c='Renewal In progress';
        accountId.Approval_Progress__c='Up For renewal';        

        needsUpdate .add(accountId);
        System.debug('Test=============');
  }
}

}
1

You have to use a Workflow with Time-dependent actions or Process Builder with Scheduled Actions. Apex Triggers are only fired on create or edit.


Update

Step by step instructions to create Process

Please read Process Scheduled Actions Considerations BEFORE creating your process


  • Start `Process Buider` and create new Process
  • Select `Account` for the object
  • Add Criteria:
    1. You can tick 'Conditions are met', I just did not have custom fields to select from
    2. Have all criteria when time actions have to apply
    3. Do not forget to check 'Yes' in Advanced settings - it enables Scheduled actions

New Criteria

  • Click on 'Set Schedule'
  • Recreate as shown in the screenshot (or adjust to your need)

Time trigger

  • Click on 'Add Action' and select 'Update records'
  • IMO - you have too many fields representing the same data, I'd recommend only to change the Status here, and have another actions (see next slide) - send email to the owner, or chatter message, and update the other fields later in the process, but this is up to you

Status Update

  • This is where you can add more actions, selection from the available options

More actions

  • A top level overview of the Process you created
  • 6 - you could have another scheduled actions - like another Status update when Contract ended. But have to pay attention to entry Criteria: we change the status 10 days before contact end, and when Process criterias will be evaluated after this change, this criteria will return false and any other Scheduled actions here will be deleted.

More time triggers

| improve this answer | |
  • I tried using both options as a simple test. I made sure the 2 fields where equal before creating a WFR and PB. Then when I created both to trigger a simple boolean test. Nothing triggered – Robert Wynter Apr 1 '16 at 14:25
  • It's not working like that. You have to have activated WF or PB in place, and then trigger records updates, so the rules are evaluated and time-triggered action records or flow interview for PB will be created. If you could give me some more background on your case, I can guide you. You don't need a formula fields like Today_10_Trigger__c as this can be defined in a time-dependent actions - like 10 days from now or 2 weeks before My_Target_Date__c – o-lexi Apr 1 '16 at 16:06
  • Sure that would be great, thanks @Oleksiy. I'm more comfortable with PB if you wouldn't mind walking me through the steps to get it working. Keeping in mind that I need this to be automatic. So if I have an account with an end date of April 11th. I need this PB to auto execute on it's own – Robert Wynter Apr 1 '16 at 16:20
  • This is what Scheduled Actions are for )) You have to read the documentation also, as they have some limitations - like you won't be able to modify (e.g. change number of days used to calculate when they trigger) them once you have some time-triggered records created for the rule or PB. I'm going to Edit my answer soon to provide you more details on how to setup. – o-lexi Apr 1 '16 at 16:35
  • There are 4 fields that I'm working with in Person Account Objects (Status__c,Approval_Progress__c,Renewal_In_Progress__c,Contract_End__c) when it's 10 days before Contract_End__c. I want the other fields to be triggered to change (Status__c = "Renewal In Progress",Approval_Progress__c = "Up For Renewal",Renewal_In_Progress__c= True) – Robert Wynter Apr 1 '16 at 18:36
0

What is your formula referencing? Triggers won't fire if a formula field changes, you'd need to create a trigger that fires when the fields driving the formula are changed.

| improve this answer | |
0

Formulas are evaluated at time of execution so by using after insert and after update you should have access to the formula values at that time.

| improve this answer | |
-1

Try the below I don't think salesforce allows comparing the values of two fields. Note sure what data type is the field accountId.Today_10_Trigger__c. Assign toa varaible in your for loop and check against that value.

trigger RenewalUpdates on Account (before insert,before update) {

    List<Account > needsUpdate = new List<Account >();  
    for( Account accountId : Trigger.new)
    {
        //  if( Trigger.oldMap.get( accountId ).Contract_End__c== Trigger.newMap.get( accountId ).Today_10_Trigger__c)
        String today10Trigger = accountId.Today_10_Trigger__c; 
        if(accountId.Contract_End__c== today10Trigger && accountId.Record_Type_Hidden__c== 'Agent' && accountId.Status__c == 'Active')
        {


            // do something here because your field are equal

            //accountId.End_Date_Trigger__c=system.today();
            accountId.Renewal_In_Progress__c=true;
            accountId.Status__c='Renewal In progress';
            accountId.Approval_Progress__c='Up For renewal';        

            needsUpdate .add(accountId);
            System.debug('Test=============');
        }
    }

}
| improve this answer | |
  • 2
    I believe your statement "I don't think salesforce allows comparing the values of two fields" is completely false as it is written. Salesforce absolutely allows you to compare values. Maybe you were trying to say something different? – Eric Mar 31 '16 at 21:24
  • yes I was trying to say something different. To extend what I was trying to say. To compare and THEN fire of a trigger based on the comparison. So on the day that the two fields are equal the trigger is executed on its own. – Robert Wynter Apr 1 '16 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.