Skip to main content
edited title
Link
Boris Bachovski
  • 16.3k
  • 8
  • 50
  • 88

Using custom setting variable directly in direct soqla SOQL statement (System.QueryException: No such column xx entity)

Source Link
kitokid
  • 1.7k
  • 5
  • 22
  • 38

Using custom setting in direct soql statement (System.QueryException: No such column xx entity)

I want to use custom setting in direct soql statement, but it turns out not working. Because of the requirement, I can't add another field in that object.

The only thing I can do is to use Custom Setting as it might be changed frequently.

Error : System.QueryException: No such column 'defaultPost' on entity 

Coding:

MySetting__c mysetting = MySetting__c.getValues('DefaultPost');
Boolean defaultPost = mysetting.booleanValue__c;

String soql = 'SELECT myfield__c'
              + ', Name'
          + ' FROM my_object__c'
          + ' WHERE my_object__c.status__c = \'Open\''
              + ' AND (my_object__c.post__c = true OR defaultPost =:true)';

How can I put Custom Setting in the query which will allow me to change frequently?

I don't want to change the coding so many times for every changes. That is my main purpose.