You need to sign in to do that
Don't have an account?
Help with Apex Trigger
I am new to this and just started developing on the Force.com platform. I would appreciate some help with an Apex trigger that I am trying to code. I have two custom objects with a master detail relationship – Employee__c (Master) and Internal_Job_History__c (Detail). A little background on the type of data the objects hold. Employee__c holds general information about employees examples include where they live, age, tenure, phone number, etc. Internal_Job_History__c holds the job history of the employee the fields include Position title, job description, division, start and end date etc.
Employee__c has a section called Current Job Information. This area displays the employee’s current job and is populated declaratively via a cross object workflow rule which pulls data from fields located on Internal_Job_History__c. The workflow rule is based on a field in Internal_Job_History__c called Current_Job__c., which is a checkbox field. Simply put, a user indicates whether or not a particular job is the current job – if it is the data from that job populates the necessary fields on Employee__c.
The issue is that I want a trigger that will only allow one Current_Job__c checkbox to be set to True per employee. So if an employee had 3 jobs in his/her job history only one could be the current job so that if that employee took on a new job within the company I could input the information in Job History and indicate that is now the current job by selecting the Current_Job__c checkbox which in turn would automatically reset the Current_Job__c field for the record that was previously the current job. This would alleviate the user from having to go through each record and find the job with Current_Job__c checked and uncheck it and then navigate to the new job and check that one. I’ve reviewed examples from previous post, Apex Developer’s guide, Force.com cookbook and just cannot get a handle on where to start or how to code this. Any help would be greatly appreciated thanks in advance. Let me know if more info is needed.