+ Start a Discussion

How to Create the BulkTrigger

Thanks your Post Rajiv .i am using your code but this code not saved display the Errors.


 i.e  Initial term of field expression must be a concrete SObject: LIST<Lead> at line 20 column 12




trigger ConvertLead on Lead (after insert, after update) {

List<Id> accountIds = new List<Id>();
List<Id> contactIds = new List<Id>();
list<lead> leadobject = new List<lead>();

for(Lead led: Trigger.New){
if(led.isConverted == true && led.Lead_type_picklist__c =='Broker'){
if(led.ConvertedAccountId != null && led.ConvertedContactId != null )
Map<Id,Account> accountMap = new Map<Id,Account>([Select Id from Account where Id IN: accountIds]);
Map<Id,contact> contactMap = new Map<Id,contact>([Select Id from contact where Id IN: contactIds]);
List<account> accountinsert = new List<Account>();
List<Broker__c> brokers = new List<Broker__c>();
for(integer i=0; i<leadobject.size(); i++){
Id accId = leadobject.ConvertedAccountId; //at line 20 column 12 ERROR LINE
Id cId = leadobject.ConvertedContactId;   //at line 20 column 12    ERROR LINE
Account accountobj = accountMap.get(accId);
Contact contactobj = contactMap.get(cId);
Agency__c ag = new Agency__c();
ag.Name = accountobj.Name;
ag.Mailing_Address__c = accountobj.BillingStreet;
ag.City__c =accountobj.BillingCity;
ag.State__c = accountobj.BillingState;
ag.County__c = accountobj.County__c;
ag.Zip_Code__c = accountobj.BillingPostalCode;
ag.Account__c = accountobj.ConvertedAccountId;
ag.Phone__c = accountobj.Phone;
Broker__c b = new Broker__c();
b.Name = contactobj.Name;
b.Agency__c = accountobj.id;
b.Contact_ID__c = contactobj.Id;
if( accountinsert.size()>0)
insert accountinsert;
if(brokers.size() > 0)
insert brokers;


how can solve this problem pls help me....................

Best Answer chosen by Admin (Salesforce Developers) 

Thanks for your post bob buzzard. Now Trigger working fine.

Thanks...............bob buzzard.

All Answers


LeadObject is declared as a list of Leads rather than a single lead instance.  Thus you'll need to access a particular record:


Id accId = leadobject[i].ConvertedAccountId; 
Id cId = leadobject[i].ConvertedContactId;   



Thanks for your post bob buzzard. Now Trigger working fine.

Thanks...............bob buzzard.

This was selected as the best answer