+ Start a Discussion
Lakshmi Kalyan KoduriLakshmi Kalyan Koduri 

there is a button in contact when click on it contact should convert to lead and after that contact is deleted from contact

Best Answer chosen by Lakshmi Kalyan Koduri
Khan AnasKhan Anas (Salesforce Developers) 
Hi Lakshmi,

You need to remove /e from Id and change instance to ap4. Also, change your trigger to after insert only.

Please change your link URL to:

https://ap4.salesforce.com/00Q/e?name_salutationlea2={!Contact.Salutation}&name_lastlea2={!Contact.LastName}&name_firstlea2={!Contact.FirstName}&lea8={!Contact.Phone}&lea3={!Account.Name}&lea11={!Contact.Email}&lea4={!Contact.Title}&lea16street={!Contact.MailingAddress}&lea16city={!Contact.MailingCity}&lea16state={!Contact.MailingState}&lea16country={!Contact.MailingCountry}&lea16zip={!Contact.MailingPostalCode}&lea9={!Contact.MobilePhone}&lea10={!Contact.Fax}&lea12={!Account.Website}&00N6F00000UHpqb={!Contact.Id}

I hope it helps you.

Kindly mark this as solved if the information was helpful.

Thanks and Regards,
Khan Anas

All Answers

Khan AnasKhan Anas (Salesforce Developers) 
Hi Lakshmi,

Greetings to you!

