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
apexuserapexuser 

How to create Lead using RecordType

Hi Folks,

             I have a requirement like "creating Lead using  RecordType",How to do this? Please let me know with some sample examples/codes and any suggestions.Any help appreciated.

 

Thanks.

Pradeep_NavatarPradeep_Navatar

You can invoke SOQL query for record type to fetch lead records.

 

Recordtype rd = [Select r.SobjectType, r.Name, r.Id From RecordType r where SobjectType = 'Lead'];

 

Hope this helps.

apexuserapexuser

but how do you create lead here using  the RecordType!!!!!!!!!!!!

SargeSarge

Hi apexuser,

 

     Assuming you have a few number of record types configured for lead, use the query posted by "Pradeep_Navatar" to get record types for lead in the code. Then you choose which one is the right one to create the Lead record

e.g.

  if you want to create a lead record with record type "Global Channels Lead"

 

  Id globalChannelRTId;

  List<RecordType> lsRt = [Select r.SobjectType, r.Name, r.Id From RecordType r where SobjectType = 'Lead'];

  for(RecordType rt: lsRt){

      if(rt.Name == 'Global Channels Lead"){

            globalChannelRTId = rt.Id;

      }

  }

 

  Lead l = new Lead(RecordTypeId = globalChannelRTId, lastname= 'My Global Lead');

// set all the required fields

 insert l;

 

 

cheers..