I have a custom object Hire_Form__c that has a contact lookup. It has the following fields:
- First Name
- Last name
- Phone
- Status (In Progress , Completed , Rejected)
- Candidate (Contact Lookup)
- Description
Create Trigger on Hire_form__c
When hire_form__c record is insert set status = ‘In Progress’. Create new contact record with firstname , lastname , email, phone. Set contact id in Candidate field on Hire_form object. Create new case record for new created contact record. Set status in case = ‘New’.
When Hire_form is updated with status = ‘Completed’ , then update the status of related case ‘Closed’. This is where I'm stuck
Create Trigger on Case
- When case is updated with Status = ‘Closed’ , then check if parent contact’s related hire form status is not ‘Completed’ , then show error message ‘You can not close the case until hire form is completed’.
This is my Trigger so far and I'm stuck in the 2nd part of the first trigger:
trigger HireProcessTrigger on Hire_Form__c (before insert, before update) {
List<Contact> contList = new List<Contact>();
List<Case> caseList = new List<Case>();
// Map<ID, Hire_Form__c> formId = new Map<ID, Hire_Form__c>();
if(Trigger.isInsert){
for(Hire_Form__c form : Trigger.new){
form.status__c = 'In Progress';
Contact cont = new Contact();
cont.FirstName = form.First_Name__c;
cont.LastName = form.Last_Name__c;
cont.Email = form.Email__c;
cont.Phone = form.Phone__c;
contList.add(cont);
insert contList;
form.Candidate__c = cont.Id;
}
for(Contact con : contList){
Case cases = new Case();
cases.Status = 'New';
cases.ContactId = con.Id;
caseList.add(cases);
insert caseList;
}
}
if(Trigger.isUpdate){
for(Hire_Form__c form : Trigger.new){
}
}
}
How do I change the status of the case related to this candidate? Will I have to go through the contact and then the case? I'm confused.