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
Muralidhar SingriMuralidhar Singri 

Before Insert Trigger error

I am using the following code for before insert trigger for a custom object Position__c. 

When I try to save get an error. Error message is as follows:
Line 4: Invalid field working_on__c for sObject Position__c.

******** Trigger code on developer **********
trigger Trg1 on Position__c (before insert) {
    for(Position__c t : Trigger.new){
        if(t.working_on__c==t.Hiring_Manager__c){
            t.working_on__c.adderror ('Data in name and Working fields should be different');
        }
    }
}
***********

Please let me know what is wrong.

Thanks,
MS
 
Best Answer chosen by Muralidhar Singri
VinojVinoj
Hi Muralidhar,

I believe that error is only given if the associated object has no field named 'working_on__c'.  Did you double check the API name for that field? You should be able to check by going to Setup | Create | Objects.  Click on the Position object and look at the Custom Fields & Relationships related list to see if you got the full API name.