DEV Community

Cover image for Salesforce Apex Trigger Program to Calculate Age from Birth Date in (Day, Month, Year)
Shubham Vaishnav
Shubham Vaishnav

Posted on

Salesforce Apex Trigger Program to Calculate Age from Birth Date in (Day, Month, Year)

Firstly we have to create an object of name " Date_OF_Birth_Calculat__c ".

Add two additional Custom fields Fields : Birth_date__c , Present_Age__c

Approach used below is as follows −

  • Input the birth date of a person
  • Check for the conditions
    • If current month is less than the birth month, then we will not consider the current year because this year has not been completed yet and to compute the differences in months by adding 12 to the current month.
    • If the current date is less than the birth date, then we will not consider month and for generating subtracted dates add number of month days to the current date and the result will difference in the dates.
  • When this conditions are meet just subtract the days, months and year to get the final result
  • Transfer the final age present age

Algorithm

Continue reading :- “ Salesforce Apex Trigger Program to Calculate Age from Birth Date in (Day, Month, Year) ”
https://salesforceforfresher.wordpress.com/2021/06/05/salesforce-apex-trigger-program-to-calculate-age-from-birth-date-in-day-month-year/

Top comments (0)