You need to sign in to do that
Don't have an account?
Angela 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:pageBlockButtons>
<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>
<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>
<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}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller
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);
}
}
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:pageBlockButtons>
<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>
<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>
<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}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller
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);
}
}
You can use ReadOnly attribute of apex components.
If you are using apex:outputField then fields are already readOnly. Can you let us know more about your requirement.
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.
Are you sure this is the same page which you are posting code for?
Regards,
Naval