Search code examples
salesforcesoql

How do I select an absent column using a literal using SOQL?


Is it possible to do something like this?

SELECT
  Id, 
  '1999-01-01T23:01:01Z' for Some_New_Date_Field__c,
  SystemModstamp
FROM Opportunity

Some_New_Date_Field__c has not been added to Opportunity yet, but I would like to return a literal value for this for now to unblock some downstream engineering work.


Solution

  • It's not possible to include a literal return value for a column in SOQL, and you also cannot set values for arbitrary property names on returned sObjects.

    In Aggregate SOQL, but not non-aggregate queries like this one, you can provide a name for a value that's used in the returned List<AggregateResult>; for example, you could do

    SELECT OwnerId, MAX(CloseDate) largestCloseDate FROM Opportunity GROUP BY OwnerId
    

    and get back AggregateResult objects that have a property largestCloseDate. I don't think that helps you here.