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
rameshramesh 

auto lead convertion based on recordtype

trigger code need
record type  id: 012Bg000000INcTIXX
when the stage will be 'converted - closed'   auto generate  account and contact and opportunity  based on record type (in after insert & after update)
 
bhupal reddy 7bhupal reddy 7
Hi Saki,
I hope this Trigger Code will help you !!


trigger Leadconversiontrigger on Lead (After insert, After Update) {
        List<Database.LeadConvert> MassLeadconvert = new List<Database.LeadConvert>();
        Set<ID> leadIds= new Set<ID>();
           for(Lead leadRecord : trigger.new) {
        if( leadRecord.Status == 'Closed - Converted' && leadRecord.isConverted == false){
             leadIds.add(leadRecord.Id);
        }
    }
    LeadStatus CLeadStatus= [SELECT Id, MasterLabel FROM LeadStatus WHERE  IsConverted=true Limit 1];
    for(id currentlead : LeadIds){
                Database.LeadConvert Leadconvert = new Database.LeadConvert();
                Leadconvert.setLeadId ( currentlead );                
                Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);
                Leadconvert.setDoNotCreateOpportunity(TRUE); 
                //you can remove this line if you want to create an opportunity during  conversion 
                MassLeadconvert.add(Leadconvert);
        }
    
    if (!MassLeadconvert.isEmpty()) {
            List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);
        }
    }

If this code is helpful for you Please mark as Best answer! 
Thank You.