Hi all, I need to know if it is possible to add days to an invoice date at the end of the month (which therefore adds 2 months), how can I also integrate the days? IF( ISPICKVAL(Company__r.Payment_Terms__c, '30 days invoice month end + 10'), DATE(YEAR(Inv
Hello, I have an Apex class that manages whether the validated invoice date is at the end of the month or not. I also have a workflow that I used to manage payment terms (e.g. 30 days, 40.50 and so on). What I can't do is add another 10 days to an invoice date at the END OF THE MONTH. I don't know if I explained myself well, unfortunately I don't speak English very well. This is the code: public class FatturaHandlerScadenza { public static void ScadenzaFat (List<Fattura__c> LeFatture){
Map<String, TerminiDiPagamento__c> MapOfTermini = new Map<String, TerminiDiPagamento__c>(); List<TerminiDiPagamento__c> Term = [Select name, Termini_Di_Pagamento__c, Numero_di_giorno__c, Fine_Mese__c,Numero_di_mesi__c FROM TerminiDiPagamento__c ]; for(TerminiDiPagamento__c t : Term){ MapOfTermini.put(t.Termini_Di_Pagamento__c, t); }
for(Fattura__c f : LeFatture){ date DataValidazioneFattura=f.Data_Fattura__c; Integer dayToRemove = DataValidazioneFattura.day()-1;
// System.debug('è entrato per il fine del mese corrente'); } else if(MapOfTermini.get(f.Termini__c).Numero_di_giorno__c != 0 && MapOfTermini.get(f.Termini__c).Numero_di_giorno__c != null){ // System.debug('è entrato e nn è fine mese '); f.Data_Scadenza__c = DataValidazioneFattura + Integer.valueOf(MapOfTermini.get(f.Termini__c).Numero_di_giorno__c) ; } else f.Data_Scadenza__c = DataValidazioneFattura.addDays(1); // System.debug('è entrato ed è a vistas');
If you are looking to add default 10 days to invoice date at the end of each month, then you can create a lightning flow which is scheduled to execute on 30th of each month which will add 10 days to the invoice date.
For example :
An invoice INV-001 record has invoice date : 12-11-2022; on 30-11-2022 the scheduled lightning flow will execute and add 10 days to 12-11-2022.
In case you want to filter the invoices then you can add conditions to the query which you add as a step in the lightning flow.
If the question is about adding X days to a date field then you can use formula fields. In case your question is different request you to elaborate.
This is the code:
public class FatturaHandlerScadenza {
public static void ScadenzaFat (List<Fattura__c> LeFatture){
Map<String, TerminiDiPagamento__c> MapOfTermini = new Map<String, TerminiDiPagamento__c>();
List<TerminiDiPagamento__c> Term = [Select name, Termini_Di_Pagamento__c, Numero_di_giorno__c, Fine_Mese__c,Numero_di_mesi__c FROM TerminiDiPagamento__c ];
for(TerminiDiPagamento__c t : Term){
MapOfTermini.put(t.Termini_Di_Pagamento__c, t);
}
for(Fattura__c f : LeFatture){
date DataValidazioneFattura=f.Data_Fattura__c;
Integer dayToRemove = DataValidazioneFattura.day()-1;
for(TerminiDiPagamento__c t : Term){
if(MapOfTermini.get(f.Termini__c)!=null ){
if(MapOfTermini.get(f.Termini__c).Fine_Mese__c == true && (MapOfTermini.get(f.Termini__c).Numero_di_mesi__c!= 0 && MapOfTermini.get(f.Termini__c).Numero_di_mesi__c != null)){
f.Data_Scadenza__c = DataValidazioneFattura.addMonths((Integer.valueOf(MapOfTermini.get(f.Termini__c).Numero_di_mesi__c))).toStartofMonth();
// System.debug('è entrato per il fine del mese corrente');
}
else if(MapOfTermini.get(f.Termini__c).Numero_di_giorno__c != 0 && MapOfTermini.get(f.Termini__c).Numero_di_giorno__c != null){
// System.debug('è entrato e nn è fine mese ');
f.Data_Scadenza__c = DataValidazioneFattura + Integer.valueOf(MapOfTermini.get(f.Termini__c).Numero_di_giorno__c) ;
} else f.Data_Scadenza__c = DataValidazioneFattura.addDays(1);
// System.debug('è entrato ed è a vistas');
}}}}
If you are looking to add default 10 days to invoice date at the end of each month, then you can create a lightning flow which is scheduled to execute on 30th of each month which will add 10 days to the invoice date.
For example :
An invoice INV-001 record has invoice date : 12-11-2022; on 30-11-2022 the scheduled lightning flow will execute and add 10 days to 12-11-2022.
In case you want to filter the invoices then you can add conditions to the query which you add as a step in the lightning flow.