+ Start a Discussion
sdfasdsdfasd 

how to get the converted lead id from lead object.

i created Trigger for Lead. once lead is converted automatically account,contact,opportunity is created.i created two custom objects.i.e agency and broker objects.

i. once lead is converted then company name goes to account then agency is created based on accountname.

ii.once lead is converted then  LeadName goes to Contact then Broker is Created based on contact name.

i created bulktrigger for this  condtions.

But now i need  once lead is converted directly we created agency and brokers records based on lead company name and lead name .how can solve this problem.pls help me........................

Navatar_DbSupNavatar_DbSup

Hi,
It’s simple you have to simply make the condition which will identify that lead is converted or not inside the trigger code on Lead object. Try the below code as reference:
trigger ConvertLead on Lead (after insert,after update)
{
For(Lead l : trigger.new)
{
if(l.IsConverted)
{
Now make your code here to insert agency and brokers records based on lead company name and lead name
system.debug('@@@@@@@@@@@@@@@@@@');
}
}
}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

sdfasdsdfasd

Thank for your post Navatar. Navatar i need one more requirement pls help me..............

 

i created BulkTrigger for Lead Conversion.i created two custom objects. i.e   Agency and Broker objects.

i. Now Lead is Converted then  Lead company name goes to Agency and Lead Name goes to Broker object. that's working fine.

ii. once lead is converted Salesforce automatically created account and contact records.But we Need to Prevent the Account and Contact inserting. .is it possiable. ...............Pls Help me...........................

 

User Manually Lead Records converted using Convert Button in Lead home page.

 

MyTrigger

===========

trigger ConvertLead on Lead (after insert, after update) {
    
    List<Lead> leadIds = new List<Lead>();
    Id lId;
  for(Lead led: Trigger.New){
        if(led.isConverted == true && led.Lead_type_picklist__c =='Broker'){
            if(led.id != null)
               leadIds.add(led);
        }
    }
    Map<Id,Lead> leadMap = new Map<Id,Lead>([Select id,Name,Company from Lead Where id in:leadIds]);
    List<Agency__c > agencyinsert = new List<Agency__c >();
    List<Broker__c> brokers = new List<Broker__c>();
    
    for(integer i=0; i<leadIds.size(); i++){
        lId = leadIds[i].Id;
        Lead leadobj = leadMap.get(lId);
        Agency__c ag = new Agency__c();
       agencyinsert.add(ag);
    }
    if( agencyinsert.size()>0)
        insert agencyinsert;
 
   for(integer i=0; i<leadIds.size(); i++){
      for(integer j=0; j<agencyinsert.size(); j++){
             Lead leadobj1 = leadMap.get(lId);
             Broker__c b = new Broker__c();
             b.Name = leadobj1.Name;
             b.Agency__c = agencyinsert[j].id;
             brokers.add(b);
         }
    }
     if(brokers.size() > 0)
        insert brokers;
}

 

How can Prevent the inserting account and contact records once lead is conversion.pls help me...............................