You need to sign in to do that
Don't have an account?
rakesh konda
Unable to create opportunity
Hello ,
I am trying to create an opportunity using triggers when an account is created .
i have executed following code but i was unable to create the account
CODE:
trigger createopportunity on Account (after insert) {
list<opportunity> opp=new list <opportunity>();
for( account acc :trigger.new){
opportunity oppt=new opportunity();
oppt.Name = acc .Name;
oppt.Accountid = acc .id;
oppt.StageName= 'proposal';
oppt.CloseDate = System.today() + 30;
opp.add(oppt);
}
if (opp.isEmpty() == false) {
Database.update(opp);
}
}
ERROR:
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger createopportunity caused an unexpected exception, contact your administrator: createopportunity: 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.createopportunity: line 12, column 1
please help me with your suggestions
I am trying to create an opportunity using triggers when an account is created .
i have executed following code but i was unable to create the account
CODE:
trigger createopportunity on Account (after insert) {
list<opportunity> opp=new list <opportunity>();
for( account acc :trigger.new){
opportunity oppt=new opportunity();
oppt.Name = acc .Name;
oppt.Accountid = acc .id;
oppt.StageName= 'proposal';
oppt.CloseDate = System.today() + 30;
opp.add(oppt);
}
if (opp.isEmpty() == false) {
Database.update(opp);
}
}
ERROR:
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger createopportunity caused an unexpected exception, contact your administrator: createopportunity: 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.createopportunity: line 12, column 1
please help me with your suggestions
You need to Insert not Update the Opportunity list
Try this code :
Please mark this question as Solved if this answers your question so that others can view it as a proper solution.
Thanks,
Apoorv
All Answers
You need to Insert not Update the Opportunity list
Try this code :
Please mark this question as Solved if this answers your question so that others can view it as a proper solution.
Thanks,
Apoorv