+ Start a Discussion
akkkakkk 

How to change the ownerid after insert the Custome Object with Trigger ?

Hi All,
 
How to change the Custome object owner id  after insert the Record. with Trigger ?
Note-> there is no any relationship with the custome object to user but only Email id same in both place.

Thanks
akkk
ANUTEJANUTEJ (Salesforce Developers) 
Hi Ak,

Can you check if the below snippet helps?
 
trigger c_trigger on custom_object__c(before insert)
{
set<string> eset= new set<String>();
map<String, User> muser= new map<String,User>();

for(Custom_object__c c: trigger.new)
{
eset.add(c.EmailId);
map.put(c.EmailId, new User());
}

list<User> UserList=[SELECT Field_Names FROM User WHERE Id in :eset] ;

for(User u: UserList)
{
User urec= muser.get(u.EmailId);
muser.put(u.EmailId,u);
}

for(Custom_object__c c: trigger.new)
{
User TempUser= muser.get(c.EmailId);
//assign values to the fields
}
}

Else if this is not the usecase can you elaborate so as to check if there are any examples for the same?

Thanks.
ANUTEJANUTEJ (Salesforce Developers) 
Please do note above is a sample snippet code and it needs to be changed as per your scenario.