You need to sign in to do that
Don't have an account?
VSK98
Getting unexpected token '('. in dynamic query
Hello All,
I was trying to restructure the static query into a dynamic query but I have been facing few issues...
Snippet Code below:
Please help me with the same..
Regards,
VSk98
I was trying to restructure the static query into a dynamic query but I have been facing few issues...
Snippet Code below:
for(user u : [select id,name,managerId from user where managerId = :UserInfo.getUserId() OR ID =: UserInfo.getUserId()]){ userMap.put(u.id,u); system.debug('userMap '+userMap); } uid = userMap.keySet(); String condition = ''+uid; condition = condition.removeStart('{'); condition = condition.removeEnd('}'); precondition = condition.split( ',' ); for(string str : precondition){ str = '\'' + str.trim() + '\'' ; fnlcondition.add(str); } String parentO = 'Account'; String childO_1 = 'Name'; String childO_2 = 'StageName'; String childO_3 = 'closeDate'; String childO_4 = 'Amount'; String childO_5 = 'Salesstage'; String childATM_1 = 'user.name'; String childATM_2 = 'TeamMemberRole'; String childATM_3 = 'AccountId'; String childO = 'Opportunity'; String child1 = 'Accountteammember'; if(childO == 'Opportunity') { childO = 'Opportunities'; } if(child1 == 'Accountteammember'){ child1 = 'Accountteammembers'; } // create dynamic SOQL query string String query = 'SELECT id,Name,Type,(select id,' +childO_1+ ',' +childO_2+ ',' +childO_3+ ',' +childO_4+ ',' +childO_5+' from ' +childO+ ') ,(select id,'+childATM_1+',' +childATM_2+ ',' +childATM_3+ ' from '+child1+ ' where UserId IN '+ fnlcondition+ ') FROM ' +parentO +' where ID IN (select ' +childATM_3+ ' from '+' Accountteammember where userID ='+fnlcondition+ ')'; // query and store results in variable p system.debug('######'+query); SObject[] p = Database.query(query); for(Integer i = 0; i < p.size(); i++){ system.debug('Parent result from SOQL query: ' +p[i]); //this can be handled dynamically if(p.get(i).getSObjects(childO) <> null){ system.debug('Child result(s) from SOQL query: ' +p.get(i).getSObjects(childO)); } if(p.get(i).getSObjects(childO_1) <> null){ system.debug('Child result(s) from SOQL query: ' +p.get(i).getSObjects(childO_1)); } }
Please help me with the same..
Regards,
VSk98