According to Salesforce help article (https://help.salesforce.com/articleView?id=faq_leads_can_i_convert.htm&type=5): You cannot convert existing accounts or contacts into leads. As an alternative, create an opportunity for the account or contact. If you prefer to use a lead, create a report containing the accounts or contacts you want to convert into leads, export them, and then import them as leads.

It is an idea to provide this functionality: 
https://success.salesforce.com/ideaView?id=08730000000BqfTAAS
https://success.salesforce.com/ideaView?id=08730000000BpOuAAK

But as a workaround you can follow below steps:

1. Go to setup
2.Click Customize from left side panel
3.Click contact drop down
4.Click Buttons, Links & Actions
5.Click new button or link
6. Name Label (eg. Clone/convert to lead)
7. Enter a description (eg. Clone contact details into new lead form)
8. Paste in link below into syntax box (change instance to your org instance):
https://na1.salesforce.com/00Q/e?name_salutationlea2={!Contact.Salutation}&name_lastlea2={!Contact.LastName}&name_firstlea2={!Contact.FirstName}&lea8={!Contact.Phone}&lea3={!Account.Name}&lea11={!Contact.Email}&lea4={!Contact.Title}&lea16street={!Contact.MailingAddress}&lea16city={!Contact.MailingCity}&lea16state={!Contact.MailingState}&lea16country={!Contact.MailingCountry}&lea16zip={!Contact.MailingPostalCode}&lea9={!Contact.MobilePhone}&lea10={!Contact.Fax}&lea12={!Account.Website}
9. Check syntax
10. Click Save
11. Go to contacts tab and select a contact (to see it in action)
12. Click Edit Layout - Top right hand screen
13. Add your link/button in the custom links section
14.Review your lead form and save

To delete converted contact follow below steps:

1. Create a custom field on the Lead object (Type: TEXT) with API Name From_Contact__c
2. Copy the Id of this field from URL:
User-added image

3. Update custom link syntax as (replace custom field Id on last line):
https://khananasrehmani-dev-ed.my.salesforce.com/00Q/e?name_salutationlea2={!Contact.Salutation}&name_lastlea2={!Contact.LastName}&name_firstlea2={!Contact.FirstName}&lea8={!Contact.Phone}&lea3={!Account.Name}&lea11={!Contact.Email}&lea4={!Contact.Title}&lea16street={!Contact.MailingAddress}&lea16city={!Contact.MailingCity}&lea16state={!Contact.MailingState}&lea16country={!Contact.MailingCountry}&lea16zip={!Contact.MailingPostalCode}&lea9={!Contact.MobilePhone}&lea10={!Contact.Fax}&lea12={!Account.Website}&00N7F00000RJEAk={!Contact.Id}

Note: Replace 00N7F00000RJEAk with your field Id

4. Write a trigger on the Lead object:
 
trigger DeleteConAfterLeadConvert on Lead (after insert) {
    
    if (Trigger.new[0].From_Contact__c != null) {        
        List<Contact> contactsToDelete = new List<Contact>();        
        Contact tempContact = [Select Id from Contact where Id =:Trigger.new[0].From_Contact__c];        
        contactsToDelete.add( tempContact ) ;        
        DELETE contactsToDelete;
    }
}

Reference: https://salesforce.stackexchange.com/questions/10811/how-to-convert-a-contact-back-to-lead-and-delete-the-old-contact-and-account

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Thanks and Regards,
Khan Anas
Lakshmi Kalyan KoduriLakshmi Kalyan Koduri
Hi Khan Anas,

                      I followed your steps to delete the contact after conversion to lead but still i am unable to delete the contact in contact object. Any help.

Thanks and Regards,
Lakshmi.
 
Lakshmi Kalyan KoduriLakshmi Kalyan Koduri
Hi Khan,
   
                Once contact is converted to lead, automatically converted contact should get deleted fom contacts, which is not happening in my case. Any help please.

Thanks and Regards,
Lakshmi.
​​​​​​​ 
Khan AnasKhan Anas (Salesforce Developers) 
Hi Lakshmi,

I have tried in my org and it is working fine. You might be missing something. Please share the screenshots what you have done so far (Trigger, New field id on lead, Link URL). 

Regards,
Khan Anas
Lakshmi Kalyan KoduriLakshmi Kalyan Koduri
Hi Khan Anas,

 Trigger : 

trigger DeleteContactAfterConvertedtoLead on Lead (before insert, after insert) 
{
    
     if (Trigger.new[0].from_contact__c != null) 
     {        
        List<Contact> clist = new List<Contact>();        
        Contact c = [Select Id from Contact where Id =:Trigger.new[0].from_contact__c];        
        clist.add( c ) ;        
        DELETE clist;
    }  
    
}

URL  :

User-added image

New field id on lead :  

User-added image
 
Khan AnasKhan Anas (Salesforce Developers) 
Hi Lakshmi,

You need to remove /e from Id and change instance to ap4. Also, change your trigger to after insert only.

Please change your link URL to:

https://ap4.salesforce.com/00Q/e?name_salutationlea2={!Contact.Salutation}&name_lastlea2={!Contact.LastName}&name_firstlea2={!Contact.FirstName}&lea8={!Contact.Phone}&lea3={!Account.Name}&lea11={!Contact.Email}&lea4={!Contact.Title}&lea16street={!Contact.MailingAddress}&lea16city={!Contact.MailingCity}&lea16state={!Contact.MailingState}&lea16country={!Contact.MailingCountry}&lea16zip={!Contact.MailingPostalCode}&lea9={!Contact.MobilePhone}&lea10={!Contact.Fax}&lea12={!Account.Website}&00N6F00000UHpqb={!Contact.Id}

I hope it helps you.

Kindly mark this as solved if the information was helpful.

Thanks and Regards,
Khan Anas
This was selected as the best answer
Lakshmi Kalyan KoduriLakshmi Kalyan Koduri
Hi Khan Anas,

                Thank you so much for your help. I implemented your suggestions and it worked perfect. But can you help me out in doing with visualforce pages.

Thanks and Regards,
Lakshmi.
Khan AnasKhan Anas (Salesforce Developers) 
Hi Lakshmi,

I'm glad I was able to help!

Unfortunately, it's not possible. As per Salesforce, you cannot convert existing accounts or contacts into leads. The solution which I have provided is only a workaround.

Hope it is clear to you. Also, if you might have open other question regarding the same query from a different account, please close it by marking it resolved. It will help to keep this community clean.

Thanks and Regards,
Khan Anas