Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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?

share|improve this question
    
Is it worth setting immediate=true on the button click if its only doing a partial page refresh? –  techtrekker Dec 20 '12 at 20:51
    
No - I want the page level validation to fire - if there is no Campaign Name, I want to stop the submit - but for some reason, it doesn't stop - it takes me to this error instead? –  BritishBoyinDC Dec 20 '12 at 22:39
    
I don't see anything in the sObjectType.newSObject documentation that would lead me to believe it should behave differently. Do you get the error when you explicitly set the default values in the new Campaign() constructor? In other words, make it so that newCampaign has all of the same field values as it would have had from the newSObject call (might need to set RecordTypeId, too). –  Peter Knolle Dec 21 '12 at 3:21
    
Thanks = it's been driving me mad all day trying to work this out...I'm in dev environment with no Campaign Record Types...so that shouldn't be an issue. I see what you are saying - but if I use the sObject method, and set a name it works just fine - so doesn't seem to be a default value issue - it just doesn't seem to apply the correct validations for a Campaign object before it tries to save, and then falls over because there isn't a name (which is required at the db level) –  BritishBoyinDC Dec 21 '12 at 3:48
    
Seems like a bug to me, have you filed a case with support? –  Ralph Jan 31 '13 at 4:45
show 3 more comments

3 Answers

From reading the details of the feature, and your statement about not performing DML, I'd say this is a possibly a bug. The newSobject method should just instantiate a new Campaign with the default values and default record type given the way you called the method.

Can you post more of the method you're calling when they create the campaign? You're not trying to use addError directly on the instantiated SObject if they forgot Name are you?

share|improve this answer
add comment

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.

share|improve this answer
add comment

I had the same issue and putting a <apex:pageMessages /> on my VF page helped me figure out the root cause of this error.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.