You need to sign in to do that
Don't have an account?

reducing soqls - too many soql queries
i am trying to tidy my code so that i reduce the number of soqls here is a sample
public class updatedeletopps { public static void updatedelopps(List<Contact> contactIds){ Id recId = Schema.SObjectType.Easy_Opportunity__c.getRecordTypeInfosByName().get('Residential Sales').getRecordTypeId(); //n1 // contact[] activecontacts = [select id, active_contact__c from contact where id in :contactIds]; set<id> activecontactsset = new set<id>(); for(contact con : activecontacts) if(con.active_contact__c == 'No') activecontactsset.add(con.Id); List<easy_opportunity__c> oppsToUpdate1 = new List<easy_opportunity__c>(); list<easy_opportunity__c> opptys = [select id, Stage__c, recordtypeid from easy_opportunity__c where Contact_Name__c in: activecontactsset and name = 'Market Appraisal' and stage__c = 'Closed Lost' and recordtypeid = :recId]; for(easy_opportunity__c opp1 : opptys) { 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>(); list<easy_opportunity__c> opptys1 = [select id, stage__c, recordtypeid from easy_opportunity__c where contact_name__c in:activecontactsset 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') ]; for(easy_opportunity__c opp2 : opptys1) { oppstodelete2.add(opp2); } delete oppstodelete2;
here's the trigger: