• Mike Ferraro
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 15
    Replies
Hello!  I updated a Time Based Workflow that's working perfectly in Sandbox, but now won't deploy due to errors on the tests:

User-added image
Do I have to somehow update these tests in order for them to pass?

Thanks!

Mike
Hi Everyone, recently a time based workflow has started throwing an error after working since 2012.  This process triggers a checkbox field that creates a new opportunity for contracts expiring in 120 days.


Error:Apex trigger UpdateAccountDummyVariable caused an unexpected exception, contact your administrator: UpdateAccountDummyVariable: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 0015000000Oa1XaAAJ; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CreateOpportunity: execution of BeforeUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 0015000000Oa1Xa) is currently in trigger CreateOpportunity, therefore it cannot recursively update itself: [] Trigger.CreateOpportunity: line 21, column 1: []: Trigger.UpdateAccountDummyVariable: line 9, column 1


Here are the two triggers referenced:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
trigger CreateOpportunity on Account (before update) {

    List<Opportunity> o = new List<Opportunity>();  
        for (Account thisAccount : Trigger.new) {
               // A workflow rule will enable dummy_COW variable which in turn will tell the trigger to create the opportunity.
               if (thisAccount.dummy_CreateOpportunityWorkflow__c) {
                    o.add (new Opportunity (                   
                    Name = thisAccount.name + ' 2020 Renewal',                 
                    OwnerId = thisAccount.OwnerID,
                    Probability = 15,
                    Opportunity_Value__c = thisAccount.Current_Contract_Value__c,
                Expiring_Contract_Value__c = thisAccount.Current_Contract_Value__c,
                    Description = 'Auto-created by workflow.',
                Renewal__c = true,
                    CloseDate = date.today()+120,
                    Current_Contract_Expiration__c = date.today()+120,
                    AccountId = thisAccount.id,     
                    StageName = 'Analysis Needed'));                        
        }  
        if (!o.isEmpty()) {
        insert o;
        // clear the variable so subsequent edits do not create a new opportunity.
        thisAccount.dummy_CreateOpportunityWorkflow__c = false;
     }  }              

}



1
2
3
4
5
6
7
8
9
10
11
12
13
trigger UpdateAccountDummyVariable on Contract (before update) {

    for (Contract thisContract : Trigger.new)
    {
    if (thisContract.Dummy_Create_New_Opportunity_Workflow__c) 
        { 
            Account a = new Account(id = thisContract.AccountId);
          a.Dummy_CreateOpportunityWorkflow__c = true;
      update a;
      thisContract.Dummy_Create_New_Opportunity_Workflow__c = false;
        }
    }
}



Thanks for any suggestions!

Mike


 
I keep getting errors when trying to deploy using outbound change sets... I finally copied and pasted to the sandbox, made my edits, and now SF won't let me send back to production.  Do I need to copy the Test Trigger over to the Sandbox too?
Hello!  I updated a Time Based Workflow that's working perfectly in Sandbox, but now won't deploy due to errors on the tests:

User-added image
Do I have to somehow update these tests in order for them to pass?

Thanks!

Mike
Hi Everyone, recently a time based workflow has started throwing an error after working since 2012.  This process triggers a checkbox field that creates a new opportunity for contracts expiring in 120 days.


Error:Apex trigger UpdateAccountDummyVariable caused an unexpected exception, contact your administrator: UpdateAccountDummyVariable: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 0015000000Oa1XaAAJ; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CreateOpportunity: execution of BeforeUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 0015000000Oa1Xa) is currently in trigger CreateOpportunity, therefore it cannot recursively update itself: [] Trigger.CreateOpportunity: line 21, column 1: []: Trigger.UpdateAccountDummyVariable: line 9, column 1


Here are the two triggers referenced:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
trigger CreateOpportunity on Account (before update) {

    List<Opportunity> o = new List<Opportunity>();  
        for (Account thisAccount : Trigger.new) {
               // A workflow rule will enable dummy_COW variable which in turn will tell the trigger to create the opportunity.
               if (thisAccount.dummy_CreateOpportunityWorkflow__c) {
                    o.add (new Opportunity (                   
                    Name = thisAccount.name + ' 2020 Renewal',                 
                    OwnerId = thisAccount.OwnerID,
                    Probability = 15,
                    Opportunity_Value__c = thisAccount.Current_Contract_Value__c,
                Expiring_Contract_Value__c = thisAccount.Current_Contract_Value__c,
                    Description = 'Auto-created by workflow.',
                Renewal__c = true,
                    CloseDate = date.today()+120,
                    Current_Contract_Expiration__c = date.today()+120,
                    AccountId = thisAccount.id,     
                    StageName = 'Analysis Needed'));                        
        }  
        if (!o.isEmpty()) {
        insert o;
        // clear the variable so subsequent edits do not create a new opportunity.
        thisAccount.dummy_CreateOpportunityWorkflow__c = false;
     }  }              

}



1
2
3
4
5
6
7
8
9
10
11
12
13
trigger UpdateAccountDummyVariable on Contract (before update) {

    for (Contract thisContract : Trigger.new)
    {
    if (thisContract.Dummy_Create_New_Opportunity_Workflow__c) 
        { 
            Account a = new Account(id = thisContract.AccountId);
          a.Dummy_CreateOpportunityWorkflow__c = true;
      update a;
      thisContract.Dummy_Create_New_Opportunity_Workflow__c = false;
        }
    }
}



Thanks for any suggestions!

Mike