0

How, in SOQL, would I assign a 0 or 1 integer value to specific string values.

Something like this, but taken out of Java pseudo-code and turned into SOQL:

if (stageName.equals(review) || stageName.equals(declined) {
    return 0;
} else if (!stageName.equals(review) || !stageName.equals(declined) {
    return 1;
}
GreyCat
  • 16,622
  • 18
  • 74
  • 112

1 Answers1

0

If you exactly know that integer value can be only 0 or 1, why you don't return and assign string representation of these values - '0' and '1'? If you don't know exact value of integer variable you always can use special function

String.valueof(integer_variable_name);

And if you want to use this assignment in SOQL query, for instaince in WHERE condition, you can use colon symbol. For example:

String review= 'review';
String declined= 'declined';
String stageName = 'declined';
List<Opportunity> opps = [SELECT Id, StageName FROM Opportunity WHERE StageName= :(stageName.equals(review) || stageName.equals(declined) ? '0':'1')];
Hleb
  • 7,037
  • 12
  • 58
  • 117