0

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

4
  • have you looked at enabling field history tracking for the logging? if so it would save you having to write a trigger for this Commented Aug 10, 2016 at 17:15
  • Yes I have explored that option. But for my requirement I need flexibility to record the logs so I choose do it this way. I need to create log every time something changes which is not related to employee too.
    – SfdcBat
    Commented Aug 10, 2016 at 17:17
  • 'tis not really Community Etiquette to call in assistance from a specific user
    – cropredy
    Commented Aug 11, 2016 at 0:29
  • Sorry! I will delete that!
    – SfdcBat
    Commented Aug 11, 2016 at 0:47

1 Answer 1

2

When we want to distinguish record creation between data loader and User Interface we generally prefer to create a new boolean field on an object and set that field value as true while inserting data using dataloader and make that field as false from user interface.

trigger Atrigger on employee__C( after insert, before update){

if(Trigger.isInsert){
// create log record with incident field value as new employee

    if(employee__c.isBulkUpload){
         //set incident as inactive.
    }

}

if(Trigger.Isupdate){

// create log record and check if the status in inactive/active and create the //log accordingly
// check for

}

}
7
  • Thanks. How do I auto update isBulkUpload when I am editing a record with user interface?
    – SfdcBat
    Commented Aug 10, 2016 at 18:15
  • What do you mean by auto update?
    – Himanshu
    Commented Aug 10, 2016 at 18:18
  • How do I set the boolean field - isBulkUpload as true or false based on datalaoder or field update?
    – SfdcBat
    Commented Aug 11, 2016 at 0:48
  • Create new field amd make default value as false but while uploading add this field in csv and set value=true
    – Himanshu
    Commented Aug 11, 2016 at 3:50
  • Thanks, is there a way I can make the existing employees in Salesforce who are not in csv as inactive ? There is status field on employee object which can have value active or inactive
    – SfdcBat
    Commented Aug 11, 2016 at 4:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .