1

I want to create records from individual inputs in a table. Individual inputs are made of Users or Contacts participating to a given meeting. A Meeting__c object is the parent of User and Contacts stored in a Participant__c object. Users and Contacts are distinguished by Record Types: Internal -> Users ; External -> Contacts. Users are stored in a Lookup field User__c ; Contacts are stored in a Lookup field Contact__c. Ths user has the possibility to select the type of participant in a list box (linked to the RecordTypeID field).

Goal: render User__c or Contact__c depending on the value of the RecordTypeID selected by the user.

For that, I use an <apex:actionSupport> tag to trigger a controller method that handles the Record Type change and sets the Render variable.

Problem: I could write a page that works like expected. But as soon as I have a field required on the page, the actionSupport call fails. The Debug log shows "You must enter a value".

Diagnostic: in any case, the call goes into the checking of required fields being filled or not before doing anything else.

What I've done:

  1. Enter a value in the required field: no error is raised in this case. But I can't require users to input all the required field PRIOR to entering any value in the participants list (5 fields in the final form)
  2. Use immediate="true" in actionSupport
  3. Use actionFunction instead of actionSupport
  4. Surrounding the <apex:pageBlockTable> tag with <apex:actionRegion>tags

2 caused a different problem. 3 and 4 couldn't resolve the issue.

My question is: is there a way to call directly the controller method without triggering the required checking ?

Thank you for you help

Visualforce page:

<apex:form >
    <apex:pageBlock >

        <apex:inputField value="{!Visit.Visit_date__c}" required="false" />
        <apex:pageBlockTable value="{!Participants}" var="u" title="Participants list" id="ParticipantsList">

            <apex:column headerValue="Participant Type" >
                <apex:inputField value="{!u.participant.RecordTypeId}"  >
                    <apex:actionSupport event="onchange" action="{!onRecordTypeChange}" reRender="ParticipantsList" >
                        <apex:param name="LineIndex" value="{!u.index}" assignTo="{!CurrentRow}" />
                    </apex:actionSupport>
                </apex:inputField>
            </apex:column>       

            <apex:column headerValue="Participant" >
                <apex:inputField value="{!u.participant.User__c}" rendered="{!u.isInternal}" />
                <apex:inputField value="{!u.participant.Contact__c}" rendered="{!NOT(u.isInternal)}" />
            </apex:column>

            <apex:column headerValue="Index" >
                <apex:outputText value="{!u.index}" />
            </apex:column>                

            <apex:column headerValue="isInternal" >
                <apex:outputText value="{!u.isInternal}" />
            </apex:column>

        </apex:pageBlockTable>

    </apex:pageBlock>
</apex:form>

0

According to my understanding of your question, you want to call controller method on selection of RecordType, without entering other mandatory fields.

This can only be solved using <apex:actionSupport> inside <apex:actionRegion>.

For example

<apex:column headerValue="Participant Type">
    <apex:actionRegion>
        <apex:inputField value="{!u.participant.RecordTypeId}"  >
            <apex:actionSupport event="onchange" action="{!onRecordTypeChange}" reRender="ParticipantsList" >
                <apex:param name="LineIndex" value="{!u.index}" assignTo="{!CurrentRow}" />
            </apex:actionSupport>
        </apex:inputField>
    </apex:actionRegion>
</apex:column>

Also, if you are making fields as mandatory based on recordtype selection, for example User__c, then wrap that field within <apex:actionRegion>. Otherwise use of required="true" always fire before submitting the page.

For example

<apex:column headerValue="Participant" >
    <apex:actionRegion>
        <apex:inputField value="{!u.participant.User__c}" rendered="{!u.isInternal}" required="true"/>
        <apex:inputField value="{!u.participant.Contact__c}" rendered="{!NOT(u.isInternal)}" required="true"/>
    </apex:actionRegion>
</apex:column>
|improve this answer|||||
  • Hi Santanu, Thank you very much for your advise. It works fine. Have a nice day FB PS: anyway, it looks like that what I want to do is not possible in APEX/Visualforce. I have to find some other way of doing that. Thanks again – fredbe Feb 23 '18 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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