+ Start a Discussion
S SaiS Sai 

In case object how to display case owner locale

HI,

In case object i created one formula field. in this formula field i want to display case owner locale based on this soql query 
" select id,localesidkey from user where id in(select ownerid from case) "

Thanks 
SAi
Best Answer chosen by S Sai
Pramod GowdaPramod Gowda
Hi sai,
You can achieve this by trigger on Case.
Find the code below to update the case owner locale on case object field.
I hope this will help.
trigger updateOwnerLocale on Case (before insert, before update) {

Set<Id> ownerIds = new Set<Id>();
Map<Id,String> ownerLocale = new Map<Id,String>();

for (Case c : trigger.new) {

    if (c.OwnerId != null)  {

        if (trigger.isInsert || (trigger.isUpdate && c.OwnerId != trigger.oldMap.get(c.id).OwnerId)) {            
            ownerIds.add(c.OwnerId);            
        }
    }
}
system.debug('confunrole***'+ownerIds);
for(List<User> userList : [SELECT Id,localesidkey FROM User WHERE ID IN : ownerIds]){
    for (User u : userList) {
        ownerLocale.put(u.id,u.localesidkey);
    }
}

// Update the contact functional role field on the Task with the relevant value
for (Case e : trigger.new) {
    e.Owner_Locale__c = ownerLocale.get(e.ownerId);
}
}

Thanks
Pramod 

All Answers

sandeep@Salesforcesandeep@Salesforce
Hi S Sai, 

We can not create such formula field directly because in formula field while looking up case owner(user) there is no such field locale ( api : LocaleSidKey) would not be visible. 

But using some code you can fulfill this requirement. 

Thanks
Sandeep Singhal
http://www.codespokes.com/
S SaiS Sai
Hi Sandeep,

Coild you plz explain the code 

Thanks 
Sai
Pramod GowdaPramod Gowda
Hi sai,
You can achieve this by trigger on Case.
Find the code below to update the case owner locale on case object field.
I hope this will help.
trigger updateOwnerLocale on Case (before insert, before update) {

Set<Id> ownerIds = new Set<Id>();
Map<Id,String> ownerLocale = new Map<Id,String>();

for (Case c : trigger.new) {

    if (c.OwnerId != null)  {

        if (trigger.isInsert || (trigger.isUpdate && c.OwnerId != trigger.oldMap.get(c.id).OwnerId)) {            
            ownerIds.add(c.OwnerId);            
        }
    }
}
system.debug('confunrole***'+ownerIds);
for(List<User> userList : [SELECT Id,localesidkey FROM User WHERE ID IN : ownerIds]){
    for (User u : userList) {
        ownerLocale.put(u.id,u.localesidkey);
    }
}

// Update the contact functional role field on the Task with the relevant value
for (Case e : trigger.new) {
    e.Owner_Locale__c = ownerLocale.get(e.ownerId);
}
}

Thanks
Pramod 
This was selected as the best answer