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
Salesforce Dev in TrainingSalesforce Dev in Training 

Cases to Contacts

I'm trying to map "Cases" when I convert a Lead to a Contact. I have a Lookup field on the Cases object for Leads, so I know they're able to be attached. However, I need to create some code that will keep the Case attached to the Lead when the Lead converts to a Contact. Right now, the Case isn't attaching to the newly converted Contact.
Salesforce Dev in TrainingSalesforce Dev in Training

User-added image

^ Here is my code

User-added image

^ Here is the error I receive

Does anybody have a solution for this?

Ravi Dutt SharmaRavi Dutt Sharma
Hi,

The  query should be use Contact.Id instead of Contact. Let me know if this helps. Thanks.
Salesforce Dev in TrainingSalesforce Dev in Training
Thank you @Ravi, bu I am still receiving an error.
Salesforce Dev in TrainingSalesforce Dev in Training
User-added image
Salesforce Dev in TrainingSalesforce Dev in Training
//Code for mapping the Cases from Lead to the contact
        List<Case> Cserecords = new List<Case>();
        try{            
           // system.debug('---leadContIdMap------'+leadContIdMap);
            Cserecords = [Select Id,Contact.id,Lead__c from Case where Lead__c IN :leadContIdMap.keySet() ];
            //system.debug('------surveysList size-----'+splrecords.size());
        }catch(QueryException ex){}
        
        for(Case Cse :Cserecords){
           // system.debug('------Lead__c-----'+sp.Lead__c);
            Cse.Contact.id = leadContIdMap.get(Cse.Lead__c);
            //System.debug('------Contact__c-----'+sp.Contact__c);
            //p.Lead__c = null;
        }
        if(Cserecords!=null && Cserecords.size() >0)
            update CseRecords;