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
Lightning UserLightning User 

can't get field from related record for custom object new override

Hi,

   I'm trying to get a field from a parent record named SSOEnabled. if it's true I want to show the password field to be edited. The parent record does have the field SSOEnabled as true. The problem is it's not showing it when I try it out? But if i do a test on a field from the current record it'll work.  Anyone know why? Thanks. :smileyhappy:

 

<apex:page standardController="EAST_SSOCredential__c" title="SSO Credential Edit: New SSO Credential">
<apex:sectionHeader title="SSO Credential Edit" subtitle="New SSO Credential"/>
<apex:form >
<apex:pageBlock title="SSO Credential Edit" id="thePageBlock" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:actionRegion >
<apex:pageBlockSection title="Information" columns="1">
<apex:inputField value="{!EAST_SSOCredential__c.Name}" required="true"/>
<apex:inputField value="{!EAST_SSOCredential__c.Website__c}">
<apex:actionSupport event="onchange" rerender="thePageBlock"/>
</apex:inputField>
<apex:inputField value="{!EAST_SSOCredential__c.Contact__c}"/>
<apex:inputField value="{!EAST_SSOCredential__c.UserID__c}"/>
<apex:inputField value="{!EAST_SSOCredential__c.Password__c}"
rendered="{!EAST_SSOCredential__c.website__r.SSOEnabled__c}"/>
</apex:pageBlockSection>
</apex:actionRegion>

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

</apex:page>
<apex:page standardController="EAST_SSOCredential__c" title="SSO Credential Edit: New SSO Credential">
<apex:sectionHeader title="SSO Credential Edit" subtitle="New SSO Credential"/>
<apex:form >
<apex:pageBlock title="SSO Credential Edit" id="thePageBlock" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:actionRegion >
<apex:pageBlockSection title="Information" columns="1">
<apex:inputField value="{!EAST_SSOCredential__c.Name}" required="true"/>
<apex:inputField value="{!EAST_SSOCredential__c.Website__c}">
<apex:actionSupport event="onchange" rerender="thePageBlock"/>
</apex:inputField>
<apex:inputField value="{!EAST_SSOCredential__c.Contact__c}"/>
<apex:inputField value="{!EAST_SSOCredential__c.UserID__c}"/>
<apex:inputField value="{!EAST_SSOCredential__c.Password__c}"
rendered="{!EAST_SSOCredential__c.website__r.SSOEnabled__c}"/>
</apex:pageBlockSection>
</apex:actionRegion>

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

</apex:page>
blombardisblombardis
{!EAST_SSOCredential__c.website__r.SSOEnabled__c}

 Is returning a List, so If you want to get that value on VF you may need to use apex:repeat to get that value.

 

 

<apex:repeat var="case" value="{!EAST_SSOCredential__c.website__r}">
     <apex:param name="q" value="{!case.SSOEnabled__c}"/>
</apex:repeat>  

Hope this works,

Bruno

 

 

 

Lightning UserLightning User

SSOEnabled__c is a boolean (checkbox) on the parent object Website. Sorry I should have been a little more clear on that.

ahab1372ahab1372

fields are not queried by thestandard controller if they are not included in the visualforce page. Referencing in the rendered attribute alone doesn't count, I belive. Include the field as an outputField and see if it works.

sforce2009sforce2009

Agrred with ahab. Use extensions class I have explained on this post. Check how to prepoulate inputfields

 

http://community.salesforce.com/t5/Visualforce-Development/How-to-re-create-the-Task-page-in-VF-with-whoid-and-whatid/m-p/179676#M23369

 

You may need small tweaks in constructor. Query the required fields and assign them.

 

Cheers

Lightning UserLightning User

Well, I think I'm doing what the last person is saying, but I keep getting this error when I try to create a new SSOCredential:

 

List has no rows for assignment to SObject

 

The problem is I want to do this when I'm overriding the new button so I think it's because theres no existing record to go on. I'm just not sure if it's possible to fulfill the goal of getting a field from a parent record that already exists even though the current record hasn't been created yet:

 

 

Here is the class:

public with sharing class relatedSSOCredHandler {
    EAST_SSOCredential__c ssoCred = new EAST_SSOCredential__c();
    private boolean isSSO;
    public relatedSSOCredHandler(ApexPages.StandardController controller) {
        this.ssoCred = (EAST_SSOCredential__c)controller.getRecord();
        String id = ApexPages.currentPage().getParameters().get('Website__c');
        isSSO = [select SSOEnabled__c from EAST_Website__c where id = :id].SSOEnabled__c;
    }
    public boolean getIsSSO() {    
        return isSSO;               
    }
}

 

 

 

Here is the page:

 

<apex:page standardController="EAST_SSOCredential__c" title="SSO Credential Edit: New SSO Credential" extensions="relatedSSOCredHandler">
<apex:sectionHeader title="SSO Credential Edit" subtitle="New SSO Credential"/>
<apex:form >
<apex:pageBlock title="SSO Credential Edit" id="thePageBlock" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:actionRegion >
<apex:pageBlockSection title="Information" columns="1">
<apex:inputField value="{!EAST_SSOCredential__c.Name}" required="true"/>
<apex:inputField value="{!EAST_SSOCredential__c.Website__c}">
<apex:actionSupport event="onchange" rerender="thePageBlock"/>
</apex:inputField>
<apex:inputField value="{!EAST_SSOCredential__c.Contact__c}"/>
<apex:inputField value="{!EAST_SSOCredential__c.UserID__c}"/>
<apex:inputField value="{!EAST_SSOCredential__c.Password__c}"
rendered="{!isSSO}"/>
</apex:pageBlockSection>
</apex:actionRegion>

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

</apex:page>
sforce2009sforce2009

This error comes when there is no corresponding record for that id field you are getting from querystring. Make sure id is coming in, that should solve the problem. Let me know

Lightning UserLightning User

The id of the record won't come in because I'm creating a new record (I'm overriding the new page for the object), so it's impossible. I have to be able to read an existing parent record on a rerender on the child object, but it's just not working!

sforce2009sforce2009

I understand.

1. If you want the parent record id, then this vf page which is on new button has to be launched from the relatedlist.

The Id I mentioned is the Id of the parent record according to this line of code

String id = ApexPages.currentPage().getParameters().get('Website__c')

String id = ApexPages.currentPage().getParameters().get('Yourobjects parentId');//the above line should be this one.

If you get the parent record Id right. your problem will be solved.

2. But note that, if you are launching the page directly from Object's tab, you can not get the parent Id and the solution will not work

Let me know if this helps.

Lightning UserLightning User

I have created a workaround using apex trigger to achieve my goal. You are probably right, there is no way to recognize a different object's fields in visualforce without the current object being established. Thanks anyway.