function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Merry SMerry S 

Cannot figure out this error - CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY

I actually understand what the error is telling me - I just cannot figure out how to fix it.

 

I have this trigger on the Opportunity:  And it works perfectly...

 

trigger OpportunityUpdateAccount on Opportunity( before insert, before update ) {
    List<Account> accsToUpdate = new List<Account>();

    for(Opportunity opp : trigger.new){
        if (opp.Stage_Calc__c != null &&  opp.Amount  >= 50000 && (opp.type.contains('New Business') | (opp.type.contains('Existing Business'))))
            accsToUpdate.add(new Account(Id = opp.AccountId, Active_Opp_over_50kcalc__c = true));
                 else if (opp.Stage_Calc__c == null && (opp.type.contains('New Business') | (opp.type.contains('Existing Business'))))
            accsToUpdate.add(new Account(Id = opp.AccountId, Active_Opp_over_50kcalc__c = false));      
                     
   }
if (accsToUpdate != null)
        update(accsToUpdate);

 However, when I add this trigger: it breaks giving the error below the code...

 

trigger partnerOpClone on Opportunity (after update) {
Opportunity opp = [select Id, closedate from Opportunity where StageName = '09-Win' and type = 'Reseller / Partner Registration' LIMIT 1];  
Opportunity newOpp = opp.clone(false, true);
newOpp.StageName='trainging';
newOpp.amount=null;
newOpp.name=account.name + 'partner';
newOpp.closedate=opp.closedate;
insert newOpp;
}

 Error:Apex trigger partnerOpClone caused an unexpected exception, contact your administrator: partnerOpClone: execution of AfterUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, OpportunityUpdateAccount: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: [] Trigger.OpportunityUpdateAccount: line 12, column 1: []: Trigger.partnerOpClone: line 8, column 1

 

 

I get that the error is telling me there is an issue with the insertion and the other trigger firing - I have tried multiple things to fix it, but I am completely stummped. Any help would be appreciated.

s_k_as_k_a

In this line 

 

"newopp.Name = account.Name +'Partner'" You didn't query account.name in soql query to get opp.

 

You can odify the query

 

oportunity opp = [select id, closedate,account.name from opportuntiy where you conditions
 
and add below lines  to assign opp name.
 
String oppname = opp.account.Name +' Partner';
newopp.Name = oppname;

 

blake.tanonblake.tanon

try changing

 

if (accsToUpdate != null)
        update(accsToUpdate);

to this..

if (accsToUpdate.isempty() != false)
        update(accsToUpdate);

 

 

 

 

 

Merry SMerry S

Thanks, I tried both of those and they worked, i can now save the opp with no errors - but I have a new problem - after I get the first op to clone, when I try cloning other ops from other accounts it always clones the first op again. So I have multiple clones on one account and none on the other accounts.

 

:(

Merry SMerry S

Does anyone know how I can resolve the issue with this cloning ops to only the first account associated with the first op? ANy help would be appreciated.


LessDefined wrote:

Thanks, I tried both of those and they worked, i can now save the opp with no errors - but I have a new problem - after I get the first op to clone, when I try cloning other ops from other accounts it always clones the first op again. So I have multiple clones on one account and none on the other accounts.

 

:(