function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Alexis RodriguezAlexis Rodriguez 

Dynamic soql

Hi,

I am trying to do the following query:

select id, Name,  (select ActivityDate, whatid, WhoId from Events where ActivityDate < :someMap.get(/* parent Contact Id */).datefield__c) from Contact
But this syntax is not supported in soql.
Is there any workaround to this ?

Thank you

YuchenYuchen
So what is the error that you are getting? When you print "someMap.get(/* parent Contact Id */).datefield__c", will you see the actual date? Also, you can try creating another map between the parent contactid and the date only, then you can use theMap.get(''theContactId') to directly get the date and use in the query.
BalajiRanganathanBalajiRanganathan
You can only use simple bind variables in dynamic SOQL query strings.
String resolvedField1 = someMap.get(/* parent Contact Id */).datefield__c;
select id, Name,  (select ActivityDate, whatid, WhoId from Events where ActivityDate < :resolvedField1
) from Contact

Refer dynamic SOQL Consideration in the link given below

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_dynamic_soql.htm