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
Rebecca YorkRebecca York 

Can I run multiple apex triggers on a button?

To give you a bit of context, we have a requirement to convert contacts back to leads if they are no longer being actively worked by our sales team.

I found an app on the Appexchange that does exactly this, except that it works off an Opportunity instead of a Contact! (https://appexchange.salesforce.com/listingDetail?listingId=a0N3000000B4HnnEAF)

Since my users are quite lazy, I know they are not going to be happy about creating a dummy opp, to decovert a lead, so my next thought was to create a trigger to create the dummy opp for them, and run the app off that.

The trigger I have created is this:
trigger CreateOpportunitytoRunUnconvert on Contact (after insert, after update) {
for(Contact c: trigger.new){ 
      if(c.Convert_back__c==true){
      String ContactId = c.Id;
         Opportunity[] ast = new Opportunity[]{};
         Opportunity o = new Opportunity();
         {
            o = new Opportunity();
            o.Name = 'Dummy Opp to Unconvert';
            o.Account = c.Account;
            o.AccountId = c.AccountId;
            o.LeadSource = c.LeadSource;
            o.Paid_in_Close_Month__c = 0;
            o.StageName = 'Identifying an Opportunity';
            o.CloseDate = System.Today();
            ast.add(o); 
       }
       insert ast;
     }
}
}

And the button I've created simply marks the 'convert back' checkbox which runs the trigger.

The next step to this would be to open up the newly created opportunity so we could 'unconvert' (the app I've found) from there, but I'm completely stumped on how to do this. The second option would be to run the trigger I've created, and then run their trigger without needing to navigate to the Opportunity (this would probably be preferable).

Any advice on how to achieve this, (or even a different way to achieve the same result) would be amazing!

Thanks for your help!
PratikPratik (Salesforce Developers) 
Hi Rebecca,

You will need to write your trigger code in Apex class.
Pass the trigger.new record id as a perameter to the class.

for button:
http://salesforcesource.blogspot.sg/2009/06/triggering-apex-method-with-custom.html
https://developer.salesforce.com/forums/ForumsMain?id=906F000000091bOIAQ

Hope this will help you to get started.

Thanks,
Pratik