function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Patrick FoyPatrick Foy 

Create Event From Custom Object

I have a custom object called Service Contract. The object contains the following fields Effective Date (date) and Calls Per Year (number) End Contract (checkbox). 

When a user sets up the service contract for a customers machine the customer will decide how many times per year they want the machine serviced.

For example: Starting April 1,2017 I want my machine serviced 2 times per year.
I need the event/reminder to tell the user on October 1 and April 1 to create a work order untill End Contract is checked. 
I have no idea how to work this out. My expirence with Apex is null, I do have other programing expirience and want to learn how to do this just really need some help. 

I had been advised previously to create a custom setting which I have but do not know how to proceed. 
Best Answer chosen by Patrick Foy
karthikeyan perumalkarthikeyan perumal
Hello Patick Foy, 

here is the sample for Creating event based on your services Contract entered by custome in salesfroce. 

this is not full code. 
its sampel code how you have to process further. ans after create the event you need to configure work flow to send the emai alert for that spacific user. 

this code used to create calender event when the services contract is inserted. 
 
trigger CreateCleaningEvent on Service_Contract__c (after insert) {

  List<Event> lstNewEvents = new List<Event>();

  for (ServiceContract__c SC : Trigger.new) {
  
  if( SC.End_Contract__c == True)
  {
    Event e = new Event();
    e.StartDateTime = SC.Start__c;
    e.EndDateTime = SC.End__c;
    e.Subject = SC.Subject__c;
    e.WhoId = SC.User__c;	 
    lstNewEvents.add(e);
  }
}
  insert lstNewEvents;

}

Hope this will give you some idea how you have to process further. 

Thanks
karthik
 

All Answers

karthikeyan perumalkarthikeyan perumal
Hello Patrick Foy, 

Step 1: 

Make sure which mode of communication you want to send to user to identifiy for those dates. Ex:(Email alert or Task or event or  just remainder) 

 we can use point click using workflow rule or process builder 
Or 
you have to write a apex code most case trigger for this kind of situation. 

decied the best thig thats suites your Org and let me know go further process (coding or point&click ) . 


Hoep this will clear. 

Thanks
karthik

For Instant communication: 
Skype: rajam.karthik
HP: 13392359597


 
Patrick FoyPatrick Foy
Karthik, The best mode of communication for this situation I think would be to create a calendar event and email if at all possible.
karthikeyan perumalkarthikeyan perumal
Hello Patick Foy, 

here is the sample for Creating event based on your services Contract entered by custome in salesfroce. 

this is not full code. 
its sampel code how you have to process further. ans after create the event you need to configure work flow to send the emai alert for that spacific user. 

this code used to create calender event when the services contract is inserted. 
 
trigger CreateCleaningEvent on Service_Contract__c (after insert) {

  List<Event> lstNewEvents = new List<Event>();

  for (ServiceContract__c SC : Trigger.new) {
  
  if( SC.End_Contract__c == True)
  {
    Event e = new Event();
    e.StartDateTime = SC.Start__c;
    e.EndDateTime = SC.End__c;
    e.Subject = SC.Subject__c;
    e.WhoId = SC.User__c;	 
    lstNewEvents.add(e);
  }
}
  insert lstNewEvents;

}

Hope this will give you some idea how you have to process further. 

Thanks
karthik
 
This was selected as the best answer
Patrick FoyPatrick Foy
Karthik, This should work out great. I had started down this path and thought I was going about it wrong so this will use some components I already created. Thank you so much