I have a specific scenario which I feel is a bit challenging and I would like to ask people's views in this forum on what they think could be a solution
I have an custom object (employees__c) which stores employees record of a company. This employee data is uploaded using data loader into salesforce every day. The csv file has employees Name,emp id and status information.
I have a trigger on employees__c object which creates another object called log__c which is child of employee__c. This log__c just records the status of employee( Active or Inactive) and has field called incident which gets a value as "new employee" if employee has status Active OR "removed employee" if employee has status Inactive. This logic is written in trigger.
trigger Atrigger on employee__C( after insert, before update){
if(Trigger.isInsert){
// create log record with incident field value as new employee
}
if(Trigger.Isupdate){
// create log record and check if the status in inactive/active and create the //log accordingly
}
}
The challenge part: requirement -> The employees who are in Salesforce but not in the csv files that is uploaded using dataloader , should be made as "Inactive" in Salesforce and thereby there corresponding log with incident field value as employee removed should be created.
My thoughts: I can query all the existing employees in Salesforce in Isupdate trigger block and see if the existing employees is in trigger.new or not , if not then make them inactive else keep them active. But this can also make the employees as inactive who were just added in IsInsert trigger.
PS : Users can also manually change the employee record to active or inactive so that should also be covered in the trigger.
Any Solution or idea ?
Thanks