function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Scott0987Scott0987 

get a list of all products

I would like to get a list of all of the products in the org so that I can work with it.  I have tried:

 list<product2> pl = [select name, id from Product2];

but I am only getting a few products not all of them.   Any idea how I can do this?

Best Answer chosen by Admin (Salesforce Developers) 
sivaextsivaext

Hi 

 

you query is correct. I didn't find any mistake in your query. your getting few records because of OWD settings. please check your settings. 

All Answers

Jia HuJia Hu
First, which kind of records you can't extract with this query?
i.e., if you want to extract deleted ones, with all rows, like,

list<product2> pl = [select name, id from Product2 all rows];

Second, did you execute this query from Execute Anonymous directly?
If you get results from VF page or Apex class, sharing setting may hide some records based on the users.
sivaextsivaext

Hi 

 

you query is correct. I didn't find any mistake in your query. your getting few records because of OWD settings. please check your settings. 

This was selected as the best answer
Scott0987Scott0987

I figured out what was happening.  when I put system.debug(product2)  it was not displaying the entire list it was just some of them followed by ....   so it was working.  thanks for the help.