You need to sign in to do that
Don't have an account?

Getting malformed query error for the below query
Hi,
When i run this query i get Malformed query error;
qLoc = Database.getQueryLocator([Select Id, Name, Type, Status,(select Id from CampaignMembers where ContactId=:'+ objContact.Id +') from Campaign]);
When i run this query i get Malformed query error;
qLoc = Database.getQueryLocator([Select Id, Name, Type, Status,(select Id from CampaignMembers where ContactId=:'+ objContact.Id +') from Campaign]);
Please try below code.
String strQuery = ' Select Id, Name, Type, Status,(select Id from CampaignMembers where ContactId=\''+objContact.Id+'\' ) from Campaign' ;
qLoc = Database.getQueryLocator( strQuery );
Please let us know if this will help you
Thanks
Amit Chaudhary
All Answers
Please try below code.
String strQuery = ' Select Id, Name, Type, Status,(select Id from CampaignMembers where ContactId=\''+objContact.Id+'\' ) from Campaign' ;
qLoc = Database.getQueryLocator( strQuery );
Please let us know if this will help you
Thanks
Amit Chaudhary
@Amit, Thanks, it did the trick. but can you explain the logic bechind quotes and backslsahes you have incorporated in the query?