You need to sign in to do that
Don't have an account?

i have written this trigger to create opportunity once we create the account on account object i have written this trigger to create opportunity once we create the account on account object
i have written this trigger to create opportunity once we create the account on account object
i have written this trigger to create opportunity once we create the account on account object if account.create opportunity=true ..what i mean is there is a check box field in account ...if that is equls true then only opptunity should get created ..here is the code
trigger Opportunitycreate on Account (after insert) {
List<opportunity>Listopp = New List<opportunity>();
for(account acc:trigger.new){
if(acc.Create_Contact__c==True){
Opportunity opp = New opportunity();
opp.account.name = acc.name;
opp.name=acc.name;
opp.CloseDate=date.Today();
opp.StageName='Prospecting';
Listopp.add(opp);
}
}
if(Listopp.size()>0)
insert Listopp;
}
am getting error while adding record in accounts objcet ...the error is in line 6...
help me please..thanks in advance.

i have written this trigger to create opportunity once we create the account on account object if account.create opportunity=true ..what i mean is there is a check box field in account ...if that is equls true then only opptunity should get created ..here is the code
trigger Opportunitycreate on Account (after insert) {
List<opportunity>Listopp = New List<opportunity>();
for(account acc:trigger.new){
if(acc.Create_Contact__c==True){
Opportunity opp = New opportunity();
opp.account.name = acc.name;
opp.name=acc.name;
opp.CloseDate=date.Today();
opp.StageName='Prospecting';
Listopp.add(opp);
}
}
if(Listopp.size()>0)
insert Listopp;
}
am getting error while adding record in accounts objcet ...the error is in line 6...
help me please..thanks in advance.
Use the below modified code, it will work.
trigger Opportunitycreate on Account (after insert) {
List<opportunity>Listopp = New List<opportunity>();
for(account acc:trigger.new){
if(acc.Create_Contact__c==True){
Opportunity opp = New opportunity();
opp.accountid = acc.id;
opp.name=acc.name;
opp.CloseDate=date.Today();
opp.StageName='Prospecting';
Listopp.add(opp);
}
}
if(Listopp.size()>0)
insert Listopp;
}
All Answers
Use the below modified code, it will work.
trigger Opportunitycreate on Account (after insert) {
List<opportunity>Listopp = New List<opportunity>();
for(account acc:trigger.new){
if(acc.Create_Contact__c==True){
Opportunity opp = New opportunity();
opp.accountid = acc.id;
opp.name=acc.name;
opp.CloseDate=date.Today();
opp.StageName='Prospecting';
Listopp.add(opp);
}
}
if(Listopp.size()>0)
insert Listopp;
}