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
Santosh K SamudralaSantosh K Samudrala 

Need Help on Converting Leads to existing account and not to create a contact

Hello , 

Need your help or advice on the e below use case :

We have thousands of Leads in our system , we are building a process to reduce them piling up and also perform a clean up activity.

As part of the process to reduce the Leads from piling up , whenever an account(source of this can be an external system) is created in our SF instance , we are actualy planning to see if we have any existing lead(with filters on some fields) and convert that lead by linking the new account created to this Lead and updating Closed Reason(Custom Field on Lead) and also to skip creating the contact.

 Below are some of the issues that i am facing when trying to implement the above process.

Scenario 1 : Tried to invoke the Leadconvert operation but facing the below issues with this.
1. Unable to skip Creation of Contact on Lead Conversion
2.Unable to set value to Custom Field of Lead upon Conversion.


Scenario 2 :   As i need to skip the contact from creation and also update the custom fields of leads while linking this to a newly created account , tried to perform the Update operation on the Lead ,  by setting the ConvertedAccountID and Custom field values to desired values. but facing the below challenges.
1. Unable to set the ConvertedAccountID , as it was readonly field.

If any one faced  such scenarios and if you are able to progress with some workaround , Please let me know.

Any help or pointers on this would be highly appreciated.
 
Raj VakatiRaj Vakati


Scenario 1 : Tried to invoke the Leadconvert operation but facing the below issues with this.


1. Unable to skip Creation of Contact on Lead Conversion 
You can not able to skip the Contact creation ( Except for personal Account ).. but you can do one think ..  create a lead conversion trigger and delete the contacts that are create as part of the lead conversion on the fly .. or you can use custom lead conversion button to do the same .. 
trigger LeadConvert on Lead (after insert,after update) {
	List<Id> conId = new List<Id>();
for(Lead myLead: Trigger.new){
if(myLead.isconverted) {
conId.add(myLead.ConvertedContactId );
	}
	}
	delete [Select id from contact where Id in :conId ] ;
}



2.Unable to set value to Custom Field of Lead upon Conversion.

Same you can do it with code or trigger 


 
Santosh K SamudralaSantosh K Samudrala
Hi Raj,
Thank you for quick response and the solution that you are suggesting , will try as suggested and will revert.
 
Raj VakatiRaj Vakati
Sure ..  i am sure it will work 
Santosh K SamudralaSantosh K Samudrala
Hi Raj,

I thought through this , but if we plan to delete the contact on Lead Trigger , it will delete the contacts even in scenarios where it should not , also i need to update Custom field with reason of auto converting the Lead , which again will not be able to do if we update the field in the trigger as the trigger doesnt know the Conversion context (I mean Lead may be converted by actually process or by the process that i am trying to build) , unless we are able to set parameters on the Lead before we are invoking the Conversion , we will not be able to identify the context and take the appropriate action.

Thanks,
Santosh
AshishkAshishk
You may need to write code in 2 different events:-
  1. Before update, here you can set the value of the custom field and then convert the lead
  2. after update, here you can delete the contact based on the condition (Use future here)
Hope this works,
Thanks
Santosh K SamudralaSantosh K Samudrala
Hi Raj and Ashish ,

I am able to acheive this with the help of your thoughts. Thank you guys for quickly chipping in and providing your thoughts.

Thanks,
Santosh