You need to sign in to do that
Don't have an account?
Rafi Hoq 4
how to insert variable into queried string
I'm querying for my message's body text. Example - 'Hi my name '+testName+' how are you'
That string is a text field on the message object. What do I need to do in the code to make those variables work? This string needs to be queried from the object, not hardcoded in the code.
That string is a text field on the message object. What do I need to do in the code to make those variables work? This string needs to be queried from the object, not hardcoded in the code.
System.debug(formattedString);
All Answers
Try below snippet.
Review below links which gives you more information.
https://developer.salesforce.com/forums/?id=906F00000008z5BIAQ
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SOQL_variables.htm
Hope above information was helpful.
Please mark as Best Answer so that it can help others in the future.
Thanks,
Vinay Kumar
System.debug(formattedString);
Hi
seems you are trying to build dynamic query. YOu can do that by first fetching the value in a variable;
List< SelectedPropName> data= [Select SelectedPropName from SettingsObject LIMIT 1];
if(data!=null && data.size()>0
{
string SelectedProeprty = data[0].SelectedPropName;
if(SelectedPropName!=null && SelectedPropName.trim().length >0)
{
string SOQL = string.Format("Select {0} from MasterObject", new List<object> {SelectedPropName});
Object Result = Database.Query(SOQL);
}
}
Hope above information was helpful.
Please mark as Best Answer so that it can help others in the future.
Thanks,
Varun Sharma
varun.y.sharma@gmail.com