I have a Lead object and would like to get all contacts for this Lead. I was not able to find an appropriate method in apex and decided to make a query. Unfortunately I don't have much experience with SOQL therefore could you please advise how to adapt the following query in SOQL. Here is the query:

select contact.* from lead, contact where lead.id = contact.Company_Name__c and lead.id = '00Q560000019qCB'

Please advise how to transform the above query in SOQL?



  • 3
    Please do not forget to mark an answer as correct if it answers your question. I've noticed that you consistently do not do this (as of this comment, you have asked 33 questions and not accepted a single answer) - it helps build a knowledge repository for anyone that has a similar issue. Dec 7, 2015 at 20:22
  • ok, thank you for your remark. I will mark it as soon as I receive an answer.
    – Dylan D
    Dec 7, 2015 at 20:26
  • Upvote for Brian's comment for emphasis - give back to the community that helps you! Now to clarify your question: In what context do you expect to receive multiple contacts for a single lead? After all, a lead can only be converted into a contact once, so a lead should have at most one contact related to it.
    – smohyee
    Dec 7, 2015 at 21:10
  • all Contacts that have same Company as the Lead? all Contacts that have same email as the Lead? or the Contact created when the Lead was converted?
    – cropredy
    Dec 8, 2015 at 1:40

1 Answer 1


There is no * in the SOQL query so you will have to specify the fields you want to pull.

I am going to ignore your need for the Company to be the same for now until you clarify your question.

to get the data from converted leads you can do the following:

Note You should ALWAYS limit your query by using selective filters as you cannot return more than 50K rows in a transaction now should you need to.

Set<ID> SetOdIds = New Set<ID>();

//Populate the set using results from another query, trigger, or something that identifies the contact IDs you are looking for. Maybe `[Select Id From Contact Where Company = 'test Company'`

[Select ConvertedContact.LastName, ConvertedContact.firstName From Lead Where isConverted = true and convertedcontactid IN :setOfIds]

You should read up and be familiar with the Force.com SOQL and SOSL Reference

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .