• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 442
  • Last Modified:

Help with an APEX trigger that creates events based on a custom datefield for every 30 days for a year

Hello community,

Im fairly new to apex in salesforce.com and would greatly appreciate some help writting a trigger that will take a custom date field in the contact object and create follow up calendar entries every 30 days for a year.

For example ....

We have a field in the contact object called intakeDate this may be different that the actual date the contact was created. I would like the trigger to add 30 days to the date check if an event was already added and if not create the event in the owners calendar. Then add 60 days and do the same thing and 90 , 120 , 180 etc... all the way to a year.

I dont really know where to begin on this so any help or direction would be appreciated.

Thanks a ton in advance for any guidence on this.
0
joedfuse
Asked:
joedfuse
  • 3
  • 3
1 Solution
 
techhealthCommented:
Everything you need to know to start Apex programming is here:
http://www.salesforce.com/us/developer/docs/apexcode/index.htm

In your particular situation, you'll need to know how triggers work, and the type needed would be an after insert and/or an after update trigger.  The logic would be creating new Events, so you'll need to get familiar with the Event object, particularly how they're linked to Contacts (through WhoId field).  If you need to check for existing Events, then you'll need query for existing Events for the Contact using SOQL.

0
 
joedfuseAuthor Commented:
Im currently in the apex 531 class now so im getting a basic understanding. I just wasnt sure what to look for in the class to accomplish this

thanks
0
 
joedfuseAuthor Commented:
Do you know where i can get a very basic code sample to get me started. Obviously i don't expect anyone to do my work for me but it would be helpful to see something i can work from to figure it out

thanks
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
techhealthCommented:
For a basic trigger structure, you can check the section Invoking Apex > Triggers > Trigger Context Variables in the Apex Developer's Guide (my first post link).

For SOQL queries it would be under Language Constructs > SOQL and SOSL Queries on the Guide.  A query for retrieving the Events that you may need to check in your requirements may be something like this:

Event [] day30=[SELECT id FROM Event WHERE activitydate= :currentContact.intakeDate__c.addDays(30) AND WhoId=: currentContact.id];
0
 
joedfuseAuthor Commented:
Great thanks for the head start now i know where to look
0
 
techhealthCommented:
Glad to help!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now