+ Start a Discussion
Saransh Bharadwaj 1Saransh Bharadwaj 1 

Need help on dynamic query

Hi Guys,

Need some help on below dynamic query. I am getting error here somewhere on 'in' operator.
 
list<Call_Memo__share> lstCallMemoShareTemp = Database.query('Select Id from Call_Memo__share'
                                                                     +'where RowCause =: '+Schema.Call_Memo__Share.RowCause.Call_Memo_Sharing_Account_Coverage_Team__c
                                                                     +'And ParentId in'
                                                                     +'(Select Id from Call_Memo__c Where'+ ParentName +' in: '+setParentId+')');

Thanks
 
CARLOS ARTURO PINTOR SALOMÓN 3CARLOS ARTURO PINTOR SALOMÓN 3
mmmm... try with a blank space between 'in' word and two points :
 
... + ' in :'+setParentId ...

 
Saransh Bharadwaj 1Saransh Bharadwaj 1
Still Same error
 
System.QueryException: unexpected token: =: Class.coverage

 
CARLOS ARTURO PINTOR SALOMÓN 3CARLOS ARTURO PINTOR SALOMÓN 3
Check out the error you got!
unexpected token: =:
There should be something wrong with that piece of code. Remember, 'IN' is a reserved word, : is a punctuation sign, both are different meaning, they don't need to be written together, use white space.
 
AmrenderAmrender

Convert you set (setParentId) to comma(,) separated string like ('SFID', 'SFID', 'SFID',....) and then pass it
 
list<Call_Memo__share> lstCallMemoShareTemp = Database.query('Select Id from Call_Memo__share'
                                                                     +' where RowCause =\'' 
																	 +Schema.Call_Memo__Share.RowCause.Call_Memo_Sharing_Account_Coverage_Team__c
                                                                     +'\' And ParentId in '
                                                                     +'(Select Id from Call_Memo__c Where'+ ParentName +' in ('+COMMA SEPARATED STRING+'))');

Regards
Amrender