Leverage Cloud-Computing, Saas, and Better Business Processes to Drive Change in Your Industry

Clint Lee

Subscribe to Clint Lee: eMailAlertsEmail Alerts
Get Clint Lee: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn

Related Topics: Cloud Computing, Salesforce.com Journal

Cloud Computing: Blog Post

Salesforce Summer '11 Master-Detail Quirk

Here's a solution

The good news about working on the Salesforce platform is that three times a year, while you're lying asleep at night, the little Salesforce elves are hard at work rolling out the newest release. The bad news is that sometimes on a Monday morning you start seeing Apex errors in your inbox. This past release of the Summer '11 upgrade was one of those times for me. I thought I'd share the details to prevent anyone else from banging their noggin' against the wall. Spoiler Alert! The story ends happily with a working solution.

Salesforce Summer 11 Logo

The Background
We had a portion of Apex code that, when executed, created a custom object that was the detail side of a master-detail relationship. Nothing special going on here, just straightforwardness.

The Problem
On the Monday morning after the org was upgraded to Summer '11, errors started to kick off whenever this particular piece of code was executed. The error given was "Field Not Writable" and it referred to the lookup field that looked up to the Master object. For all the visual learners out there (like me!) see the diagram below.

Master-Detail Visual

Whenever an Object B was attempting to be inserted we would get an error on Field 1 saying "Field Not Writable". Very strange since two days earlier this was working splendidly and nothing had changed since. After quite some time of trying to track down the root problem we submitted a Case to Salesforce assuming this was some bug related to the upgrade. As it usually goes, shortly after submitting the case we developed a solution that worked. Here it is...

The Solution
This is actually so simple it hurts. The object was being created like this.

[java] Object_B__c objB = new Object_B__c(); objB.field1__c = objectAId; insert objB; [/java]

The solution was simply to instantiate the Master object field in the constructor. Like so...

[java] Object_B__c objB = new Object_B__c(field1__c = objectAId); insert objB; [/java]

A very subtle quirk in the new release but nonetheless one that can cost you hours of time trying to understand and resolve. Salesforce support did respond and let me know that they were unaware this change had happened. The case was forwarded on for analysis. No word yet on whether this was intended or unintended but for now all is good.

I hope this helps and as always I look forward to any comments or feedback.

More Stories By Clint Lee

Clint is a Principal and Founder of The Flywheel Group, a premier provider of innovative solutions to the franchise industry. The FranchiseFlywheel™ application was developed out of the industry's need for a cutting-edge and affordable franchise management tool for franchisors. Spending several years in the franchise industry directing daily activities related to franchise and business development processes, marketing, lead-generation, and contract administration, and an understanding of the needs of peers and colleagues, led to the development of the application. The Flywheel Group is focused on improving best practices and driving change in the franchise industry by introducing industry-leading solutions and working with its clients to re-engineer business processes that will ultimately enhance revenue and improve bottom line efficiency. Clint actively writes and shares his thoughts on the Flywheel Blog.