0

I have a custom object called Employee__c. Once I create a new User in Salesforce, a new and corresponding Employee__c record has to be automatically created in the system using the information from the User record.

How can I create a new Employe__c record out of a new User record?

2

2 Answers 2

1

This is pretty straight forward, but what the others said.. Process builder or trigger. I did this in the after context so you can link your Employee__c.User to it..

trigger User on User (after insert)
{
    List<User> userList = new List<User>();

    for(User u : Trigger.new)
    {
        userList.add(u);
    }

    List<Employee__c> employeeList = new List<Employee__c>();

    for(User user : userList)
    {
        Employee__c emp = new Employee__c();
        emp.User__c = user.ID;
        employeeList.add(emp);
    }

    insert employeeList;
}
-1

You can use Process builder or a trigger to create the Employee records.

1
  • How is your answer different than Derek's?
    – Raul
    Commented Jul 10, 2017 at 16:00

You must log in to answer this question.

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