I'm writing a batch process where the invoice status is DUE
Send an Email based on the Configuration done in metadata.
global class InvoiceDueNotification implements Database.batchable<sObject>{
set<decimal> varDueDays = new set<decimal>();
string varInvoiceStage = 'Due';
global Database.QueryLocator start(Database.BatchableContext bc){
list<Invoice_Reminder__mdt> MetaData = [SELECT Id, Label, No_of_Days__c FROM
Invoice_Reminder__mdt WHERE Active__c = true];
For(Invoice_Reminder__mdt a : MetaData)
{
// varDueDaysLabel.add(a.Label);
varDueDays.add( Integer.valueOf(a.No_of_Days__c));
}
String query = 'SELECT Id, Family_Member__r.Name, Amount__c, Due_Date__c , Month__c, Name, Program_Name__c, Program_Price__c, stage__c, Service_Center__r.Name, Service_Center__r.D2_BEFORE_DUE_DATE__c Service_Center__r.On_Due_Date__c FROM SCInvoice__c where Stage__c =:varInvoiceStage and Due_Days__c in: varDueDays' ;
system.debug('query' + query);
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<sObject> scope){
list<Invoice_Reminder__mdt> MetaData = [SELECT Id, Label, No_of_Days__c FROM Invoice_Reminder__mdt WHERE Active__c = true];
For(Invoice_Reminder__mdt a : MetaData)
{
for(SCInvoice__c inv :(List<SCInvoice__c>) scope){
// Like inv.a.label
}
}
}
In metadata values will be D2_BEFORE_DUE_DATE__c
, .....On_Due_Date__c
with Status. In Account object Fields has been created with the same API name as metadata value.
In the above for loop For(Invoice_Reminder__mdt a : MetaData)
a.label value will be D2_BEFORE_DUE_DATE__c
, how do we dynamically fetch the column in nested for loop
Ex: If metadata value is D2_BEFORE_DUE_DATE__c
then fetch the D2_BEFORE_DUE_DATE__c
column in inner loop.
Can You please help me o this.