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
chriscwharrischriscwharris 

Read Only fields/data in edit mode

So I have a pretty simple requirement which seems once again impossible in Salesforce. I have a parent and child, when I create the child I want to display a few values from the parent at the top of the form to assist the entry of data in the child, nothing out of the oridnary you would think. Problem is it seems output only fields or emdedded VF pages etc.. disappear when in edit mode!

Any way around this? I want to display a stock level type field on the child so users don't waste time ordering more stock than is available and I don't want them to have to wait until they try to save.

Thanks
Ashish DevAshish Dev
There are 2 options.
1) Relatively easy: you need to override edit layout with vf page. For flexibility of setting fields for edition you can use field sets.
2) Complex: Use sidebard component javascript trick. On the fly include vf page containing info of parent obj in iframe.
chriscwharrischriscwharris
Thanks for the reply. I had already tried to override with a VF but no luck. I tried using a standard tag such as

Stock: {!Parent__c.Stock__c }

Which displayed in READ mode but not in edit. I also tried an output field such as

<apex:outputField value="{!Child__c.Parent__r.Stock__c}"/>
 
Which again displayed in READ but not edit.

So are you saying Fieldsets allow you to show data in READ mode from a parent object?

Thanks          
Ashish DevAshish Dev
You can use tags like apex:inputText or apex:inputField appropriatly to display input fields for different field types. 
Let me know if issue still exist.
chriscwharrischriscwharris
Thanks Ashish, I'm not sure you have grasped my issue. I have no problem with editable fields. What I can not display is READ ONLY values from a parent document, either when creating or editing a child document. If I open an already created child in READ mode then I can see the parent fields, when I edit the record they vanish. As you can see above, I have used outputField and also referenced the field direct hoping it would simply show static text but it always vanishes when in EDIT mode.

 
Ashish DevAshish Dev
Chris,
Let me reiterate your issue. There are Read Only fields (profile level access on those fields are Read-Only) and you want to display(using input fields) them in edit layout of the child object.
Well, this has to be done using wrapper class of the extension controller of your VF page.
Below is the code:
Note: dev101__SLASerialNumber__c field is read only for all profiles.

VF Page:
<apex:page standardController="Contact" extensions="ContOverrideCntrl" >
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlockSection>
                <apex:inputText value="{!aw.accName}"/>
                <apex:inputText value="{!aw.accAnnualRevenue}"/>
                <apex:inputText value="{!aw.accSrlNum}"/>

            </apex:pageBlockSection>
        </apex:pageBlock>
        <apex:pageBlock>
            <apex:pageBlockSection>
                <apex:inputText value="{!contact.name}"/>
                <apex:inputField value="{!contact.AccountId}"> </apex:inputField>
                
                <apex:inputField value="{!contact.LeadSource}"> </apex:inputField>
                <apex:inputField value="{!contact.Birthdate}"> </apex:inputField>
                <apex:inputField value="{!contact.Description}"> </apex:inputField>
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
                <apex:commandButton action="{!cancel}" value="Cancel"/>
                
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Extension Controller:
public class ContOverrideCntrl {
    public AccWrapper aw {get;set;}
    public Id cId = apexPages.currentPage().getParameters().get('id');
    
    public ContOverrideCntrl(ApexPages.StandardController cntrl){
        Contact con = [SELECT Id, Name, Account.Name, Account.AnnualRevenue, Account.dev101__SLASerialNumber__c FROM Contact WHERE Id = :cId];        
        
        aw = new AccWrapper();
        aw.accName = con.Account.Name;
        aw.accAnnualRevenue = string.valueOf(con.Account.AnnualRevenue) ;
        aw.accSrlNum = con.Account.dev101__SLASerialNumber__c;
    }
    public class AccWrapper{
        public String accName {get;set;}
        public string accAnnualRevenue {get;set;}
        public string accSrlNum {get;set;}
    }
}

Let me know if this helps you in solving your issue.
chriscwharrischriscwharris
Hi Ashish,

Thanks again, as I suspected you've not understood my requirement. I do not want read only fields shown in input fields. I have a parent object that has various items of data on it. When creating a child document I want to have a number of items of data from the parent visibile to facilitate the completion of the child fields.

Think of a page with an area at the top that is read only showing data from the parent and a section below that is the editable fields for the child. At the moment I can not find a way to display data from the parent on the child whilst creating/editing the child. I can add formula fields that show when "reading" an existing child record but that doesn't help.

Thanks​​
Ashish DevAshish Dev
Chris 
You can achieve this through code provided by me.

VF is overriding contact's default new and edit screen. It contains desired input fields from contact. and fields from account objects.
Just try it.

Let me know if this does not help you.