How to combine two triggers in same Trigger:
trigger createorderpricebook on Order (after update) {
List<Order> orderList = new List<Order>();
for(Order o : [SELECT Id,Status, Pricebook2Id,(SELECT Id FROM Order_Pricebooks__r) FROM Order WHERE Id IN :trigger.new]){
if(o.Order_Pricebooks__r.isEmpty()){
orderList.add(o);
}
}
List<Order_Pricebook__c> orderPriceBookList = new List<Order_Pricebook__c>();
for(Order ce:orderList) {
if(ce.status =='Activated'){
Order_Pricebook__c gh = new Order_Pricebook__c();
gh.name= 'ela';
gh.Order__c = ce.id;
gh.Price_Book__c = ce.pricebook2Id;
orderPriceBookList.add(gh);
}
}
insert orderPriceBookList;
}
2.
trigger updateorderpricebook on Order (after update) {
List<Order_Pricebook__c> orderPriceBookList = new List<Order_Pricebook__c>();
for(Order ce:trigger.new) {
list<Order_Pricebook__c> tt = [select id, Price_Book__c,Order__c from Order_Pricebook__c where Order__c =:ce.id];
for(Order_Pricebook__c io:tt)
{
if(ce.status =='Activated')
{
io.Price_Book__c = ce.priceBook2Id;
orderPriceBookList.add(io);
}
}
}
update orderPriceBookList;
}