You need to sign in to do that
Don't have an account?
SFDC@Error
How to merge two trigger in same object
Hi All
How can i merge two triiger in a single trigger on a perticular object.
I have created two trigger but not working at a time both trigger(one is working only ).so how to merge this two trigger on a single trigger.
How can i merge two triiger in a single trigger on a perticular object.
I have created two trigger but not working at a time both trigger(one is working only ).so how to merge this two trigger on a single trigger.
trigger CreateOpportunity on Boutique__c (after insert , after update) { List<Opportunity> opps = new List<Opportunity>(); for (Boutique__c boutique : Trigger.new) { if((boutique.Visit_Type__c == 'Browsing' || boutique.Visit_Type__c == 'Enquiry') && boutique.LeadType__c== 'Regular' && String.isNotBlank(boutique.Opportunity_Name__c)) { Opportunity childOpp = new Opportunity(); childOpp.Boutique__c = boutique.Id; childOpp.Name = boutique.Opportunity_Name__c; childOpp.StageName = 'Invitation'; childOpp.CloseDate = System.Today()+150; childOpp.Contact__c = boutique.Customer_Name__c; childOpp.Amount = boutique.Amount__c; childOpp.AccountId = '0012800001J3sMRAAZ'; childOpp.Assisted_By__c = boutique.Assisted_By_Look_Up__c; childOpp.Budget_Range__c = boutique.Budget_Range__c; childOpp.Stone__c = boutique.Stone__c; childOpp.Shadow_Assistance__c = boutique.Shadow_Assistance_Look_Up__c; childOpp.Visit_Type__c = boutique.Visit_Type__c; //childOpp.Enquiry_Details__c = boutique.Enquiry_Details__c; childOpp.Enquiry_Details1__c = boutique.Enquiry_Details__c; childOpp.FullName__c = boutique.Customer_Name__c; opps.add(childOpp); } } if (!opps.isEmpty()) insert opps; }
Trigger ContactCountTrigger on Boutique__c(After insert,After Delete,After Undelete) { Set<Id> setAccountIds = new Set<Id>(); //Whenever your working with After Undelete operation you can access data through //Trigger.new or Trigger.newMap but not with Trigger.old or Trigger.oldmap variables if(Trigger.isInsert || Trigger.isUndelete) { for(Boutique__c con : Trigger.new) { setAccountIds.add(con.Customer_Name__c); } } if(Trigger.isDelete) { //if you use Trigger.new below in place of Trigger.old you will end up with //System.NullPointerException:Attempt to de-reference a null object for(Boutique__c con : Trigger.old) { setAccountIds.add(con.Customer_Name__c); } } List<Contact> listAccs = [Select id,name,Total_Visit__c,(Select id from Boutiques__r) from Contact where Id in : setAccountIds]; for(Contact acc :listAccs) { acc.Total_Visit__c = acc.Boutiques__r.size(); } update listAccs; }
Please try this piece of code .
Hope its help you
Regards,
Suraj
You can use below code: