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
John Gallinagh 8John Gallinagh 8 

String Query not Working

Here's a query that I'm able to get working using the Force.com Explorer, but when I try to fire it in the Developer Console it doesn't work.  What am I missing?

Force.com Explorer Query:
SELECT Id, Territory_Mapping__c, Company_HQ_Country_Full_Name__c, Territory_Mapping_State_Abbreviation__c, Company_HQ_State__c, HQ_State_Value_Territory_State__c FROM Lead
where Territory_Mapping__c !=NULL
AND(Company_HQ_Country_Full_Name__c = 'United States' OR Company_HQ_Country_Full_Name__c = 'Canada')
AND HQ_State_Value_Territory_State__c = FALSE
Developer Console
String query = 'SELECT Id, Territory_Mapping__c, Company_HQ_Country_Full_Name__c, Territory_Mapping_State_Abbreviation__c, Company_HQ_State__c, HQ_State_Value_Territory_State__c FROM Lead';
where Territory_Mapping__c !=NULL
AND(Company_HQ_Country_Full_Name__c = \'United States\' 
OR Company_HQ_Country_Full_Name__c = \'Canada\')
AND HQ_State_Value_Territory_State__c = FALSE;


 
HARSHIL U PARIKHHARSHIL U PARIKH
Here are few things I can think of,
1) On  line 1 at the third row you are having ; mark which ends the query right there
2) You need to store the results in List<SObject> which is lead in your case so it should be List<Lead>

Try to use the following SOQL.
 
List<Lead> fetchingLeadRecords = [SELECT Id, Territory_Mapping__c, Company_HQ_Country_Full_Name__c, Territory_Mapping_State_Abbreviation__c, Company_HQ_State__c, HQ_State_Value_Territory_State__c FROM Lead
where Territory_Mapping__c !=NULL
AND(Company_HQ_Country_Full_Name__c = 'United States' OR Company_HQ_Country_Full_Name__c = 'Canada')
AND HQ_State_Value_Territory_State__c = FALSE ];
Hope it helps!
 
Maharajan CMaharajan C
Hi John,

Simply you can use like below in developer console:

1) In the Developer Console, click the Query Editor tab in the bottom.
2) Copy and paste the following into the first box under Query Editor, and then click Execute in bottom.

SELECT Id, Territory_Mapping__c, Company_HQ_Country_Full_Name__c, Territory_Mapping_State_Abbreviation__c, Company_HQ_State__c, HQ_State_Value_Territory_State__c FROM Lead where (Territory_Mapping__c !=NULL AND (Company_HQ_Country_Full_Name__c = 'United States' OR Company_HQ_Country_Full_Name__c = 'Canada') AND HQ_State_Value_Territory_State__c = FALSE)

The above query will display the related records based on the query condtions.

Then the query you are trying is looks like dynamic SOQL so it's a hard one because you have to define the variables to each fields which are used in the SOQL.

Can you please Let me know if it works or not and also If you face any problems!!!

If it works don't forget to mark this as a best answer!!!

Thanks,
​Raj
Maharajan CMaharajan C
Hi John,

Did you try the above things.

Can you please Let me know if it works or not and also If you face any problems!!!

If it works don't forget to mark this as a best answer!!!

Thanks,
​Raj