You need to sign in to do that
Don't have an account?
SV 9
Trigger to insert values into PBE
Have to insert historical products which are not there in PBE.
i am new to coding and now sure how to write a trigger, below is the requirement.
Object 1 ( Prod by country)
fields: Unique_id = Countryid-Prodcode
Countryid
ProdID
Prodcode
Product_Name__c
Object 2 (PricebookEntry)
Currencycode
unique_id = Prodcode-Countryid.number
isactive
IsArchived
IsArchived
Pricebook2Id
Product2Id
Productcode
UnitPrice
UseStandardPrice
Trigger on Object1(Prod by Country)
IF countryid.number=100, then
insert below product details into PBE
CurrencyISO Code = USD
External_ID__c = object1.Productcode'-'object1.countryid
IsActive = Object1. Isactive
IsArchived= false
IsArchived = obejct1.isdelete
Name = Object1.Product_Name__c
Pricebook2Id = 'USA PB ID hardcode'
Product2Id=Object1.Prodid
Productcode= Object1.Product_Code__c
UnitPrice = 1.0
UseStandardPrice = False
else if countryid.number=200
CurrencyISO Code = IST
External_ID__c = object1.Productcode'-'object1.countryid
IsActive = Object1. Isactive
IsArchived= false
IsArchived = obejct1.isdelete
Name = Object1.Product_Name__c
Pricebook2Id = 'IND PB ID hardcode'
Product2Id=Object1.Prodid
Productcode= Object1.Product_Code__c
UnitPrice = 1.0
UseStandardPrice = False
i am new to coding and now sure how to write a trigger, below is the requirement.
Object 1 ( Prod by country)
fields: Unique_id = Countryid-Prodcode
Countryid
ProdID
Prodcode
Product_Name__c
Object 2 (PricebookEntry)
Currencycode
unique_id = Prodcode-Countryid.number
isactive
IsArchived
IsArchived
Pricebook2Id
Product2Id
Productcode
UnitPrice
UseStandardPrice
Trigger on Object1(Prod by Country)
IF countryid.number=100, then
insert below product details into PBE
CurrencyISO Code = USD
External_ID__c = object1.Productcode'-'object1.countryid
IsActive = Object1. Isactive
IsArchived= false
IsArchived = obejct1.isdelete
Name = Object1.Product_Name__c
Pricebook2Id = 'USA PB ID hardcode'
Product2Id=Object1.Prodid
Productcode= Object1.Product_Code__c
UnitPrice = 1.0
UseStandardPrice = False
else if countryid.number=200
CurrencyISO Code = IST
External_ID__c = object1.Productcode'-'object1.countryid
IsActive = Object1. Isactive
IsArchived= false
IsArchived = obejct1.isdelete
Name = Object1.Product_Name__c
Pricebook2Id = 'IND PB ID hardcode'
Product2Id=Object1.Prodid
Productcode= Object1.Product_Code__c
UnitPrice = 1.0
UseStandardPrice = False
You can try checking the below link for help in writing trigger.
>> https://trailhead.salesforce.com/en/content/learn/modules/apex_triggers
>> Trigger samples for reference: [https://tekslate.com/15-sample-triggers-different-scenarios]
Also, while creating a trigger you need to follow best practices so that the trigger is future proof. [https://developer.salesforce.com/forums/?id=906F0000000DBl8IAG]
Do let me know if you are stuck somewhere.
I hope this helps and in case if this comes handy can you please choose this as best answer so that it can be used by others in the future.
Regards,
Anutej