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
Swaroopa Akula 1Swaroopa Akula 1 

Using partner email id how can we update the partner user username field in the saleforce?

i have a commision cusotm object . i have two fields partner email id field and partner user look up field. i will enter the email id field and partner user username field should get updated automatically. how could i do that?
Raj VakatiRaj Vakati
You can able to do it using the trigger 
Refer this code
 
trigger commisionUse on commision__c (before Insert)
{

Set<String> emails = new Set<String>(); 
for(commision__c c: Trigger.new){
emails.add(c.partner_email__c)
}

List<User> users = [Select Id , Email from User where Email IN  : emails];

Map<String, Id> mapsEmail = new Map<String, Id> () ;
for(User u : users){
mapsEmail.put(u.email ,u.Id) ;
}

for(commision__c c: Trigger.new){
if(mapsEmail.get(c.partner_email__c)!=null){
c.partner_user__c = mapsEmail.get(c.partner_email__c)
}

}


}