You need to sign in to do that
Don't have an account?

to query on custom settings field
Hi,
I have made opportunity stage name as custom settings field (hierarchy type). (name:Opp_Stg_Mappings__c)
I need to query on open opportunities and I did the below way.
[select Id, ownerId from Opportunity where stageName != Opp_Stg_Mappings__c.getOrgDefaults().X100_Stage_Name__c];
I am getting error message
"Error: Compile Error: unexpected token: 'Opp_Stg_Mappings__c.getOrgDefaults' ".
Please let me know how do I resolve this issue.
Thanks,
JBabu.
You are making a call (getorgdefaults) in your SOQL query. As far as I know, you can only use bind variables in your SOQL and those require a colon appear before the bind variable.
That is why you are getting the unexpected token.
I would recommend that prior to your SOQL, that you read your default into a var named "CurrentStageName" and then use this as your SOQL:
[select Id, ownerId from Opportunity where stageName != :CurrentStageName];
All Answers
You are making a call (getorgdefaults) in your SOQL query. As far as I know, you can only use bind variables in your SOQL and those require a colon appear before the bind variable.
That is why you are getting the unexpected token.
I would recommend that prior to your SOQL, that you read your default into a var named "CurrentStageName" and then use this as your SOQL:
[select Id, ownerId from Opportunity where stageName != :CurrentStageName];
Thanks a lot colemab it worked.
You can bind to functions as well:
Note the ":" before the reference. The extra variable shouldn't be necessary. I'm including this comment only for completion. colemab's answer is also perfectly acceptable. Note that function binding is not supported in dynamic SOQL (so you can't use it with Database.query(string, boolean)).
Other common examples: