Skip to main content
added 463 characters in body
Source Link
Adrian Larson
  • 151.3k
  • 38
  • 247
  • 431

You can't compareYou can't compare a field to another field in SOQL.

Salesforce has added a fieldclear Knowledge Article to another field in SOQLmake that clear. Take a look atFrom Field to field comparison in an SOQL WHERE clause:

Salesforce does not allow direct field to field comparison in SOQL query.

To achieve this you can create a formula field that will compare fields and return a value (such as true or false) which you can use in a WHERE clause.


Originally I also pointed to the documentation on fieldExpression Syntax (emphasis mine):

fieldName comparisonOperator value

value: A value used to compare with the value in fieldName. You must supply a value whose data type matches the field type of the specified field. You must supply a native value—other field names or calculations are not permitted. If quotes are required (for example, they are not for dates and numbers), use single quotes. Double quotes result in an error.

A common workaround is to create a checkbox formula to the same effect. Then just check if it's true in your query.

You can't compare a field to another field in SOQL. Take a look at the documentation on fieldExpression Syntax (emphasis mine):

fieldName comparisonOperator value

value: A value used to compare with the value in fieldName. You must supply a value whose data type matches the field type of the specified field. You must supply a native value—other field names or calculations are not permitted. If quotes are required (for example, they are not for dates and numbers), use single quotes. Double quotes result in an error.

A common workaround is to create a checkbox formula to the same effect. Then just check if it's true in your query.

You can't compare a field to another field in SOQL.

Salesforce has added a clear Knowledge Article to make that clear. From Field to field comparison in an SOQL WHERE clause:

Salesforce does not allow direct field to field comparison in SOQL query.

To achieve this you can create a formula field that will compare fields and return a value (such as true or false) which you can use in a WHERE clause.


Originally I also pointed to the documentation on fieldExpression Syntax (emphasis mine):

fieldName comparisonOperator value

value: A value used to compare with the value in fieldName. You must supply a value whose data type matches the field type of the specified field. You must supply a native value—other field names or calculations are not permitted. If quotes are required (for example, they are not for dates and numbers), use single quotes. Double quotes result in an error.

A common workaround is to create a checkbox formula to the same effect. Then just check if it's true in your query.

Commonmark migration
Source Link

You can't compare a field to another field in SOQL. Take a look at the documentation on fieldExpression Syntax (emphasis mine):

fieldName comparisonOperator value
 

value: A value used to compare with the value in fieldName. You must supply a value whose data type matches the field type of the specified field. You must supply a native value—other field names or calculations are not permitted. If quotes are required (for example, they are not for dates and numbers), use single quotes. Double quotes result in an error.

A common workaround is to create a checkbox formula to the same effect. Then just check if it's true in your query.

You can't compare a field to another field in SOQL. Take a look at the documentation on fieldExpression Syntax (emphasis mine):

fieldName comparisonOperator value
 

value: A value used to compare with the value in fieldName. You must supply a value whose data type matches the field type of the specified field. You must supply a native value—other field names or calculations are not permitted. If quotes are required (for example, they are not for dates and numbers), use single quotes. Double quotes result in an error.

A common workaround is to create a checkbox formula to the same effect. Then just check if it's true in your query.

You can't compare a field to another field in SOQL. Take a look at the documentation on fieldExpression Syntax (emphasis mine):

fieldName comparisonOperator value

value: A value used to compare with the value in fieldName. You must supply a value whose data type matches the field type of the specified field. You must supply a native value—other field names or calculations are not permitted. If quotes are required (for example, they are not for dates and numbers), use single quotes. Double quotes result in an error.

A common workaround is to create a checkbox formula to the same effect. Then just check if it's true in your query.

Source Link
Adrian Larson
  • 151.3k
  • 38
  • 247
  • 431

You can't compare a field to another field in SOQL. Take a look at the documentation on fieldExpression Syntax (emphasis mine):

fieldName comparisonOperator value

value: A value used to compare with the value in fieldName. You must supply a value whose data type matches the field type of the specified field. You must supply a native value—other field names or calculations are not permitted. If quotes are required (for example, they are not for dates and numbers), use single quotes. Double quotes result in an error.

A common workaround is to create a checkbox formula to the same effect. Then just check if it's true in your query.