You need to sign in to do that
Don't have an account?
Nitin Sharma
I create a trigger to add related opportunity record on account object if there is no opportunity.but when i create a account its gives me a error .what does it mean
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger Addreletedrecord caused an unexpected exception, contact your administrator: Addreletedrecord: 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.Addreletedrecord: line 8, column 1
Review all error messages below to correct your data.
Apex trigger Addreletedrecord caused an unexpected exception, contact your administrator: Addreletedrecord: 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.Addreletedrecord: line 8, column 1
As you are using update on records which are not existing in the database so the Id for update is not identified and as a result you are getting error.
Please replace the update statement with "UPSERT".
Upsert will automatically detects wheteher a record is inserted or updated
So change your code with below code :
Let me know if you have any other issue.
Thanks,
Abhishek
All Answers
There is an error in your trigger code where you are trying to update some object.
Maybe you are no passing the correct Id of object which you are trying to update.
It would be easy to help you if you post your trigger code here.
Without seeing your code it is not possible to help you out.
So please share your code.
Thanks,
Abhishek
List<Opportunity> oppList = new List<Opportunity>();
for(Account a:[SELECT Id,Name from Account where Id IN:Trigger.new AND Id NOT IN(SELECT AccountId from Opportunity)]){
oppList.add(New Opportunity(Name= a.Name+'opportunity',StageName='Prospecting',AccountId=a.Id));
}
If(oppList.Size()>0){
Update oppList;
}
}
As you are using update on records which are not existing in the database so the Id for update is not identified and as a result you are getting error.
Please replace the update statement with "UPSERT".
Upsert will automatically detects wheteher a record is inserted or updated
So change your code with below code :
Let me know if you have any other issue.
Thanks,
Abhishek
Thanks,
Nitin
Please elaborate your below code. I am not able to understand.
for(Account a:[SELECT Id,Name from Accountwhere Id IN:Trigger.new AND Id NOT IN(SELECTAccountId from Opportunity)]){
oppList.add(New Opportunity(Name= a.Name+'opportunity',StageName='Prospecting',AccountId=a.Id));
Thanks
Naveen
i need to create a trigger with handler class to automatically create an opportunity when a new account is created where the account has min 5 mandatory fields and all the fields are copied to the new opportunity created.
1. Create a custom field on the Contact object: Is Primary Contact(checkbox);
2. A validation should be added so that if the Account already has a Primary Contact set a new one cannot be added;
Can you please open a new question regarding your request and share the link here?
Thanks,
Abhishek Bansal.
Hi Abhishek !
Thanks
https://developer.salesforce.com/forums/ForumsMain?id=9060G000000MTbFQAW