Skip to main content
How to auto -populate user look up field on the case object? using the Web Email field on case object

I have a web email or SuppliedEmail standard fiel which holds the email address of the user 

Using this field I want to auto populate the respective user lookup

 
4 respuestas
  1. 12 feb 2016, 18:05

    trigger CaseTrigger on Case(before insert, before update){

    List<String> emails = new List<String>();

    Map<String, Id> userEmailToIDMap = new Map<String, Id>();

    for(Case c: trigger.new){

    emails.add(c. SuppliedEmail);

    }

    List<USer> users = [SELECT Id, Email from user where Email IN :emails];

    for(User u : users){

    userEmailToIDMap.put(u.Email, u.Id();

    }

    for(Case c:trigger.new){

    if(userEmailToIDMap.get(c.SuppliedEmail) != null){

    c.Owner = userEmailToIDMap.get(c.SuppliedEmail);

    {

    }

    }

0/9000