+ Start a Discussion
Harjeet Singh 28Harjeet Singh 28 

Custom Lead Conversion to specific oppty record types

Hi All, 

I need to auto convert a lead to oppty where converted oppty record type will depend upon the fields on leads. 
My use case is something like below:
​​​​​​Let's say I have 2checkbox fields on leads checkbox 1 and checkbox 2. 
So if I select checkbox1 then lead will convert to oppty with recordtype1
And if I select checkbox2 then lead will convert to oppty with recordtype2
Assume recordtype1 and recordtype2 exists on oppty. Also there are validations in place to ensure user can't select both checkboxes(which I have already created) 
What are my options available to achieve the above? 

I am aware about lead conversion using Process builder which invokes an invocable method in an Apex class and convert the leads to res account, contact and opportunity but I am not sure how can I set the record type of opportunity while conversion

Kindly help

Many thanks in advance

Thanks & Regards, 
Harjeet
Sainath VenkatSainath Venkat
Hi Harjeet,

first you need to fetch the recordtype ids from opportunity, you can get it by using below code.
Id recordtype1 = [select Id From RecordType WHERE DeveloperName='Opportunityrecordtype1'].Id;
        Id recordtype2 = [select Id From RecordType WHERE DeveloperName='opportunityrecordtype2'].Id;
in place of Opportunityrecordtype1 and Opportunityrecordtype2, provide the record type names that were present in your org.

then you can have if condition on lead.
if(Lead.checkbox1 == true){
 //inconversion code provide
     RecordtypeId = recordtype1;
}
same for other checkbox too.
if(Lead.checkbox2 == true){
 //inconversion code provide
     RecordtypeId = recordtype2;
}


Hope it helps for you.