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);