You need to sign in to do that
Don't have an account?
Navneeth Raj
System.DmlException TRIGGER ERROR
SCENARIO: If Lead Status is "Open - Not Contacted" add to Account else if it is "Working - Contacted" add to Opportunity
trigger AutoQualifyLead2 on Lead (after insert) {
List<Account> accs=new List<Account> ();
List<Opportunity> opps=new List<Opportunity> ();
for(Lead l:Trigger.New)
{
if(l.Status=='Open - Not Contacted'){
Account a=new Account();
a.Fax=l.Fax;
a.Phone=l.Phone;
a.Industry=l.Industry;
accs.add(a);
}
else{
if(l.Status=='Working - Contacted'){
Opportunity op=new Opportunity();
op.Name=l.Name;
op.Description=l.Description;
opps.add(op);
}
}
}
if(accs.size()>0){ insert accs; }
if(opps.size()>0){ insert opps; }
}
ERROR: As seen in attached Image
trigger AutoQualifyLead2 on Lead (after insert) {
List<Account> accs=new List<Account> ();
List<Opportunity> opps=new List<Opportunity> ();
for(Lead l:Trigger.New)
{
if(l.Status=='Open - Not Contacted'){
Account a=new Account();
a.Fax=l.Fax;
a.Phone=l.Phone;
a.Industry=l.Industry;
accs.add(a);
}
else{
if(l.Status=='Working - Contacted'){
Opportunity op=new Opportunity();
op.Name=l.Name;
op.Description=l.Description;
opps.add(op);
}
}
}
if(accs.size()>0){ insert accs; }
if(opps.size()>0){ insert opps; }
}
ERROR: As seen in attached Image
The error message seems to indicate that you are missing required fields for the new opportunity. You need to add something like this:
Hope this helps.
Cheers,
Peter
You have missed the required field in account and opportunity objects ,that is the root cause for this error.
Thanks
Muba