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
shrey.tyagi88@tcs.comshrey.tyagi88@tcs.com 

Get Owner Name form Note Standard object --Please Help!!!!

Hi All,

        I have written a trigger on Standard Note object . Now this object has Owner Id field. Upon insert i want a map say

Map<id,string> OwnerMap , to get populated with Owner Id and Owner full name (First +Last). Can anyone please help me with this.

 

trigger abd on Note( after insert, after update){

List<id> OnwerIdList=new List<id>();

 for (Note ntvar : Trigger,.New){

 OnwerIdList.add(ntvar.ownerId);
 }

List <String> ownerFirstname=[Select FirstName from user where id in:OnwerIdList ];

List <String> ownerLastname=[Select LastName from user where id in:OnwerIdList ];

}

Best Answer chosen by Admin (Salesforce Developers) 
Shweta_AgarwalShweta_Agarwal

trigger abd on Note( after insert, after update){

List<id> OnwerIdList=new List<id>();

Map<id,string> OwnerMap = new Map<id,string>();

 for (Note ntvar : Trigger,.New){

 OnwerIdList.add(ntvar.ownerId);
 }

List <User> ownername=[Select FirstName, lastName, Id from user where id in:OnwerIdList ];
for (Note ntvar : Trigger.New){
for(User u : ownername){
if(ntvar.ownerId == u.id){
OwnerMap.put(ntvar.ownerId,u.FirstName + ' ' + u.LastName) ;
}
}
}

}