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
Swamy P R NSwamy P R N 

Hoe do i get converted LeadId in Opportunity

Hi Buddies,

I have a scenarion that, whenever lead is converted its creating an opportunity. Now i want to populate that leadid in opportunity.

or else

How can i find the opportunity is created from conversion of lead or it is created seperately in system?
Best Answer chosen by Swamy P R N
Swamy P R NSwamy P R N
Pramod try with the below code:

trigger trigMapFields on Lead (before update) {

    Map<Id,String> leadStatus = new Map<Id,String>(); // Map of the converted Contact ID and the Lead Status

    for(Lead lead : Trigger.new) {
        if (lead.IsConverted) {
            leadStatus.put(lead.ConvertedContactId,lead.Status);
        }
    }
    List<Contact> conContacts = [select Id from Contact WHERE Contact.Id IN :leadStatus.keySet()];
    for ( Contact c : conContacts) {
        c.Type__c = leadStatus.get(c.Id);
    }
    update conContacts;
}

All Answers

@anilbathula@@anilbathula@
Hi Swamy PRN

This is very simple create a check box field in lead object and make check box default true.
And create a same type of field in opportunity and map both lead on opportunity fields by standard mapping.
Thats it when a lead is converted the check box on opportunity will be true .
If opportunity is created directly it will be false.


Thanks
Anil.B


@anilbathula@@anilbathula@
And dont put any default value to opportunity check box filed.
Swamy P R NSwamy P R N
I already did this,

but i don't want to create the fields as an extra..So is there any work around with standard configuration??
Swamy P R NSwamy P R N
Standard configuration means,

In Lead we have a API called " ConvertedOpportunityId " like that is any field in opportunity like "ConvertedLeadId " ??
@anilbathula@@anilbathula@
Hi Swamy PRN

Ther is no such type of field(ConvertedLeadId) in opportunity.
The only option is to create a new filed.


Thanks
Anil.B
Swamy P R NSwamy P R N
Its resolved with the inclusion of small trigger on lead.
We have CreatedOpportunityId field on Lead Object. Once the lead is converted than we will query on newly created opportunity than we will update Lead ID field(on opportunity).
Pramod Kumar 41Pramod Kumar 41
Hello Sir @Swamy P R N 
I am also getting same issue ,if you got this solution ,Pls provide also.

Thank you,
Pramod kumar
Swamy P R NSwamy P R N
Pramod try with the below code:

trigger trigMapFields on Lead (before update) {

    Map<Id,String> leadStatus = new Map<Id,String>(); // Map of the converted Contact ID and the Lead Status

    for(Lead lead : Trigger.new) {
        if (lead.IsConverted) {
            leadStatus.put(lead.ConvertedContactId,lead.Status);
        }
    }
    List<Contact> conContacts = [select Id from Contact WHERE Contact.Id IN :leadStatus.keySet()];
    for ( Contact c : conContacts) {
        c.Type__c = leadStatus.get(c.Id);
    }
    update conContacts;
}
This was selected as the best answer
Pramod Kumar 41Pramod Kumar 41
Thank you Sir
ivan Todorov 2ivan Todorov 2
I think that there is already abetter option/s 

option 1. create a lead Id field and map it to your text field in the opportunity.
option 2. use process builder on when lead is converted  and converted opp Id <> '' - update opp-y related to the lead with the lead id value in your custom field

may be other options are also there.

in anyway you can not do a lookup as it will not work - if you only wanted to see which opp comes from a lead - use a report type "lead with converted lead information" or a similar one


 
Pramod Kumar 101Pramod Kumar 101
We have a field ConvertedOpportunityId On Lead .