3

I need to create a post with a message of happy birthday when it's the birthday of a user.

I have seen the code to create the post but I don't know how when to run it.

Should I write a trigger?

  • added from comment:

This is my code:

Global class HappyBirthday implements Schedulable{

global void execute(SchedulableContext sc) {

 List<user> lst=[Select id,name from user where date_of_birth__c =today];
   for(User u:lst){
FeedItem post = new FeedItem();

post.ParentId = u.id;

 post.Body = 'Happy birthday '+u.name;

   insert post;
}

} }

I don’t want use the button SCHEDULE CLASS. To run the class above every day where i should insert this code?

HappyBirthday happy = new HappyBirthday();

String sch = '0 0 8 * * ?';

   system.schedule('HappyJob', sch, Happy);
2
  • 3
    Can you post the link that shows how to write the code so that we can guide you from there based on what the post suggests!!
    – Rao
    Apr 26, 2013 at 20:48
  • Relevant birthday formula Apr 29, 2013 at 8:11

1 Answer 1

5

Instead of doing this with a trigger, you should just write a schedulable batch job that runs once every day. (Unfortunately workflow doesn't support chatter posts (yet))

Where your batch job's query basically is, get all the users which birthday equals today, and make a Chatter Post to their feed.

  1. Using Batch Apex
  2. Apex Scheduler
  3. Manually Schedule Apex
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .