How do I convert a trigger to an Apex class
<p>I need to transfer the below trigger logic to an apex class. But in apex class I cant use <code>Trigger.New</code> as it will give error. Once I give the logic in apex call, I can call the method in trigger so, Can anybody please tell me that how can I convert this trigger to an apex class?</p>

<pre><code>trigger updatecontactrolecount on Opportunity(before insert, before update) {
     Boolean isPrimary;
     Integer iCount;
     Map &lt; String, Opportunity &gt; oppty_con = new Map &lt; String, Opportunity &gt; (); //check if the contact role is needed and add it to the oppty_con map
     for (Integer i = 0; i &lt; Trigger.new.size(); i++) {
         oppty_con.put(Trigger.new[i].id,
             Trigger.new[i]);
     }
     isPrimary = False;
     for (List &lt; OpportunityContactRole &gt; oppcntctrle: [select OpportunityId from OpportunityContactRole where(OpportunityContactRole.IsPrimary = True and OpportunityContactRole.OpportunityId in : oppty_con.keySet())]) {
         if (oppcntctrle.Size() &gt; 0) {
             isPrimary = True;
         }
     }
     iCount = 0;
     for (List &lt; OpportunityContactRole &gt; oppcntctrle2: [select OpportunityId from OpportunityContactRole where(OpportunityContactRole.OpportunityId in : oppty_con.keySet())]) //Query for Contact Roles
     {
         if (oppcntctrle2.Size() &gt; 0) {
             iCount = oppcntctrle2.Size();
         }
     }
     for (Opportunity Oppty: system.trigger.new) //Check if  roles exist in the map or contact role isn't required 
     {
         Oppty.Number_of_Contacts_Roles_Assigned__c = iCount;
         Oppty.Primary_Contact_Assigned__c = isPrimary;
     }
 }
</code></pre>