I need to use run a query based on the value in custom settings. Delete_Lookup__c is my custom settings. I need to change the output of query based on the values in custom settings.

    global class CustomHelperClass {
        public static void deleteDealPipeline(List<Id> accnts){
           system.debug('Account Trigger  '+accnts);
           List<Delete_Lookup__c> lookup =Delete_Lookup__c.getAll().values();
           for(Delete_Lookup__c l : lookup){
                List<Deal_Pipeline__c> dealPipelines = [SELECT Id, Name FROM l.API_Value__c where l.Relationship__c.Id IN :accnts];
                system.debug('SOQL Account  '+dealPipelines);
                delete dealPipeLines; 

I'm getting an error "Invalid type: Schema.API_Value__c" in the SOQL query. Can anyone help me to understand the issue here?

  • Apart from getting an answer to your question, you should take some time to review Apex Design Best Practices and move your SOQL & DML outside of your for loop.
    – TSmith
    Mar 3, 2021 at 15:54

1 Answer 1


Assuming I understand your code correctly, you need a dynamic query for this, since you're trying to use a variable in the FROM clause:

List<sObject> childRecords = Database.query(
  ' where '+
  ' IN :accnts'
delete childRecords;
  • Thanks alot. It is working Mar 3, 2021 at 14:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .