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
Jim MontgomeryJim Montgomery 

sqol query in apex trigger

I have a trigger that inserts new line items into a custom object. One of the items I need to insert is the productID of a specific product.
How can I use [select id from product2 where productcode = 12345']  in an apex trigger?
Best Answer chosen by Jim Montgomery
v varaprasadv varaprasad
Hi jim,

product2  pro =  [select id from product2 where productcode = 12345' limit 1];

assign your product id like below to another record : 
object.product2id = pro.id;

Hope it helps you.

Thanks
Varaprasad



 

All Answers

sfdcMonkey.comsfdcMonkey.com
in apex trigger you can query the product2 like below query:

 list<product2 > lstOfProd = [select id from product2 where productcode = 12345'];

Hopes it helps you
thanks
v varaprasadv varaprasad
Hi jim,

product2  pro =  [select id from product2 where productcode = 12345' limit 1];

assign your product id like below to another record : 
object.product2id = pro.id;

Hope it helps you.

Thanks
Varaprasad



 
This was selected as the best answer
Jim MontgomeryJim Montgomery
Worked great. Thanks!