• Home
  • About
    • Leadership
    • Partners
    • Blogroll
  • Force-Squared Blog
    • Tips and Tricks
    • Configuration
    • Development
  • Support
    • Knowledge Base
    • Submit a Case
  • Is It Dreamforce Yet?

X-Squared On Demand

Salesforce solutions delivered

  • Home
  • About
    • Leadership
    • Partners
    • Blogroll
  • Force-Squared Blog
    • Tips and Tricks
    • Configuration
    • Development
  • Support
    • Knowledge Base
    • Submit a Case
  • Is It Dreamforce Yet?
  • Tips and Tricks
  • Configuration
  • Development
You are here: Home / Salesforce CRM / Configuration / Next Birthday Formula

Next Birthday Formula

July 6, 2011 by David Schach 4 Comments

How would you display your Contacts with upcoming birthdays? I’ve seen people use “Birthdays This Week,” “Birthdays This and Next Week,” and other reports to display the list.

I’ve also seen requirements for showing a person’s next birthday, to trigger an automatic email to each Contact on his/her birthday. Let’s see how it’s done:

if(
Month (Birthdate) < = Month(Datevalue( NOW() ) ),
   if ( Month (Birthdate) < Month(Datevalue( NOW() ) ),
      DATE( YEAR( DATEVALUE( NOW() ) ) + 1 , MONTH( Birthdate ) , DAY( Birthdate ) ),
      if ( Day (Birthdate) < Day ( Datevalue ( NOW() ) ),
          DATE( YEAR( DATEVALUE( NOW() ) ) + 1 , MONTH( Birthdate ) , DAY( Birthdate ) ),
          DATE( YEAR( DATEVALUE( NOW() ) )  , MONTH( Birthdate ) , DAY( Birthdate ) )
      )
   ),
DATE( YEAR( DATEVALUE( NOW() ) ) , MONTH( Birthdate ) , DAY( Birthdate ) )
)

Next, use Batch Apex to send an email daily to all people where Next_Birthday__c == date.today(). Easy!

Now we can put this into a report and a dashboard showing the next “n” birthdays. Sure, it’s possible that more than n people will have a birthday on a given day, but at least you know that the emails will go out to each of them! If you want to see everyone with birthdays in a certain range, make a custom report and click through from a dashboard or a custom link.

Enjoy!

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to email a link to a friend (Opens in new window) Email

Related

Filed Under: Configuration, Salesforce Tagged With: Apex, Force.com Builder, Force.com Platform

← PageReference Best Practice Best Practice: Multiple Chatter Posts of the Same File →

Comments

  1. Andy Ognenoff says

    July 6, 2011 at 20:07

    Nice formula David! Saved for future reference and I would think could be used for finding next occurrence of any date just by swapping out the Birthdate field.

    Have you tested what happens with Feb 29th?

    For my own use, I also reformatted a bit. Commas at the beginning of lines in if statements make it easy to select an entire condition to add or remove for testing. Posting it back here will probably mangle it though so let me know if you want to see how how I reformatted it.

    Reply
  2. Tal Frankfurt says

    July 10, 2011 at 17:19

    Great formula! Did you look at the Birthday eMailer app on the AppExchnage (by force.com labs)?
    http://appexchange.salesforce.com/listingDetail?listingId=a0N30000003I77zEAC

    Reply
    • David Schach says

      July 11, 2011 at 11:54

      Thanks for sharing that! I took a look, and it’s great for automatically emailing birthdays and anniversaries; it doesn’t, however, provide visibility into upcoming birthdays. A great complement to this formula, though. And a great example of using Batch Apex with email templates.

      Reply
  3. David Langan says

    May 10, 2013 at 08:58

    Thank you for the formula! You made my life easier.

    For the click-not-code inclined (like myself) you can also achieve the equivalent to the Apex trigger by adding in a hidden toggle field (I use a number field. Checkbox boolean values cannot be used in workflows). I trigger the initial time-based email workflow action when the toggle value equals 1; I also add a field update to this workflow to set the toggle value to zero.

    A separate field update workflow is triggered when the toggle is updated to zero and sets the toggle to back 1 re-triggering the time based email workflow.

    Reply

Share Your ThoughtsCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Is it Dreamforce Yet?

Find out!

Find us on the AppExchange

Mass Update Contacts 2.0

Get It Now

Recent Posts

  • Prevent Duplicate Emails on Leads
  • Duplicate Record Item Enrichment and Auto-Deletion Code
  • Lightning Component With Running User Information
  • ChatterBINGO is Now Open-Source
  • Display Only My Role’s Records on a Report

Post Categories

Popular Tags

#df09 #df10 Akismet Apex AppBuilder AppExchange Appirio Astadia Blogs Chatter Configuration Content DreamFactory Dreamforce Eclipse IDE Enterprise Force.com Builder Force.com Platform Google Infowelders Integration Just for fun Lightning New Developments New Features Partner Program PersonAccount Projects Publisher Salesforce Salesforce1 Salesforce for Google Apps sfdcverse Sites Visualforce Web-to X-Squared On Demand

Find Us Online

  • Twitter
  • Facebook
  • LinkedIn
  • RSS

Subscribe

RSS Feed Comments

Subscribe via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 164 other subscribers

Copyright © 2008–2025 X-Squared On Demand · Genesis Framework by StudioPress · WordPress · Log in