• Welcome
  • About
    • Leadership
    • Blogroll
  • Force-Squared Blog
  • Support
    • Knowledge Base
    • Log a Case
  • Is It Dreamforce Yet?
  • Welcome
  • About
    • Leadership
    • Blogroll
  • Force-Squared Blog
  • Support
    • Knowledge Base
    • Log 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:

[sourcecode title=”Formula: Next Birthday”]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 ) ) ) [/sourcecode]

Next, use Batch Apex to send an email daily to all people where

Java
1
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!

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 →

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

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

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

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

Like Us on Facebook

Like Us on Facebook

Share This Page

Find Us Online

  • Twitter
  • Facebook
  • LinkedIn
  • Google Plus
  • X-Squared G+ Page
  • 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 5,089 other subscribers

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