public static List<Product2> getProduct2(List<String> Ids) {

    system.debug('productsetids' + Ids);
    Set<String> filterIds = new Set<String>();
    for(String s : Ids){

    system.debug('filterids' + filterIds);
    List<Product2> products = [SELECT Id, Name FROM Product2 WHERE Id =:filterIds];

    System.debug('returnedproducts' + products );
    return products;


productsetids and filterIds are filled but the SOQL query returns empty, the ids are valid in the system with corresponding products.

  • Can the running user see/access those records? – Raul Aug 1 '19 at 7:11
  • I can get returned records from running SOQL query on dev console. Running user is also admin. – Neophyte__c Aug 1 '19 at 7:13
  • Just to be sure it's not an issue with your Ids, can you show us one of the Ids? – Derek F Aug 2 '19 at 12:45

You might be sending a stringified list with 1 member and ids separated with commas. Use debug to check the list size.

| improve this answer | |

Firstly, you have constructor in Apex Set to convert List to Set directly. You can use like below:

Set<String> filterIds = new Set<String>(Ids);

You need not iterate over list for getting Set.

This method should definitely work. Can you check

  1. If you are definitely passing correct Product2 Ids and whether its List because I have seen implementations where you pass String of comma separated Ids but expect List of Ids - this will not happen.
  2. If above is fine, do you have access to those Products ?
| improve this answer | |
  • Run system.debug('productsetids size' + Ids.size()); to make sure your ids are not just under index 0 (size 1). This is likely the issue as you stated you and the running user are Sys Admins. – Glen De Marcos Aug 1 '19 at 8:11

you are using "=:" but it should be "in :" like following :

 List<Product2> products = [SELECT Id, Name FROM Product2 WHERE Id in :filterIds];

"=:" is used to compare only one id and you are using list so "in :".

| improve this answer | |
  • 3
    That is certainly not true. = works with Set as well – Raul Aug 1 '19 at 7:10
  • List<String> Ids is a string list and I can query ids with the set right? – Neophyte__c Aug 1 '19 at 7:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.