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
Salesforce Admin 110Salesforce Admin 110 

convert trigger to class 2

here i have trigger how do i convert to class:
 
trigger updatedeleteopps3 on Contact (after update) {
Set<Id> contactIds = new Set<Id>();

 
    
//n1

    for(contact con : Trigger.new)
    {
         if(con.active_contact__c == 'No')
              contactIds.add(con.Id);
    }




     List<easy_opportunity__c> oppsToUpdate1 = new List<easy_opportunity__c>();

     for(easy_opportunity__c opp1 : [select id, Stage__c, recordtypeid from easy_opportunity__c where Contact_Name__c in: 

contactIds and name = 'Market Appraisal' and stage__c = 'Closed Lost' and recordtypeid in (select id from recordtype 

where name = 'Residential Sales')])
     { 
          opp1.Stage__c='Closed Lost';
      opp1.Opportunity_Lost_Reason__c = 'Lost Contact';
         opp1.Opportunity_Rating__c = 'Cold';
          oppsToUpdate1.add(opp1);
     }

     update oppsToUpdate1;

 list<easy_opportunity__c> oppstodelete2 = new list<easy_opportunity__c>();
        
        for(easy_opportunity__c opp2 : [select id, stage__c, recordtypeid from easy_opportunity__c where contact_name__c 

in:contactids and (name =  'Lost MA Upsell - Gas Safety Check' or name = 'Lost MA Upsell - Home Buyer Report' or name = 'Lost MA Upsell - Conveyancing' or name = 'Lost MA Upsell - Mortgage') ])
        {
        oppstodelete2.add(opp2);
        }
        delete oppstodelete2;


//n2

 for(contact con : Trigger.new)
    {
         if(con.active_contact__c == 'No')
              contactIds.add(con.Id);
    }

     List<easy_opportunity__c> oppsToUpdate3 = new List<easy_opportunity__c>();

    for(easy_opportunity__c opp3 : [select id, Stage__c, recordtypeid from easy_opportunity__c where Contact_Name__c in: 

contactIds and name = 'Market Appraisal' and stage__c = 'Closed Won' and recordtypeid in (select id from recordtype 

where name = 'Residential Sales')])
     { 
          opp3.Stage__c='Closed Won';
      
         opp3.Opportunity_Rating__c = 'Warm';
          oppsToUpdate3.add(opp3);
     }

     update oppsToUpdate3; 

 list<easy_opportunity__c> oppstoupdate4 = new list<easy_opportunity__c>();
        
        for(easy_opportunity__c opp4 : [select id, stage__c, recordtypeid from easy_opportunity__c where contact_name__c 

in:contactids and name = 'Instruction Opportunity' and stage__c = 'Closed Won' and recordtypeid in (select id from recordtype 

where name = 'Residential Sales')])
        {
            opp4.Stage__c='Closed Lost';
      opp4.Opportunity_Lost_Reason__c = 'Lost Contact';
         opp4.Opportunity_Rating__c = 'Cold';
        oppstoupdate4.add(opp4);
        }
        update oppstoupdate4;
    
    
    //n3
 for(contact con : Trigger.new)
    {
         if(con.active_contact__c == 'No')
              contactIds.add(con.Id);
    }

     List<easy_opportunity__c> oppsToUpdate5 = new List<easy_opportunity__c>();

     for(easy_opportunity__c opp5 : [select id, Stage__c, recordtypeid from easy_opportunity__c where Contact_Name__c in: 

contactIds and name = 'Instruction Opportunity' and stage__c = 'Closed Lost' and recordtypeid in (select id from 

recordtype where name = 'Residential Sales')])
     { 
          opp5.Stage__c='Closed Lost';
      opp5.Opportunity_Lost_Reason__c = 'Lost Contact';
         opp5.Opportunity_Rating__c = 'Cold';
          oppsToUpdate5.add(opp5);
     }

     update oppsToUpdate5;

list<easy_opportunity__c> oppstodelete6 = new list<easy_opportunity__c>();
        
        for(easy_opportunity__c opp6 : [select id, stage__c, recordtypeid from easy_opportunity__c where contact_name__c 

in:contactids and (name = 'Lost Instruction Upsell - Gas Safety Check' or name = 'Lost Instruction Upsell - Home Buyer Report' or name = 'Lost Instruction Upsell - Conveyancing' or name = 'Lost Instruction Upsell - Mortgage')])
        {
        oppstodelete6.add(opp6);
        }
        delete oppstodelete6;
        
//n4

for(contact con : Trigger.new)
    {
         if(con.active_contact__c == 'No')
              contactIds.add(con.Id);
    }

     List<easy_opportunity__c> oppsToUpdate7 = new List<easy_opportunity__c>();

     for(easy_opportunity__c opp7 : [select id, Stage__c, recordtypeid from easy_opportunity__c where Contact_Name__c in: 

contactIds and name = 'Instruction Opportunity' and stage__c = 'Closed Won' and recordtypeid in (select id from 

recordtype where name = 'Residential Sales')])
     { 
          opp7.Stage__c='Closed Lost';
      opp7.Opportunity_Lost_Reason__c = 'Lost Contact';
         opp7.Opportunity_Rating__c = 'Cold';
          oppsToUpdate7.add(opp7);
     }

     update oppsToUpdate7;

list<easy_opportunity__c> oppstodelete8 = new list<easy_opportunity__c>();
        
        for(easy_opportunity__c opp8 : [select id, stage__c, recordtypeid from easy_opportunity__c where contact_name__c 

in:contactids and (name = 'Bundle 1 Opportunity' or name = 'Bundle 2 Opportunity' or name = 'Bundle 3 Opportunity') ])
        {
        oppstodelete8.add(opp8);
        }
        delete oppstodelete8;


//n5






for(contact con : Trigger.new)
    {
         if(con.active_contact__c == 'No')
              contactIds.add(con.Id);
    }

     List<easy_opportunity__c> oppsToUpdate9 = new List<easy_opportunity__c>();

     for(easy_opportunity__c opp9 : [select id, Stage__c, recordtypeid from easy_opportunity__c where Contact_Name__c in: 

contactIds and name = 'Bundle 1 Opportunity' and stage__c = 'Closed Lost' and recordtypeid in (select id from 

recordtype where name = 'Residential Sales')])
     { 
          opp9.Stage__c='Closed Lost';
      opp9.Opportunity_Lost_Reason__c = 'Lost Contact';
         opp9.Opportunity_Rating__c = 'Cold';
          oppsToUpdate9.add(opp9);
     }

     update oppsToUpdate9;

//n6

for(contact con : Trigger.new)
    {
         if(con.active_contact__c == 'No')
              contactIds.add(con.Id);
    }

     List<easy_opportunity__c> oppsToUpdate10 = new List<easy_opportunity__c>();

     for(easy_opportunity__c opp10 : [select id, Stage__c, recordtypeid from easy_opportunity__c where Contact_Name__c in: 

contactIds and name = 'Bundle 2 Opportunity' and stage__c = 'Closed Lost' and recordtypeid in (select id from 

recordtype where name = 'Residential Sales')])
     { 
          opp10.Stage__c='Closed Lost';
      opp10.Opportunity_Lost_Reason__c = 'Lost Contact';
         opp10.Opportunity_Rating__c = 'Cold';
          oppsToUpdate10.add(opp10);
     }

     update oppsToUpdate10;

//n7

for(contact con : Trigger.new)
    {
         if(con.active_contact__c == 'No')
              contactIds.add(con.Id);
    }

     List<easy_opportunity__c> oppsToUpdate11 = new List<easy_opportunity__c>();

     for(easy_opportunity__c opp11 : [select id, Stage__c, recordtypeid from easy_opportunity__c where Contact_Name__c in: 

contactIds and name = 'Bundle 3 Opportunity' and stage__c = 'Closed Lost' and recordtypeid in (select id from 

recordtype where name = 'Residential Sales')])
     { 
          opp11.Stage__c='Closed Lost';
      opp11.Opportunity_Lost_Reason__c = 'Lost Contact';
         opp11.Opportunity_Rating__c = 'Cold';
          oppsToUpdate11.add(opp11);
     }

     update oppsToUpdate11;


//n8

for(contact con : Trigger.new)
    {
         if(con.active_contact__c == 'No')
              contactIds.add(con.Id);
    }

     List<easy_opportunity__c> oppsToUpdate12 = new List<easy_opportunity__c>();

     for(easy_opportunity__c opp12 : [select id, Stage__c, recordtypeid from easy_opportunity__c where Contact_Name__c in: 

contactIds and name = 'Bundle 1 Opportunity' and stage__c = 'Closed Won' and recordtypeid in (select id from recordtype 

where name = 'Residential Sales')])
     { 
          opp12.Stage__c='Closed Lost';
      opp12.Opportunity_Lost_Reason__c = 'Lost Contact';
         opp12.Opportunity_Rating__c = 'Cold';
          oppsToUpdate12.add(opp12);
     }

     update oppsToUpdate12;

list<easy_opportunity__c> oppstodelete13 = new list<easy_opportunity__c>();
        
        for(easy_opportunity__c opp13 : [select id, stage__c, recordtypeid from easy_opportunity__c where contact_name__c 

in:contactids and (name = 'Bundle 1 Upsell Opportunity - Conveyancing' or name = 'Bundle 1 Upsell Opportunity - Premium Listing' or name = 'Bundle 1 Upsell Opportunity - EPC' or name = 'Bundle 1 Upsell Opportunity - Individual Viewings' or name = 'Bundle 1 Upsell Opportunity - Mortgage' or name = 'Bundle 1 Upsell Opportunity - Sales Progression') ])
        {
        oppstodelete13.add(opp13);
        }
        delete oppstodelete13;

//n9

for(contact con : Trigger.new)
    {
         if(con.active_contact__c == 'No')
              contactIds.add(con.Id);
    }

     List<easy_opportunity__c> oppsToUpdate14 = new List<easy_opportunity__c>();

     for(easy_opportunity__c opp14 : [select id, Stage__c, recordtypeid from easy_opportunity__c where Contact_Name__c in: 

contactIds and name = 'Bundle 2 Opportunity' and stage__c = 'Closed Won' and recordtypeid in (select id from recordtype 

where name = 'Residential Sales')])
     { 
          opp14.Stage__c='Closed Lost';
      opp14.Opportunity_Lost_Reason__c = 'Lost Contact';
         opp14.Opportunity_Rating__c = 'Cold';
          oppsToUpdate14.add(opp14);
     }

     update oppsToUpdate14;

list<easy_opportunity__c> oppstodelete15 = new list<easy_opportunity__c>();
        
        for(easy_opportunity__c opp15 : [select id, stage__c, recordtypeid from easy_opportunity__c where contact_name__c 

in:contactids and (name = 'Bundle 2 Upsell Opportunity - Hosted Open House Viewings' or name = 'Bundle 2 Upsell Opportunity - Premium Listing' or name = 'Bundle 2 Upsell Opportunity - Mortgage' )])
        {
        oppstodelete15.add(opp15);
        }
        delete oppstodelete15;

//n10

for(contact con : Trigger.new)
    {
         if(con.active_contact__c == 'No')
              contactIds.add(con.Id);
    }

     List<easy_opportunity__c> oppsToUpdate16 = new List<easy_opportunity__c>();

     for(easy_opportunity__c opp16 : [select id, Stage__c, recordtypeid from easy_opportunity__c where Contact_Name__c in: 

contactIds and name = 'Bundle 3 Opportunity' and stage__c = 'Closed Won' and recordtypeid in (select id from recordtype 

where name = 'Residential Sales')])
     { 
          opp16.Stage__c='Closed Lost';
      opp16.Opportunity_Lost_Reason__c = 'Lost Contact';
         opp16.Opportunity_Rating__c = 'Cold';
          oppsToUpdate16.add(opp16);
     }

     update oppsToUpdate16;

list<easy_opportunity__c> oppstodelete17 = new list<easy_opportunity__c>();
        
        for(easy_opportunity__c opp17 : [select id, stage__c, recordtypeid from easy_opportunity__c where contact_name__c 

in:contactids and (name = 'Bundle 3 Upsell Opportunity - Conveyancing' or name = 'Bundle 3 Upsell Opportunity - EPC' or name = 'Bundle 3 Upsell Opportunity - Mortgage') ])
        {
        oppstodelete17.add(opp17);
        }
        delete oppstodelete17;

//n11

for(contact con : Trigger.new)
    {
         if(con.active_contact__c == 'No')
              contactIds.add(con.Id);
    }

     List<easy_opportunity__c> oppsToUpdate18 = new List<easy_opportunity__c>();

     for(easy_opportunity__c opp18 : [select id, Stage__c, recordtypeid from easy_opportunity__c where Contact_Name__c in: 

contactIds and name = 'Applicant Conveyancy Opportunity' and stage__c = 'Closed Won' and recordtypeid in (select id 

from recordtype where name = 'Residential Sales')])
     { 
          opp18.Stage__c='Closed Lost';
      opp18.Opportunity_Lost_Reason__c = 'Lost Contact';
         opp18.Opportunity_Rating__c = 'Cold';
          oppsToUpdate18.add(opp18);
     }

     update oppsToUpdate18;

//n12
for(contact con : Trigger.new)
    {
         if(con.active_contact__c == 'No')
              contactIds.add(con.Id);
    }

     List<easy_opportunity__c> oppsToUpdate19 = new List<easy_opportunity__c>();

     for(easy_opportunity__c opp19 : [select id, Stage__c, recordtypeid from easy_opportunity__c where Contact_Name__c in: 

contactIds and name = 'Applicant Mortgage Opportunity' and stage__c = 'Closed Won' and recordtypeid in (select id from 

recordtype where name = 'Residential Sales')])
     { 
          opp19.Stage__c='Closed Lost';
      opp19.Opportunity_Lost_Reason__c = 'Lost Contact';
         opp19.Opportunity_Rating__c = 'Cold';
          oppsToUpdate19.add(opp19);
     }

     update oppsToUpdate19;



//n13
for(contact con : Trigger.new)
    {
         if(con.active_contact__c == 'No')
              contactIds.add(con.Id);
    }

     List<easy_opportunity__c> oppsToUpdate20 = new List<easy_opportunity__c>();

     for(easy_opportunity__c opp20 : [select id, Stage__c, recordtypeid from easy_opportunity__c where Contact_Name__c in: 

contactIds and name = 'Applicant Home Buyer Report Opportunity' and stage__c = 'Closed Won' and recordtypeid in (select 

id from recordtype where name = 'Residential Sales')])
     { 
          opp20.Stage__c='Closed Lost';
      opp20.Opportunity_Lost_Reason__c = 'Lost Contact';
         opp20.Opportunity_Rating__c = 'Cold';
          oppsToUpdate20.add(opp20);
     }

     update oppsToUpdate20;

//n14
for(contact con : Trigger.new)
    {
         if(con.active_contact__c == 'No')
              contactIds.add(con.Id);
    }

     List<easy_opportunity__c> oppsToUpdate21 = new List<easy_opportunity__c>();

     for(easy_opportunity__c opp21 : [select id, Stage__c, recordtypeid from easy_opportunity__c where Contact_Name__c in: 

contactIds and name = 'Applicant Gas Safety Check Opportunity' and stage__c = 'Closed Won' and recordtypeid in (select 

id from recordtype where name = 'Residential Sales')])
     { 
          opp21.Stage__c='Closed Lost';
      opp21.Opportunity_Lost_Reason__c = 'Lost Contact';
         opp21.Opportunity_Rating__c = 'Cold';
          oppsToUpdate21.add(opp21);
     }

     update oppsToUpdate21;
//n15   
  for(contact con : Trigger.new)
    {
         if(con.active_contact__c == 'No')
              contactIds.add(con.Id);
    }




     List<easy_opportunity__c> oppsToUpdate22 = new List<easy_opportunity__c>();

     for(easy_opportunity__c opp22 : [select id, Stage__c, recordtypeid from easy_opportunity__c where Contact_Name__c in: 

contactIds and name = 'Market Appraisal' and stage__c = 'New' and recordtypeid in (select id from recordtype 

where name = 'Residential Sales')])
     { 
          opp22.Stage__c='Closed Lost';
      opp22.Opportunity_Lost_Reason__c = 'Lost Contact';
         opp22.Opportunity_Rating__c = 'Cold';
          oppsToUpdate22.add(opp22);
     }

     update oppsToUpdate22;
    
    list<easy_opportunity__c> oppstodelete27 = new list<easy_opportunity__c>();
        
        for(easy_opportunity__c opp27 : [select id, stage__c, recordtypeid from easy_opportunity__c where contact_name__c 

in:contactids and name like '%Lost MA Upsell%' ])
        {
        oppstodelete27.add(opp27);
        }
        delete oppstodelete27;
    

   //n16
  
for(contact con : Trigger.new)
    {
         if(con.active_contact__c == 'No')
              contactIds.add(con.Id);
    }




     List<easy_opportunity__c> oppsToUpdate23 = new List<easy_opportunity__c>();

     for(easy_opportunity__c opp23 : [select id, Stage__c, recordtypeid from easy_opportunity__c where Contact_Name__c in: 

contactIds and name = 'Applicant Conveyancy Opportunity' and stage__c = 'New' and recordtypeid in (select id from recordtype 

where name = 'Residential Sales')])
     { 
          opp23.Stage__c='Closed Lost';
      opp23.Opportunity_Lost_Reason__c = 'Lost Contact';
         opp23.Opportunity_Rating__c = 'Cold';
          oppsToUpdate23.add(opp23);
     }

     update oppsToUpdate23;

//17

for(contact con : Trigger.new)
    {
         if(con.active_contact__c == 'No')
              contactIds.add(con.Id);
    }




     List<easy_opportunity__c> oppsToUpdate24 = new List<easy_opportunity__c>();

     for(easy_opportunity__c opp24 : [select id, Stage__c, recordtypeid from easy_opportunity__c where Contact_Name__c in: 

contactIds and name = 'Applicant Mortgage Opportunity' and stage__c = 'New' and recordtypeid in (select id from recordtype 

where name = 'Residential Sales')])
     { 
          opp24.Stage__c='Closed Lost';
      opp24.Opportunity_Lost_Reason__c = 'Lost Contact';
         opp24.Opportunity_Rating__c = 'Cold';
          oppsToUpdate24.add(opp24);
     }

     update oppsToUpdate24;
    
  //n18  
    
 for(contact con : Trigger.new)
    {
         if(con.active_contact__c == 'No')
              contactIds.add(con.Id);
    }




     List<easy_opportunity__c> oppsToUpdate25 = new List<easy_opportunity__c>();

     for(easy_opportunity__c opp25 : [select id, Stage__c, recordtypeid from easy_opportunity__c where Contact_Name__c in: 

contactIds and name = 'Applicant Home Buyer Report Opportunity' and stage__c = 'New' and recordtypeid in (select id from recordtype 

where name = 'Residential Sales')])
     { 
          opp25.Stage__c='Closed Lost';
      opp25.Opportunity_Lost_Reason__c = 'Lost Contact';
         opp25.Opportunity_Rating__c = 'Cold';
          oppsToUpdate25.add(opp25);
     }

     update oppsToUpdate25;   
    
    //n19
    
    for(contact con : Trigger.new)
    {
         if(con.active_contact__c == 'No')
              contactIds.add(con.Id);
    }




     List<easy_opportunity__c> oppsToUpdate26 = new List<easy_opportunity__c>();

     for(easy_opportunity__c opp26 : [select id, Stage__c, recordtypeid from easy_opportunity__c where Contact_Name__c in: 

contactIds and name = 'Applicant Gas Safety Check Opportunity' and stage__c = 'New' and recordtypeid in (select id from recordtype 

where name = 'Residential Sales')])
     { 
          opp26.Stage__c='Closed Lost';
      opp26.Opportunity_Lost_Reason__c = 'Lost Contact';
         opp26.Opportunity_Rating__c = 'Cold';
          oppsToUpdate26.add(opp26);
     }

     update oppsToUpdate26;  
    
    
    
    
    
    
    
    
       
    }

 
pconpcon
It sounds like you're looking for someone to write the code for this project. These forums are not meant for that; you'll want to post over on the AppExchange site [1] where you can match up with a developer looking to work on your project. I would suggest reading over these articles [2] [3] and if you have any specific questions feel free to ask them.

[1] https://appexchange.salesforce.com/developers
[2] http://blog.deadlypenguin.com/blog/2012/02/13/classifying-triggers-in-salesforce/
[3] https://developer.salesforce.com/page/Trigger_Frameworks_and_Apex_Trigger_Best_Practices