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
Vikas KVikas K 

Hallo All, hallo All, list<product> p = [select Name,type from Product]; system.debug(p);

hallo All,  

when i try to execute the following query in sandbox

list<product> p = [select Name,type from Product];
system.debug(p);


i have records in the products object with name and type as columns..but when i try to fetch those records i am getting error  Invalid type: product

 Can you plz help me out in debugging this plz?
Best Answer chosen by Vikas K
sf test 18sf test 18
Hi Vikas,

There is no object API name with Product. Insted of using Product in query use Product2 (because Product is no longer available in salesforce)
Even you query from Product2, You will get the results from Product only. You can try your query as below.
List<Product2> lstProducts = [SELECT Id, Name FROM Product2];
System.debug(lstProducts);

For better clarification, you can chek the object wether it is existed or not in workbench (https://workbench.developerforce.com/login.php)  in SOQL Qery.

Let me know if you need further clarification else if you clear on this mark as best answer.

Thanks,
VK.
 

All Answers

Ajay K DubediAjay K Dubedi
Hi Kamvr,

Use Product2 instead of product, follw bellow example:
List<Product2> p = [select Name,type from Product2];
system.debug(p);

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
sf test 18sf test 18
Hi Vikas,

There is no object API name with Product. Insted of using Product in query use Product2 (because Product is no longer available in salesforce)
Even you query from Product2, You will get the results from Product only. You can try your query as below.
List<Product2> lstProducts = [SELECT Id, Name FROM Product2];
System.debug(lstProducts);

For better clarification, you can chek the object wether it is existed or not in workbench (https://workbench.developerforce.com/login.php)  in SOQL Qery.

Let me know if you need further clarification else if you clear on this mark as best answer.

Thanks,
VK.
 
This was selected as the best answer
Vikas KVikas K
Thank u for ur quick response....ur idea is working fine but say i have another field Gegenkonto__c...but when i try to fetch that its throwing an error
case-1>
List<Product2> p = [select Name,type,Gegenkonto__c from product2];
for this i am getting name,type data but i am not  getting Gegenkonto__c  data
(but i actually have Gegenkonto__c  field in the product object)

case-2>
List<Product2> p = [select Name,type,recordtype,Gegenkonto__c from product2];
in this case i am getting the below error

Line: 1, Column: 20
select id,Name,Gegenkonto__c,recordtype from Product2 ^ ERROR at Row:1:Column:30 No such column 'recordtype' on entity 'Product2'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

but when i looked at product object fields i have both the fields recordtype and Gegenkonto__c