You need to sign in to do that
Don't have an account?
debprakash shaw
Soql query for retrieve record based on picklist field
picklist field name = Member_Level__c
value= Level 1 - Parent Account Holder
Level 2 - Adult Secondary Account
Level 3 - Child Dependent Account
Select Id,Account.id,Account.name,Account__c,Parent_Member_Name__r.id,(Select Id from cases),(select Id from Contact_Products__r) from contact WHERE Member_Level__c=:Level 1 - Parent Account Holder And AccountId IN :list_Employer
I try this query in batch class but when running the code I get an error "System.QueryException: unexpected token: '1' "
please tell me how to fix that
Thanks in Advance
Please use the below code:-
query='Select Id,Account.id,Account.name,Account__c,Parent_Member_Name__r.id,(Select Id from cases),(select Id from Contact_Products__r) from contact WHERE Member_Level__c =\ 'Level 1 - Parent Account Holder\' And AccountId IN :list_Employer'
All Answers
I think the problem is you are putting a static value with ' : ' . While in apex ' : ' means you are supposed to give a variable. And if you are specifying the string value you need to put them in between ' ' .
You must try the below query :
Select Id,Account.id,Account.name,Account__c,Parent_Member_Name__r.id,(Select Id from cases),(select Id from Contact_Products__r) from contact WHERE Member_Level__c= 'Level 1 - Parent Account Holder' And AccountId IN :list_Employer
Thanks & Regards
Tushar Mathur
Hi Tushar
Thanks for replying, I try this query but I also get the error
Please use below code:-
What you was doing wrong:-
: operator use for dynamic parametr, if you use static parameter then don't need this operator
Level 1 - Parent Account Holder ->>> this is not dynamic so use in ''
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
Hi Mukesh,
Thanks for replying , after using your query like
Select Id,Account.id,Account.name,Account__c,Parent_Member_Name__r.id,(Select Id from cases),(select Id from Contact_Products__r) from contact WHERE Member_Level__c = 'Level 1 - Parent Account Holder' And AccountId IN :list_Employer
I'm getting some errors in my developer console. Error screenshot below please check that
Thanks.
According to your screenshot you have started entering string with ' and didn't end it at right place can you please provide the current code.Or else check the code correctly and then save your apex class.
Hi Tushar,
here is my code below
global Database.QueryLocator start(Database.BatchableContext bc){
if(sObjectType == 'Order'){
if(fromDate == null && toDate == null ){
query='Select Id,account_holder__r.Account__c,account_holder__r.AccountId from Order__c WHERE account_holder__r.AccountId IN:list_Employer';
}else{
query='Select Id,account_holder__r.Account__c,account_holder__r.AccountId from Order__c WHERE account_holder__r.AccountId IN:list_Employer AND (NOT (CreatedDate >=:fromDate AND CreatedDate <=: toDate))';
}
}else if(sObjectType == 'Contact'){
if(fromDate == null && toDate == null ){
query='Select Id,Account.id,Account.name,Account__c,Parent_Member_Name__r.id,(Select Id from cases),(select Id from Contact_Products__r) from Contact WHERE AccountId IN :list_Employer';
}else{
query='Select Id,Account.id,Account.name,Account__c,Member_Level__c,Parent_Member_Name__r.id,(Select Id from cases),(select Id from Contact_Products__r) from contact WHERE Member_Level__c ='Level 1 - Parent Account Holder' And AccountId IN :list_Employer AND account__c NOT IN :set_NonDeleteId AND CreatedDate >=:fromDate AND CreatedDate <=:toDate';
}
}
System.debug(query);
return Database.getQueryLocator(query);
}
Thanks,
Please use the below code:-
query='Select Id,Account.id,Account.name,Account__c,Parent_Member_Name__r.id,(Select Id from cases),(select Id from Contact_Products__r) from contact WHERE Member_Level__c =\ 'Level 1 - Parent Account Holder\' And AccountId IN :list_Employer'