You need to sign in to do that
Don't have an account?
Error throwing on simple update trigger
Let me first start by saying that I am completely new to the Appex scene. I created the below trigger with some help from another cummunity member yesterday. The logic is very simple: Whenever the field opp.StageName is updated to '4 - Closed Won' and the roll-up summary field opp.Hosting__c is greater than zero, change the account.type to 'Customer'.
trigger OpportunityUpdateAccount on Opportunity(after insert, after update) { List<Account> accsToUpdate = new List<Account>(); for(Opportunity opp : trigger.new) {if (opp.StageName == '4 - Closed Won' && opp.Hosting__c > 0) accsToUpdate.add(new Account(Type = 'Customer')); } if (accsToUpdate != null && !accsToUpdate.isEmpty()) Database.update(accsToUpdate); }
However, when I go into an Opportunity and (in either order) add a product to increase the Hosting__c above $0 and update the StageName to '4 - Closed Won', it throws the below error:
Apex trigger OpportunityUpdateAccount caused an unexpected exception, contact your administrator: OpportunityUpdateAccount: execution of AfterUpdate 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 9, column 1
My guess is that I have not done a well enough job identifying what records actually need to be changed.
Any suggestions?
The problem is that you are creating a new account:
but the system has no way to associate this with an existing account. You'll need to specify the id, which you should be able to pull from the opportunity object, e.g.
All Answers
The problem is that you are creating a new account:
but the system has no way to associate this with an existing account. You'll need to specify the id, which you should be able to pull from the opportunity object, e.g.
That fixed it. Thanks a ton!!
I am also facing the same issue. Please see my code snippet below:
I am receiving following error:
Appreciate your help to resolve this issue.