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

Apex Trigger Complie Error
Hello,
I am a newbie and tried creating a trigger for creating a account on a field value change in Lead object.
when i compile i get the error:
Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST:SOBJECT:Lead at line 5 column 5
Any direction ?
code:
trigger create_Accnt on Lead (after update) {
//Check if the lead field Intrest_to_Buy is changed to 'Willing to Buy'
if (Trigger.New.Intrest_to_Buy = 'Willing to Buy'&& Trigger.old.Intrest_to_Buy != 'Willing to Buy') {
Account CreateAccnt = new Account ();
CreateAccnt.Name = 'testing_trig';
insert CreateAccnt;
}
}
Account CreateAccnt = new Account ();
CreateAccnt.Name = 'testing_trig';
insert CreateAccnt;
}
}
Joe
Message Edited by Joe2008 on 07-31-2008 03:34 AM
Message Edited by Joe2008 on 07-31-2008 05:51 AM
Since I added a loop, I also "bulkified" the trigger: Inside the loop, it creates Accounts and adds them to a List. Once the loop is finished, it uses a single "insert" statement to add all the Accounts to the database in a single operation.
As a rule of thumb, you should almost never use a DML statement (insert/update/delete) inside a loop, in Apex or just about any other database-accessing code.
All Answers
Since I added a loop, I also "bulkified" the trigger: Inside the loop, it creates Accounts and adds them to a List. Once the loop is finished, it uses a single "insert" statement to add all the Accounts to the database in a single operation.
As a rule of thumb, you should almost never use a DML statement (insert/update/delete) inside a loop, in Apex or just about any other database-accessing code.
Thx
Joe