Tuesday 26 July 2016


1 task triggeer

trigger Leadconv on Lead (After Insert) { 

    map<Id, Lead> mapNewLead = trigger.newMap; 
     Contact c;
    for(Lead objLead: mapNewLead.values()) 
    { 
        if (objLead.isConverted == true && objLead.ConvertedAccountId != null) 
        { 
             c = new contact(LastName = objLead.X2nd_Contact_Name__c,
                                        
                                       AccountId = objLead.convertedAccountId);
                                       
        } 
        insert c;
    } 
     
}
-----------------------------------------




01   
        trigger LeadConvert on Lead (after update) {
02
03    map<Id, Lead> mapNewLead = trigger.newMap;
04    List<Contact> lstContact = new List<Contact>();
05    for(Lead objLead: mapNewLead.values())
06    {
07        if (objLead.isConverted =true )
08        {
09            lstContact.add(new contact(LastName = objLead.First_Other_Contact_Name__c,Phone =objLead.First_Other_Contact_Phone__c,
10            Email = objLead.First_Other_Contact_Email__c,AccountId = objLead.convertedAccountId));
11            lstContact.add(new contact(LastName = objLead.Second_Other_Contact_Name__c,Phone =objLead.Second_Other_Contact_Phone__c,
12            Email = objLead.Second_Other_Contact_Email__c,AccountId = objLead.convertedAccountId));
13            lstContact.add(new contact(LastName = objLead.Third_Other_Contact_Name__c,Phone =objLead.Third_Other_Contact_Phone__c,
14            Email = objLead.Third_Other_Contact_Email__c,AccountId = objLead.convertedAccountId));
15             
16        }
17    insert lstContact;
18}
19}

+++++++++++++++++++++++++++++++++++++++++++++++++++++++

trigger Leadconv8998 on Lead (After Insert) { 

    map<Id, Lead> mapNewLead = trigger.newMap; 
    List<Contact> lstContact = new List<Contact>(); 
    for(Lead objLead: mapNewLead.values()) 
    { 
        if (objLead.isConverted == true && objLead.ConvertedAccountId != null) 
        { 
            lstContact.add(new contact(LastName = objLead.X2nd_Contact_Name__c,
                                        
                                       AccountId = objLead.convertedAccountId));
        } 
    } 
    insert lstContact; 
}

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


trigger leadconvert8 on Lead (before insert) {
/*
trigger LeadConvert on Lead (after update) {

  // no bulk processing; will only run from the UI
  if (Trigger.new.size() == 1) {

    if (Trigger.old[0].isConverted == false && Trigger.new[0].isConverted == true) {

      // if a new account was created
      if (Trigger.new[0].ConvertedAccountId != null) {

        // update the converted account with some text from the lead
        Account a = [Select a.Id, a.Description From Account a Where a.Id = :Trigger.new[0].ConvertedAccountId];
        a.Description = Trigger.new[0].Name;
        update a;

      }          

      // if a new contact was created
      if (Trigger.new[0].ConvertedContactId != null) {

        // update the converted contact with some text from the lead
        Contact c = [Select c.Id, c.Description, c.Name From Contact c Where c.Id = :Trigger.new[0].ConvertedContactId];
        c.Description = Trigger.new[0].Name;
        update c;

        // insert a custom object associated with the contact
        MyObject obj = new MyObject();
        obj.Name = c.Name;
        obj.contact__c = Trigger.new[0].ConvertedContactId;
        insert obj;

      }

      // if a new opportunity was created
      if (Trigger.new[0].ConvertedOpportunityId != null) {

        // update the converted opportunity with some text from the lead
        Opportunity opp = [Select o.Id, o.Description from Opportunity o Where o.Id = :Trigger.new[0].ConvertedOpportunityId];
        opp.Description = Trigger.new[0].Name;
        update opp;

        // add an opportunity line item
        OpportunityLineItem oli = new OpportunityLineItem();
        oli.OpportunityId = opp.Id;
        oli.Quantity = 1;
        oli.TotalPrice = 100.00;
        oli.PricebookEntryId = [Select p.Id From PricebookEntry p Where CurrencyIsoCode = 'USD' And IsActive = true limit 1].Id;
        insert oli;

      }         

    }

  }    

}*/ 

}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Final Trigger:


rigger LeadConvertyerru on Lead (after update) {

 

    map<Id, Lead> mapNewLead = trigger.newMap;

    List<Contact> lstContact = new List<Contact>();

    for(Lead objLead: mapNewLead.values())

    {

        if (objLead.isConverted == true &&  objLead.X2nd_Contact_Name__c != Null)

        {

            lstContact.add(new contact(LastName = objLead.X2nd_Contact_Name__c,
            /*  Phone = objLead.First_Other_Contact_Phone__c,

           Email = objLead.First_Other_Contact_Email__c,*/ 
           
           AccountId = objLead.convertedAccountId));

         /*   lstContact.add(new contact(LastName = objLead.Second_Other_Contact_Name__c,Phone = objLead.Second_Other_Contact_Phone__c,

            Email = objLead.Second_Other_Contact_Email__c,AccountId = objLead.convertedAccountId));

            lstContact.add(new contact(LastName = objLead.Third_Other_Contact_Name__c,Phone = objLead.Third_Other_Contact_Phone__c,

            Email = objLead.Third_Other_Contact_Email__c,AccountId = objLead.convertedAccountId));

       */      

        }

    insert lstContact;

}


++++++++++++++++++++++++++++++++++++++++++++++++++++