Tuesday, June 28, 2011

INVALID_FIELD and INVALID_FIELD_FOR_INSERT_UPDATE error in Salesforce.com Professional Edition

Some time back I wrote a post on the INVALID_FIELD error that you may get when calling the Salesforce.com upsert() method. Today I want to elaborate on this issue a little more since Salesforce.com has changed a lot since I last wrote about this issue.

The INVALID_FIELD error or the  INVALID_FIELD_FOR_INSERT_UPDATE error is commonly seen in the Professional Edition of Salesforce.com when using the upsert() method. In professional edition, field security is defined by what fields are included on the page layout. If the fields are not a part of the page layout you cannot use those fields in the upsert() method. If they are not in the page layout, the API (or any apex code for that matter), would not see the field and any reference to it would result in error.

So to overcome this error, all you have to do is add these fields to the custom object's page layout. To do this:

  1. Select Your Name | Setup | Create | Objects.
  2. Choose the object.
  3. Scroll to the Page Layouts section.
  4. Click Edit next to the page layout you want to customize.
  5. Add a new "Section" to the page layout by dragging "section" to the page.
  6. Add fields that are throwing an error into this section.
Now you should be able to call upsert() on these fields without error.  Doing the above will also display these fields in the actual page layout for all users. If you don't want to do this, you can edit the page layouts of individual objects that use this layout to hide these columns.