You need to sign in to do that
Don't have an account?

Need help in creating Due date from static to dynamic
Here i have created Picklist(Premium_Type : monthly, quarterly, half-yearly and annually) , Premium_start_Date, End_Date and Premium_Due_Date and with some help updated the code, which is a static one. The code is
public with sharing class LICDueDate
{
public static void DueDateInsert (list<Life_Insurance_Data__c> Due)
{
for(Life_Insurance_Data__c D : Due)
if(D.Premium_Type__c == 'Monthly')
{
D.Premium_Due__c = D.Premium_Start_Date__c.addMonths(1) - 5;
}
else if(D.Premium_Type__c == 'Quarterly' )
{
D.Premium_Due__c = D.Premium_Start_Date__c.addMonths(3) - 5;
}
else if(D.Premium_Type__c == 'Half-Yearly')
{
D.Premium_Due__c = D.Premium_Start_Date__c.addMonths(6) - 5;
}
else if(D.Premium_Type__c == 'Yearly')
{
D.Premium_Due__c = D.Premium_Start_Date__c.addMonths(12) - 5;
}
}
Here the code works fine and i got one problem.
I am getting Due Date correctly for the 1st time and it is not working when the due date has paid, it should move on to the next month due date. please refere the image below.
Here i need like If i choose (D.Premium_Type__c == 'Monthly') and start date is 01/02/2019.
The premium due will be : 24/02/2019 ( perfect till now)
when i paid my Due amount on or before 24/2/2019 in my "LIC_Payement_Gateways" and considering my "Paid_Date__c", the due date should change to next month : 27/03/2019 and it should go on with Monthly, quarterly, half-yearly and yearly ( this is what i want to do )
Any one can help me in this ?
Thanks in advance.
public with sharing class LICDueDate
{
public static void DueDateInsert (list<Life_Insurance_Data__c> Due)
{
for(Life_Insurance_Data__c D : Due)
if(D.Premium_Type__c == 'Monthly')
{
D.Premium_Due__c = D.Premium_Start_Date__c.addMonths(1) - 5;
}
else if(D.Premium_Type__c == 'Quarterly' )
{
D.Premium_Due__c = D.Premium_Start_Date__c.addMonths(3) - 5;
}
else if(D.Premium_Type__c == 'Half-Yearly')
{
D.Premium_Due__c = D.Premium_Start_Date__c.addMonths(6) - 5;
}
else if(D.Premium_Type__c == 'Yearly')
{
D.Premium_Due__c = D.Premium_Start_Date__c.addMonths(12) - 5;
}
}
Here the code works fine and i got one problem.
I am getting Due Date correctly for the 1st time and it is not working when the due date has paid, it should move on to the next month due date. please refere the image below.
The premium due will be : 24/02/2019 ( perfect till now)
when i paid my Due amount on or before 24/2/2019 in my "LIC_Payement_Gateways" and considering my "Paid_Date__c", the due date should change to next month : 27/03/2019 and it should go on with Monthly, quarterly, half-yearly and yearly ( this is what i want to do )
Any one can help me in this ?
Thanks in advance.
Change all 4 lines to: if( D.total_payments_made__c!=0) nummonths=1*(integer.valueOf(D.total_payments_made__c));
See this link: https://salesforce.stackexchange.com/questions/4628/compile-error-illegal-assignment-from-decimal-to-integer (https://salesforce.stackexchange.com/questions/4628/compile-error-illegal-assignment-from-decimal-to-integer)
DM me if there are further errors. Contact details are there on my site.
All Answers
I would approach it in this way: make the above trigger only on insert. I am assuming start date and Premium Type can not be changed later.
Now create an insert trigger on LIC_payment_gateways object and compute the next due date from paid date, Premium Type and start date.
Let me know if you need help with the code.
If the start date and Premium Type can be changed in between, after few payments have been made, you will need to consider an insert, update trigger.
Thanks.
I hope you find the above solution helpful.
Thanks and Regards,
Neha Aggrawal
www.initaura.com - Everything Salesforce (https://initaura.com/)
Thanks for the quick reply, as i am a newbie to salesforce and coding. I working on my best and i dont know how to write the logic exactly and where to start.
For my query, i am looking for this " From LIC_payment_gateways object need to compute the next due date from paid date". I am struck with how to do that.
Object : LIC_Payment_Gateway__c
Fields used :
Object : Life_Insurance_Data__c
Fields used :
As you said : "Now create an insert trigger on LIC_payment_gateways object and compute the next due date from paid date, Premium Type and start date. Let me know if you need help with the code."
Now i need your help. Help with the code
Thanks in advance.
Sorry, I just saw the roll up field total_payment_made. That simplifies things.
Just update your existing code to something like this:
The above code should run whenever your roll up summary field updates (which will be when a new record is inserted in LIC_Payment_Gateway__c. Your trigger should be both insert and update trigger.
Not tested, please check once.
Thanks.
I hope you find the above solution helpful.
Thanks and Regards,
Neha Aggrawal
www.initaura.com - Everything Salesforce (https://initaura.com)
Thanks for helping me with the code. I tested the code and i am getting error..Please have a look
Many many thanks for helping me this much.
I add semicolon at the end of those line and one new error came up stating as...
What i am expecting for this error is, we have used "D.total_payments_made__c " which is a currency & it is a decimal one.
We have written "Integer nummonths=0" and it is a integer value.
Now how we are going to convert Decimal to integer ?
Change all 4 lines to: if( D.total_payments_made__c!=0) nummonths=1*(integer.valueOf(D.total_payments_made__c));
See this link: https://salesforce.stackexchange.com/questions/4628/compile-error-illegal-assignment-from-decimal-to-integer (https://salesforce.stackexchange.com/questions/4628/compile-error-illegal-assignment-from-decimal-to-integer)
DM me if there are further errors. Contact details are there on my site.
I am very very thankful to you. Finally i acheived what i want with your support. Thanks for your guidance.
Here i am sharing the code which works perfect.
public with sharing class LICDueDate
{
public static void DueDateInsert (list<Life_Insurance_Data__c> Due)
{
Integer nummonths=0;
for(Life_Insurance_Data__c D : Due)
if(D.Premium_Type__c == 'Monthly')
{
if( D.total_payments_made__c!=0) nummonths=1*(integer.valueOf(D.total_payments_made__c)+1);
else nummonths=1;
D.Premium_Due__c = D.Premium_Start_Date__c.addMonths(nummonths) - 5;
}
else if(D.Premium_Type__c == 'Quarterly' )
{
if( D.total_payments_made__c!=0) nummonths=3*(integer.valueOf(D.total_payments_made__c)+1);
else nummonths=3;
D.Premium_Due__c = D.Premium_Start_Date__c.addMonths(nummonths) - 5;
}
else if(D.Premium_Type__c == 'Half-Yearly')
{
if( D.total_payments_made__c!=0) nummonths=6*(integer.valueOf(D.total_payments_made__c)+1);
else nummonths=6;
D.Premium_Due__c = D.Premium_Start_Date__c.addMonths(nummonths) - 5;
}
else if(D.Premium_Type__c == 'Yearly')
{
if( D.total_payments_made__c!=0) nummonths=12*(integer.valueOf(D.total_payments_made__c)+1);
else nummonths=12;
D.Premium_Due__c = D.Premium_Start_Date__c.addMonths(nummonths) - 5;
}
}
Please mark the answer as solved.