You need to sign in to do that
Don't have an account?
Nitish 73
System.QueryException: unexpected token: ':'
Hi everyone,
I am trying to build a dynamic SOQL Query and I am getting this error. If any of you can help, I'd be very thankful.
Here is the code
Everything works fine. Even the Query string I formed in 'kjax' variable is also what I wanted.
But when I execute, I am getting the error
System.QueryException: unexpected token: ':'
When I remove the ':' , Iam getting this error
System.QueryException: expecting a colon, found 'AC__c'
Can you guys guide me as to where am I going wrong on this. Would be really grateful
Thanks
Nitish
I am trying to build a dynamic SOQL Query and I am getting this error. If any of you can help, I'd be very thankful.
Here is the code
SObjectType objToken = Schema.getGlobalDescribe().get('AC__c'); system.debug('<<<! objToken'+objtoken); DescribeSObjectResult objDef = objToken.getDescribe(); Map<String, SObjectField> fields = objDef.fields.getMap(); system.debug('<<<!!!! fields'+fields); AC__c newline = new AC__c(); newline.Is_it_for_Commercial_Use__c = 'No'; newLine.Movement_Type__c = 'Import'; String var=''; List<SObjectField> sfield = fields.values(); for(sobjectfield c: sfield){ var+=c+','; } var = var.removeEnd(','); String q = 'Select '+var+' FROM AC__c WHERE ID=\'' + 'a00r000000164eq' + '\''; //ID=\'' + varID + '\'' system.debug('<<!!! AC Fields'+q); List<sObject> sobjList = Database.query(q); system.debug(' <<<!!! sobjList ACCCCCCCC'+sobjList); system.debug('AC size '+sobjlist.size()); SObjectType objDM = Schema.getGlobalDescribe().get('Regulations_Association_Matrix__c'); system.debug('<<< objDM'+objDM); DescribeSObjectResult objDeff = objDM.getDescribe(); Map<String, SObjectField> DMfields = objDeff.fields.getMap(); system.debug('<<<<<<<<<DM Fields'+DMFields); // AC__c newline = new AC__c(); //newline.Is_it_for_Commercial_Use__c = 'No'; String var2=''; List<SObjectField> sfielddm = DMfields.values(); for(sobjectfield c: sfielddm){ var2+=c+','; } var2 = var2.removeEnd(','); system.debug('var2'+var2); String[] varlist = var2.split(','); system.debug('((((((((((((( varlist'+varlist); String dmm = 'Select '+var2+' FROM Regulations_Association_Matrix__c'; system.debug('<<!!! DM Fields'+dmm); List<sObject> sobjListDM = Database.query(dmm); system.debug('<<<!!!! SobjListDMMMMMMMMMM'+SobjListDM); system.debug('DM size '+sobjlistDM.size()); List<String> fingers = new List<String>(); List<SObjectField> lop = new List<SobjectField>(); String str=''; string first=''; Map<String, SObjectField> finalmap = new Map<String, SObjectField>(); for (String d: varlist){ if(fields.containsKey(d)) { system.debug('@@@@@@@@d'+d); fingers.add(d); finalmap.put(d,fields.get(d)); } for(sobjectfield s: finalmap.values()){ lop.add(s); } } for(sobjectfield md: lop){ str+=+'('+md+' = :'+newline+'.'+md+' OR '+md+' = '+'\'\' '+');'+' AND '; } system.debug('<<<<<<<!!!!!!!!!!!! str '+str); String kjax = 'Select '+var2+' FROM Regulations_Association_Matrix__c WHERE '+str; system.debug('<<<! kjax'+kjax); List<sObject> dmlist = Database.query(kjax);
Everything works fine. Even the Query string I formed in 'kjax' variable is also what I wanted.
But when I execute, I am getting the error
System.QueryException: unexpected token: ':'
When I remove the ':' , Iam getting this error
System.QueryException: expecting a colon, found 'AC__c'
Can you guys guide me as to where am I going wrong on this. Would be really grateful
Thanks
Nitish
Please mark as best answer if this resolves your issue.
Sorry but It didnt seem to work, still getting the same error
I need to check the dynamic query you formed.