You need to sign in to do that
Don't have an account?
jillian
Trigger that Creates Opportunity when a Case is Closed
I am trying to write a trigger that creates an Opportunity when a case is closed, the opportunity would be attached to the Account that was associated to the case. Here is what I have, anyone have any help here?
trigger Opportunitycreate on case (after insert) {
List<opportunity>Listopp = New List<opportunity>();
for(case acc:trigger.new){
if(acc.Create_opp__c=True){
Opportunity opp = New opportunity();
opp.name=acc.name;
opp.CloseDate=date.Today();
opp.StageName='Prospecting';
Listopp.add(opp);
}
}
if(Listopp.size()>0)
insert Listopp;
}
trigger Opportunitycreate on case (after insert) {
List<opportunity>Listopp = New List<opportunity>();
for(case acc:trigger.new){
if(acc.Create_opp__c=True){
Opportunity opp = New opportunity();
opp.name=acc.name;
opp.CloseDate=date.Today();
opp.StageName='Prospecting';
Listopp.add(opp);
}
}
if(Listopp.size()>0)
insert Listopp;
}
Here is the working sample code.
Best Regards,
Mithun.
All Answers
Create_opp__c field is created in Case object or Account object?
Best Regards,
Mithun.
try adding pp.AccountId = acc.AccountId; while creating opportunity
trigger Opportunitycreate on case (after insert) {
List<opportunity>Listopp = New List<opportunity>();
for(case acc:trigger.new){
if(acc.Create_opp__c=True){
Opportunity opp = New opportunity();
opp.AccountId = acc.AccountId;
opp.name=acc.name;
opp.CloseDate=date.Today();
opp.StageName='Prospecting';
Listopp.add(opp);
}
}
if(Listopp.size()>0)
insert Listopp;
}
Regards,
Bhanu Mahesh
Here is the working sample code.
Best Regards,
Mithun.