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
Richard101Richard101 

SObject row does not allow errors - master-detail relationship lookup field

Hello

We have a custom object (QuoteOrder__c) which is the child in a master-detail relationship with Opportunity.

On my visualforce page my intention is to have it display the Contacts on the Opportunity (via OpportunityContactRole) once you have selected an opportunity from the lookup dialog. I've tried this and it works fine until you change the text in the opportunity field and click or tab out of the field (and therefore clear the underlying Opportunity Id) at which point the page reloads and just gives me the error "SObject row does not allow errors".


For simplicity, I've reduced my page down to just this:
<apex:page controller="QuoteOrder">
    <apex:form >
        <apex:pageBlock>
            <apex:pageBlockSection columns="1"> 
                <apex:inputField value="{!quoteOrder.OpportunityLink__c}" id="opportunity" label="Opportunity">
                    <apex:actionSupport event="onchange" rerender="details" />
                </apex:inputField>
            </apex:pageBlockSection>
            
            <apex:pageBlockSection columns="1" id="details">
                <!-- Other stuff will go here when an opportunity is selected -->
                <apex:messages></apex:messages>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

And I've reduced my controller down to just this:
public with sharing class QuoteOrder {
    public QuoteOrder__c quoteOrder { get; set; }

    public QuoteOrder() {
        this.quoteOrder = (QuoteOrder__c)QuoteOrder__c.SObjectType.newSObject(null, true);
    }
}

I assume it's upset because in the master-detail relationship the opportunity is a compulsory field and the page is submitting with no value. To this end, I have used jquery to check the value of the underlying Id when the blur event is activated, and then if the Id is undefined I have used event.preventDefault() but the page still submits and presents me with the error message. Can anybody suggest how I can stop it submitting in this situation please?

Thank you
Richard
Best Answer chosen by Richard101
Nayana KNayana K
<apex:actionSupport event="onchange" rerender="details" immediate="true"/>

Not sure if this helps or not. Please try this once.

All Answers

Nayana KNayana K
<apex:actionSupport event="onchange" rerender="details" immediate="true"/>

Not sure if this helps or not. Please try this once.
This was selected as the best answer
Richard101Richard101
That's exactly what I needed!

Thanks very much
Richard

 
Nayana KNayana K
Please mark the answer as best.