0

AggregateResult[] groupedResultCall = [ SELECT Account_vod__c, count(Id) 
                                        FROM Call2_vod__c 
                                        WHERE Call_Date_vod__c >= :QuarterStartDate
                                          AND Call_Date_vod__c <= :QuarterEndDate 
                                          AND Account_Type__c =: accStaticRec.Account_Type__c 
                                          AND Territory_vod__c =: accStaticRec.Territory__c 
                                          AND Status_vod__c = 'Submitted_vod' 
                                          AND (Call_Type_vod__c != 'Call Only' 
                                            OR Call_Type_vod__c != 'Event Only' 
                                            OR Call_Type_vod__c != 'Event Detail')
                                          AND Account_vod__c IN :accIdSet                                                           
                                          AND Activity_Type__c <> 'Staff'
                                        GROUP BY Account_vod__c ];

 AggregateResult[] groupedResultCall = [SELECT Account_vod__c, count(Id) 
                                        FROM Call2_vod__c 
                                        WHERE Call_Date_vod__c >= :QuarterStartDate 
                                          AND Call_Date_vod__c <= :QuarterEndDate 
                                          AND Account_Type__c =:accStaticRec.Account_Type__c 
                                          AND Territory_vod__c = :accStaticRec.Territory__c 
                                          AND Status_vod__c = 'Submitted_vod' 
                                          AND (Call_Type_vod__c != 'Call Only' 
                                            AND Call_Type_vod__c != 'Event Only' 
                                            AND Call_Type_vod__c != 'Event Detail')
                                          AND Account_vod__c IN :accIdSet  
                                          AND Activity_Type__c <> 'Staff'
                                        GROUP BY Account_vod__c ];

which query is correct. Please correct me

2 Answers 2

1

2nd one is correct.

AND (Call_Type_vod__c != 'Call Only' 
AND Call_Type_vod__c != 'Event Only' 
AND Call_Type_vod__c != 'Event Detail')

I think you want to retrieve those rows for which 'Call_Type_vod__c' value is other than these values ('Call Only', 'Event Only', 'Event Detail') . So 2nd will work.

1st query will return all the rows

AND (Call_Type_vod__c != 'Call Only' 
OR Call_Type_vod__c != 'Event Only' 
OR Call_Type_vod__c != 'Event Detail')
0

The only one difference between queries is on nested AND condition

AND (Call_Type_vod__c != 'Call Only' 
  OR Call_Type_vod__c != 'Event Only' 
  OR Call_Type_vod__c != 'Event Detail')

VS

AND (Call_Type_vod__c != 'Call Only' 
  AND Call_Type_vod__c != 'Event Only' 
  AND Call_Type_vod__c != 'Event Detail')

and it fully depends on your data model and your expectation regarding the result of this query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.