+ Start a Discussion
rornelasrornelas 

Populate lookup value into text field

Hi Everyone,

I have a a lookup field that gets populated with the territory name by a Managed package. I want to take the value of this lookup and populate an existing text field.  This is what I have so far. Any help would be greatly appreciated!
 
trigger UpdateExistTerritory on Service_Order__c (before insert, before update) {
    List<Service_order__c> ServiceTerr = new List<Service_order__c>();
    for(Service_order__c servOrder : trigger.new){
        if(servOrder.ManagePckgTerritory__r.Name  != null){
            servOrder.ManagePckgTerritory__r  = servOrder.ExistingText_field__C;
            ServiceTerr.add(servOrder);
        }
    }
    update ServiceTerr;
   
}

 
SalesFORCE_enFORCErSalesFORCE_enFORCEr
It should be the other way around. Why don't you use a formula field to get the value from the lookup field?
trigger UpdateExistTerritory on Service_Order__c (before insert, before update) {
    List<Service_order__c> ServiceTerr = new List<Service_order__c>();
    for(Service_order__c servOrder : trigger.new){
        if(servOrder.ManagePckgTerritory__r.Name  != null){
            servOrder.ExistingText_field__C = servOrder.ManagePckgTerritory__r.Name;
            ServiceTerr.add(servOrder);
        }
    }
    update ServiceTerr;
   
}
rornelasrornelas
The thing is that the customer has a territory field that they've been using for a while and a lot of their reports are dependent on this field. They don't want another territory field they just update the existing one they have. Does this answer your question?

I will try the trigger.