Skip to main content
5 of 8
added 18 characters in body
Keith C
  • 137.3k
  • 29
  • 218
  • 458

APEX trigger lookup field value in onther custom object

today I signed in on SF Stackexchange and I'm a newbie on Apex.

My User story: Uptill know we used an MS Access application for complaint registration/handling. Because we want to get rid of MS Access applications I created an object in SF called Complaints__c. Creating a task for the complaint handler, sending him/her an email that a complaint is assigned to him/her and logging that email on the activity timeline works great. Notification by email on task creation is usually switched by our users so I forced sending an email and adding it to the activity line)

Last thing I want to do is auto fill the deadline. When a new complaint is registered, the complaint handler has to do a follow up before the Deadline that is set when de complaint is registerd. The Deadline can depend on 2 values in another field, let's say Option: option 1, Option 2 If Option 1 is chosen, the Deadline is different then when option 2 was chosen. I have a second Custom object Called PeriodOfTime__c that contains Id, Name, Date__c, Option1Date__c, Option2Date__c. On registration I would like use an apex trigger to fill (before insert) the field Deadline__c in my Complaints__c object with the value of Option1Date__c or Option2Date__c from the Object PeriodOfTime__c where PeriodOfTime__c.Date__c = date.today() I stored these dates in this table to make sure that Option1Date__c and Option2Date__c are never a saterday, sunday or a special day, like Christmas. I would like to get something like:

If(Option = Option 1)
  {Complaint.Deadline__c = OptionDate1;}
Else  
  {Complaint.Deadline__c = OptionDate2;}

Getting user info like:

User H = [select Id, Email, Department, Division from User where Id =: 'some userID'];

is easy but getting Option1Date__c and Option2Date__c from:

[select Id, Option1Date__c, Option2Date__c from PeriodeOfTime__c where Date__c =: date.today()]

doesn't seem to work the same way on a custom object. Can anyone help me how to do this. I guess it must be something with list or set by I can't figger out how. Thanx