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
YashhYashh 

Help On Trigge

 I want to build a trigger on product object 
so the scenario is 
when a new product is created a field should get populated as a new product.
AbhinavAbhinav (Salesforce Developers) 
Hi Yashh,

#Sample Code

trigger ProductTrigger on Product2 (before insert) {
    
    for (Product2 p : Trigger.new)
    {
        p.testCustomField__c ='New Product';
    }

}
Hope above information helps, Please mark as Best Answer so that it can help others in the future
Lukesh KarmoreLukesh Karmore

trigger YourTrigger on Product2 (After insert) {
    
    for (Product2 p : Trigger.new)
    {
        p.yourField__c='New Product';
    }
update p;
}
Suraj Tripathi 47Suraj Tripathi 47
Hi Yashh,
If you want to update the newly created product field in the trigger then you can use it before insert like given below.
 
trigger ProductSamplerigger on Product2 (before insert) {
    
    for (Product2 productObj : Trigger.new)
    {
        productObj.customField__c ='New Product';  // you can use your custom field here to assign the new Product value.
    }

}
In case you find any other issue please mention. 
If you find your Solution then mark this as the best answer. 

Thanks and Regards
Suraj Tripathi.