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

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

    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.

closed as off-topic by Raul, Vijay Ganji, glls, Mohith Shrivastava, Pranay Jaiswal Aug 5 at 9:45

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on problems in code you've written must describe the specific problem and include valid code to reproduce it. For help writing short, self-contained syntactically-valid examples, see: SSCCE.org" – Raul, Vijay Ganji, glls, Mohith Shrivastava, Pranay Jaiswal
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Can the running user see/access those records? – Raul Aug 1 at 7:11
  • I can get returned records from running SOQL query on dev console. Running user is also admin. – Neophyte__c Aug 1 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 at 12:45
1

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

2

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 ?
  • 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 at 8:11
0

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 :".

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

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