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
Shravan Kumar 71Shravan Kumar 71 

Update Product Details on Lead

I have a custom field on Lead - Product_ID__c which store Product ID. I am unable to sucessfully wite a trigger that lookup up to product based upon the product ID and update two fields on lead Course Code & Category Code with the values from Product object.

Any sample code would help a lot.

Best Answer chosen by Shravan Kumar 71
Raj VakatiRaj Vakati
Try this

trigger test on Lead (before update) {
	Set<Id> prds= new Set<Id>();
 for(Lead {
  prds.add(ls.Product_ID__c );
 Map<Id ,Product2> prod = new Map<Id,Product2>([select Id,Course_Code__c , Category_Code__c from Product2 where Id in : prds]);
  for(Lead {
 Product2 prd2 =   prod.get(ls.Product_ID__c) ; 
 ls.Course_Code__c = prd2.Course_Code__c;
 ls.Category_Code__c = prd2.Category_Code__c ;