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

  • How can we fetch/retrieve only one contact from account in SOQL Query in Salesforce?

    Posted by Deepak on January 17, 2020 at 3:16 PM

    How can we fetch/retrieve only one contact from account?

    • This discussion was modified 6 years ago by  Deepak.
    Deepanshu Singh replied 6 years ago 2 Members · 1 Reply
  • 1 Reply
  • 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