Activity Forums Salesforce® Discussions How can we fetch/retrieve only one contact from account in SOQL Query in Salesforce?

  • Deepanshu Singh

    Member
    January 18, 2020 at 5:09 pm
    set<id> accountids = new set<id>();
    for(Contact con : Trigger.New) {        
         accountids.add(con.AccountId);
    }
    List<account> accList = [ select Name, (select AccountId, firstName, lastName from Contacts where AccountId =: accountids limit 1) from Account ];

     

     

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos

Salesforce Interview Questions and Answers - For Freshers and Experienced Candidates

Video in

Learn most important Salesforce Interview Questions and Answers, asked at every interview. These Interview questions will be useful to all entry-level candidates, beginners, interns, and…