function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Pooja NekkalapudiPooja Nekkalapudi 

How to auto -populate user look up field on the case object?

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
 
Best Answer chosen by Pooja Nekkalapudi
R Z KhanR Z Khan
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);
{
}

}

All Answers

R Z KhanR Z Khan
You can write a trigger that will query for the suers who have that email address adn then auto populate it in the case before it gets inserted
Pooja NekkalapudiPooja Nekkalapudi
Do you have any sample code since im new to coding 
R Z KhanR Z Khan
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);
{
}

}
This was selected as the best answer
Pooja NekkalapudiPooja Nekkalapudi
Thanks a lot this worked :)