+ Start a Discussion
YuckleYuckle 

Display Orginal Case Owner Name

I would iike to display the name of the original case owner on the case page after a case is reassigned.  I have created a field Level 1 Owner Id where I capture the original owner id upon reassignment.  But, I have been unable to figure out how to the display the name of the original owner from the id value stored in  Level 1 Owner Id.  There must be a way..  Please help.

Best Answer chosen by Admin (Salesforce Developers) 
skodisanaskodisana

Hi,

 

Lookup fields we can not update dynamically using Workflow field update.

May be you might need to write a small trigger on Case object looks like below.

 

trigger OldOwnerNameUpdate on Case(before update){

 

     for(Case c : Trigger.New){

              if(Trigger.OldMap.get(c.Id).OwnerId != c.OwnerId)

                        c.Level_1_Owner_Id = a.OwnerId;

     }

}

 

Thanks,

Kodisana

 

All Answers

skodisanaskodisana

Hi,

 

Create a Level 1 Owner Id as Lookup to User object and then populate the OwnerId to this field.

Then User Name will show automatically.

 

Thanks,

Kodisana

 

YuckleYuckle

Okay.  How do I populate this field once created as a lookup field to user  to User, with a Field Update?

skodisanaskodisana

Hi,

 

Lookup fields we can not update dynamically using Workflow field update.

May be you might need to write a small trigger on Case object looks like below.

 

trigger OldOwnerNameUpdate on Case(before update){

 

     for(Case c : Trigger.New){

              if(Trigger.OldMap.get(c.Id).OwnerId != c.OwnerId)

                        c.Level_1_Owner_Id = a.OwnerId;

     }

}

 

Thanks,

Kodisana

 

This was selected as the best answer
YuckleYuckle

Thanks.  I'll get it a try

myanceymyancey

It works!  Here's the final version:

 

trigger CaptureLevel1Owner on Case (before update) {
           
      for(Case c: Trigger.new) {
        String caseLevel2 = 'Level 2';
        if (Trigger.isUpdate) {
          if (c.Level__c == caseLevel2) {        
                   if (c.Level_1_Owner__c == null)
              c.Level_1_Owner__c = c.Level_1_Case_Owner_Id__c;
           }
         }
      }
 }

myanceymyancey

I built this is the Sandbox.  How do I get it into production?

skodisanaskodisana

Hi,

 

To migrate the code to the Production you have to write test class for code coverage.

after that you need to use Force.com Migration tool OR Ant tool to migrate the code to the Production.

Below is the sample code for test class:

 

Public class TestClass_onCase
{
    @istest private Static void Test_method(){
Contact con = new Contact(LastName='Test Contact'); // populate all the required fields
insert con;
Case c = new Case(ContactId=con.Id,Status='Open');// populate the required fields
insert c;
}
}

 

Thanks,

Kodisana