1

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?

1
  • 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 at 15:54
2

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(
  'SELECT Id FROM '+
  l.API_Value__c+
  ' where '+
  l.Relationship__c+
  ' IN :accnts'
);
delete childRecords;
1
  • Thanks alot. It is working – ajith binny Mar 3 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.