Problem:
You need to create a trigger on the product object which fires every time we insert a new product, we want to make sure that we will add XYZ at the beginning of that product code.
Trigger code :
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trigger changeProductCode on Product2 (before insert) { | |
list<Product2> productList=trigger.new; | |
//newer version of the records | |
for(Product2 pro : productList) | |
{ | |
if(pro.ProductCode != null && pro.ProductCode != ' ') | |
{ | |
Pro.ProductCode = 'XYZ -' + pro.ProductCode; | |
} | |
} | |
} |
Check our trigger :
Create a new product and give product code as V305001 and hit save
And changeProductcode trigger will fire and beginning of the product code will change
Try This Assignment :
You need to create a trigger on the product object which fires every time we insert a new product and we want to make sure that we will add 'sir' at the end of that product name.
Was this blog is useful?