function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sdfasdsdfasd 

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

======

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 )
leadobject.add(led);
accountIds.add(led.ConvertedAccountId);
contactIds.add(led.ConvertedContactId);
}
}
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;
accountinsert.add(ag);
Broker__c b = new Broker__c();
b.Name = contactobj.Name;
b.Agency__c = accountobj.id;
b.Contact_ID__c = contactobj.Id;
brokers.add(b);
}
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) 
sdfasdsdfasd

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

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

All Answers

bob_buzzardbob_buzzard

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;   

 

sdfasdsdfasd

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

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

This was selected as the best answer