[SalesForce] Required Field on VisualForce Triggers “SObject row does not allow errors” message

I must be missing something here..I have a visualforce page, that enables a user to create a Campaign – I have a pageblock/section with the Campaign Fields, including name, and Name is marked required. I click a button, and if the name field for Campaign is blank, I get this error:

System.FinalException: SObject row does not allow errors

In the logs, the line before my error is a VF Page Message "You Must Enter a Value", but instead of throwing the error back to the user, the next line is:

EXCEPTION_THROWN [EXTERNAL]|System.FinalException: SObject row does
not allow errors

And the thing is, if I remove all code in the pagereference call in the controller, and just return null, it still gives the error, but as far as I can tell, I am not writing anything to the database?

Update – apparently, it is this line causing my issue:

newCampaign = (Campaign)Campaign.sObjectType.newSObject(null, true);

if I use the standard way:

newCampaign = new Campaign();

the page works just fine.

Is that expected behavior?

Best Answer

As mentioned in my comment, it's a bug. I got a response from Salesforce today confirming it.

Here is the bug in the known issues tracker:
https://success.salesforce.com/issues_view?id=a1p30000000Sz5RAAS

As you have deduced it is caused when an object is instantiated using the SObjectType.newSObject method, but only when the useDefaults flag is true. Which without it defeats the purpose of instantiating the Campaign record in that way.

Related Topic