+ Start a Discussion
Angela SchloederAngela Schloeder 

How to have 2 fields 'read only' on vf page layout????

I need the fields "Meeting Rating" and "Rating Notes" to be Read Only on this page only. I know how to do it with FLS, but not for a vf page.

Also, once the 'Post-Meeting Notes' task has been created and saved, if you you edit it, it shows a different page layout; (Pre-Meeting Notes layout).

<apex:page standardController="Task" extensions="ViewTaskExtension">
    <apex:sectionHeader title="Task" subtitle="{!Task.Subject}" />
    <apex:form >
        <apex:pageMessages ></apex:pageMessages>
        <apex:pageBlock title="Task Edit"  id="thePageBlock" mode="edit">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!edit}" value="Edit"/>
                <apex:commandButton action="{!delete}" value="Delete"/>
            <apex:pageBlockSection title="Task Information" columns="2" collapsible="false">
                <apex:outputField value="{!Task.OwnerId}"/>
                <apex:outputField value="{!Task.Attendee__c}"/>
                <apex:outputField value="{!Task.Subject}"/>
                <apex:outputField value="{!Task.WhatId}"/>
                <apex:outputField value="{!Task.ActivityDate}"/>
                <apex:outputField value="{!Task.WhoId}"/>
                <apex:outputField value="{!Task.Description}"/>
                <apex:outputField value="{!taskHelper.Next_Steps__c}" rendered="{!showPostTaskFields}"/>
                <apex:outputfield value="{!Task.Meeting_Rating__c}" rendered="{!showPostTaskFields}"/>
                <apex:outputfield value="{!Task.Rating_Notes__c}" rendered="{!showPostTaskFields}"/>
                <apex:outputField value="{!Task.Date_Approved__c}" rendered="{!showPreTaskFields}"/>
                <apex:outputField value="{!Task.Approved_by__c}" rendered="{!showPreTaskFields}"/>
            <apex:pageBlockSection title="Additional Information" columns="2" collapsible="false">
                <apex:outputField value="{!Task.Priority}" rendered="{!showPreTaskFields}"/>
                <apex:outputField value="{!Task.Meeting_Notes__c}" rendered="{!showPreTaskFields}"/>
                <apex:outputField value="{!Task.Status}"/>
            <apex:pageBlockSection title="System Information" columns="2" collapsible="false">
                <apex:outputField value="{!Task.CreatedById}"/>
                <apex:outputField value="{!Task.LastModifiedById}"/>
                <apex:outputField value="{!Task.Related_Event__c}"/>

public with sharing class CreatePostMeetingTaskExtension {
    private Event currentEvent;
    public Task postMeetingTask {get;set;}
    public Task_Helper__c taskHelper {get;set;}
    public CreatePostMeetingTaskExtension(ApexPages.StandardController controller) {
        this.currentEvent = (Event)controller.getRecord();
        currentEvent = [Select OwnerId,Attendee__c,WhatId,WhoId,Meeting_Rating__c,Rating_Notes__c from Event where Id =: currentEvent.id];
        taskHelper = new Task_Helper__c();
        postMeetingTask = new Task();
        postMeetingTask.OwnerId = currentEvent.OwnerId;
        postMeetingTask.Attendee__c = currentEvent.Attendee__c;
        postMeetingTask.WhatId = currentEvent.WhatId;
        postMeetingTask.WhoId = currentEvent.WhoId;
        postMeetingTask.Meeting_Rating__c = currentEvent.Meeting_Rating__c;
        postMeetingTask.Rating_Notes__c = currentEvent.Rating_Notes__c;
        postMeetingTask.Subject = 'Post Meeting Notes';
        postMeetingTask.Status = 'Completed';
        postMeetingTask.Related_Event__c = currentEvent.id;
    public PageReference save(){
        insert taskHelper;
        postMeetingTask.Task_Helper__c = taskHelper.id;
        insert postMeetingTask;
        return new PageReference('/'+postMeetingTask.id);
Naval Sharma4Naval Sharma4
Hi Angela,

You can use ReadOnly attribute of apex components. 
<apex:inputText value="{!Account.Name}" html-readonly="true" />
<apex:InputText label="User ID" value="{!formattedId}" disabled="true" />

Angela SchloederAngela Schloeder
Thank you for your reply. I am not a developer by any means and cannot get this to work.
Naval Sharma4Naval Sharma4
Hi Angela,

If you are using apex:outputField  then fields are already readOnly. Can you let us know more about your requirement.
Angela SchloederAngela Schloeder
That's is what I thought, but they are not Read Only. There is a Custom Link on the Event which opens a New Task vf page, see below:User-added image

As you can see all fields are editable. The "Meeting Rating" and "Rating Notes" values pull from the related Event. I cannot have them read only on the Event, just for this vf page that creates a New Task with the additional Long Text Area field I need.
Angela SchloederAngela Schloeder
If I used a formula field to pull in from Event, users couldn't see them when creating this New Task.
Naval Sharma4Naval Sharma4
Hi Angela,

Are you sure this is the same page which you are posting code for?
Naval Sharma4Naval Sharma4
Angela,I am glad you found it out.