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
Ravi kumar 292Ravi kumar 292 

ContactId is null

Hi all,

This is my code.

String LeadId=ApexPages.currentPage().getParameters().get('id'); 
            Lead l =[select id,Amount_in_Rs__c,Status,Application_Id__c from Lead where id=:LeadId];
            system.debug('Lead id--'+l.id); 
           Contact c = [select id,FirstName,LastName from Contact where id=:l.id];
           system.debug('contact id --'+c.id);

I am getting the Lead id from the lead query but am not getting the contact id which is related to the lead. I have one contact for the lead.

Help on this.

Thanks,
Mahesh DMahesh D
Hi Ravi,

Contact c = [select id,FirstName,LastName from Contact where id=:l.id];

Here you are using the L.Id which is wrong.

Regards,
Mahesh
Mahesh DMahesh D
Hi Ravi,

If you can explain us exactly what you are trying to achieve here then it will be easy to provide the better solution.

Contact Id will not be equal to l.Id.

Regards,
Mahesh
Amit Chaudhary 8Amit Chaudhary 8
         
           Sring LeadId=ApexPages.currentPage().getParameters().get('id'); 
           Lead l =[select id,Amount_in_Rs__c,Status,Application_Id__c from Lead where id=:LeadId];
         

           system.debug('Lead id--'+l.id); 
           Contact c = [select id,FirstName,LastName from Contact where id=:l.id]; // You are using lead id here which will never be equal to Contcact ID
           system.debug('contact id --'+c.id);

If you want to fatch the related contact then query should one lastName or any other field like below

           Contact c = [select id,FirstName,LastName from Contact where LastName =:l.LastName];
           system.debug('contact id --'+c.id);

Let us know if this will help you

Thanks
Amit Chaudhary