You need to sign in to do that
Don't have an account?
Visithra
Can someone help to solve dynamic soql, I have to query my sobject and its fields(ID, Name) and Where condition also dynamic SOQL and my code is below
public static void displaySobjectRecords(string objName,List<string> Fields, string field, string operator, string value){
//List<string> objFields=new List<string>{'ID','Name'};
//objFields.add('ID');
//objFields.add('Name');
String QueryStr='Select '+string.join(Fields, ',')+' From '+objName WHERE +field+' ' +operator+ ' ' +value;
List<Sobject> lstObjects=Database.query(QueryStr);
for(Sobject obj:lstObjects){
system.debug('========');
system.debug(obj.get('Name'));
system.debug(obj.get('ID'));
system.debug('========');
}
}
Thanks
//List<string> objFields=new List<string>{'ID','Name'};
//objFields.add('ID');
//objFields.add('Name');
String QueryStr='Select '+string.join(Fields, ',')+' From '+objName WHERE +field+' ' +operator+ ' ' +value;
List<Sobject> lstObjects=Database.query(QueryStr);
for(Sobject obj:lstObjects){
system.debug('========');
system.debug(obj.get('Name'));
system.debug(obj.get('ID'));
system.debug('========');
}
}
Thanks
Do you just need ID and Name fields from the object?
Thanks,
Eg if WHERE rating=HOT my soql query should bring all the records which is related to condition
Thanks,
Can you try as below.
You can execute the below in anonomous window.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,