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
kiran2000kiran2000 

soql query

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

ManoharSFManoharSF

Kiran, it depends on requirement as each one has its meaing. 

 

First one is saying atleast one doesn't matches then you are good.

Second one is saying 'neither this nor that' for AND (Call_Type_vod__c != 'Call Only' AND Call_Type_vod__c != 'Event Only' AND Call_Type_vod__c != 'Event Detail'

 

It would be more clear, if you can include your requirement as well.

 

David SupuranDavid Supuran

the second one is complete using AND.

 

Also you might want to write it a bit cleaner for example

 

Old way: Call_Type_vod__c != 'Call Only' AND Call_Type_vod__c != 'Event Only' AND Call_Type_vod__c != 'Event Detail'

New way: Call_Type_vod__c NOT IN ('Call Only', 'Event Only', 'Event Detail')

 

Make sense?  For further reading and understanding you should really study Boolean Algebra and understand the logic conditions

 

 

[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 NOT IN ('Call Only', 'Event Only', 'Event Detail') AND
    Account_vod__c IN :accIdSet 

 

 

To further project into this query, you can optimize it by removing the negated values of '!=' if the list of values it should match isn't too long, this would be better optimized to do Call_Type_vod__c IN ('this','or','that') versus Call_Type_vod__c NOT IN (...) because the NOT IN will cause issues with large amounts of data and makes the query run slower.