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
Scott2014Scott2014 

Update Lookup Field with Contents of Text Field

I am trying to create a trigger on the Account record in which the NAICS Code (field name: "NaicsCode" from Data.com) updates our custom object NAICS (field name: "NAICS_Code__c") anytime the custom object field is blank. 

Can anyone advise me on what I am doing wrong? This is what I have currently but it doesn't seem to be working. 

trigger NAICS on Account (before insert,before update) {
     for(NAICS_Code_C naics:trigger.new){
        if(Naics!=null){
            Account.NAICS_Code__c=Naics;
    
        }
    }
}
logontokartiklogontokartik
Hi Scott,

The lookup field on an object is not an actual field, but a relationship to a different object. From what I see is you are trying to add a lookup relation on Account if the relation is not already present. 

Your case looks like there are 2 objects Account & NAICS and are related via Custom Field on Account NAICS_Code__c (which is a lookup field).
The field that is being populated from data.com is NaicsCode on Account?

Can you please confirm if my understanding is right?

Also to understand more on Lookup relationships. Please refer to 

http://www.salesforce.com/us/developer/docs/api/Content/relationships_among_objects.htm






Scott2014Scott2014
You are correct.  Is this possible?