Activity Forums Salesforce® Discussions How can I convert the Set of Id's so that I can use this set into the Dynamic SOQL query that I want to use it with IN Comparison.

  • How can I convert the Set of Id's so that I can use this set into the Dynamic SOQL query that I want to use it with IN Comparison.

    Posted by Mohit on September 7, 2016 at 3:23 pm

    Hi All,

    How can I convert the Set of Id's so that I can use this set into the Dynamic SOQL query that I want to use it with IN Comparison.

    So how can I convert the set to string for the Dyanmic SOQL

    Please give Suggestion

    PRANAV replied 8 years, 3 months ago 2 Members · 1 Reply
  • 1 Reply
  • PRANAV

    Member
    September 8, 2016 at 5:48 am

    Hi Mohit,

    Bind variables actually work in dynamic SOQL:

    Map<Id,Account> accts = new Map<Id,Account>([select Id from Account]);
    Set<Id> accountIds = accts.keySet();
    String q = 'select id from Contact where AccountId in :accountIds';
    List<Contact> cts = Database.query(q);

    You can try the above code as an example.

    Note that you can't embed method calls (e.g. AccountId in :accts.keySet() would fail) when binding in this way.

    Hope this helps you.

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos