+ Start a Discussion
Keith Stephens 18Keith Stephens 18 

soql query with inline text

I am needing to include a string of text in my soql query. Is this possible?
In sql server the following query works and returns the text, but how do I do this using SOQL?

SELECT [LastModifeidDate]
      ,[Plaintiff_Full_Name__c]
      ,[Pliantif_Last_Name__c],
   'hello world'
  FROM [ERP].[dbo].[Cases]
Thanks,
KS
Purushotham YellankiPurushotham Yellanki
Hi Keith,

I don't think Salesforce SOQL supports using plain text in your queries. You can always use Dynamic Soql to pull data and below is a Dynamic Soql example that pulls Id, Name with couple of other fields from Account and again here I am using my field Api names that are stored in text1 and text2 variables.

String text1 = 'Text_Field_1__c';
String text2 = 'Text_Field_2__c';

String qry = 'Select Id, Name, ' + text1 + ', ' + text2 + ' From Account Limit 22';
List<Object> lstRcds = Database.query(qry);  

System.debug('************' + lstRcds);

Salesforce Documentation is the best reference guide: https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_sosl_intro.htm




Thank you