You need to sign in to do that
Don't have an account?
NecroGiggles
SQOL query OR command in code not working.
I need to edit this SQOL query in this code so that it only looks at task that are (status = complet) and (Type = up to 6 diffrent values)" I asume I need to use a or statmnet but I am having no luck getting it to work. I also need to remove the part were it looks for Events. I am haveing no luck with this any help would be great.
public with sharing class OpportunityCallActivityCount { public static Boolean didRun = false; public static String oppPrefix = Opportunity.sObjectType.getDescribe().getKeyPrefix(); /* * Takes a set of opportunity IDs, queries those opportunities, and updates the activity count if appropriate */ public static void updateOpportunityCounts(Set<ID> oppIds) { if (didRun == false) { //We only want this operation to run once per transaction. didRun = true; //Query all the opportunites, including the tasks child relationships List<Opportunity> opps = [SELECT ID, Email_Activities__c, (SELECT ID FROM Tasks where Type='Email' AND Status='Completed'), (SELECT ID FROM Events) FROM Opportunity WHERE ID IN :oppIds]; List<Opportunity> updateOpps = new List<Opportunity>(); for (Opportunity o : opps) { Integer count = o.tasks.size() + o.events.size(); if (o.Call_Activity__c != count) { o.Call_Activity__c = count; updateOpps.add(o); //we're only doing updates to opps that have changed...no need to modify the others } } //Update the appropriate opportunities try { update updateOpps; } catch (Exception e) { //This is controversial. Anything could happen when updating the opportunity..validation rule, security, etc. The key is we don't //want the event update to fail...so we put a try catch around the opp update to make sure we don't stop that from happening. } } } }
Please find below the modified code:
Regards,
Mahesh
All Answers
List<Opportunity> opps = [SELECT ID, Email_Activities__c, (SELECT ID FROM Tasks where (Type='1' OR Type = '2' OR Type = '3' OR Type = '4' OR Type = '5' OR type = '6') AND Status='Completed') FROM Opportunity WHERE ID IN:oppIds];
Please find below the modified code:
Regards,
Mahesh