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
springerwaspringerwa 

Create "New" Note button on Visualforce Page

I have the following "Summary" Visualforce Page selectively showing fields and related lists from Opportunity.  I want the user to be able to add a new note by clicking a "New" button from this screen but I have not been able to find the syntax for an Opportunity Note.

 

Relevant PageBlock section and the code in Red that throws the error:

 

Can anyone assist with the correct code to add a new Opportunity Note from this VisualForce page?

 

<apex:pageBlock title="Notes"> <apex:pageBlockButtons > <apex:commandButton action="/002/e?parentid={!opportunity.id}" value="New Note"/>

</apex:pageBlockButtons> <apex:pageBlockTable value="{!Opportunity.Notes}" var="note"> <apex:column width="30px"> <apex:facet name="header"><strong>Link</strong></apex:facet> <div> <a href="/{!note.id}">Link</a> </div> </apex:column> <apex:column value="{!note.createddate}" width="120px"/> <apex:column value="{!note.createdbyid}" width="120px"/> <apex:column value="{!note.body}" /> </apex:pageBlockTable> </apex:pageBlock>

 

 

 

 

Entire Page Code:

<apex:page standardController="Opportunity" standardStylesheets="true" showHeader="false" sidebar="false" tabStyle="Opportunity"> <table width="98%" height="50%" border="0" cellpadding="0" cellspacing="0"> </table> <apex:form > <apex:pageBlock title="Opportunity Strategy - Details"> <apex:pageBlockSection title="Opportunity Information" columns="3"> <apex:pageBlockSectionItem > <apex:outputLabel value="Opportunity" for="opportunity"/> <a href="/{!opportunity.Id}">{!opportunity.Name }</a> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem dataStyle="width: 240px"> <apex:outputLabel value="Account" for="account"/> <a href="/{!Opportunity.Account.id}">{!Opportunity.Account.Name}</a> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="State" for="state"/> <apex:outputField id="address" value="{!Opportunity.Account.BillingState}" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Account Type" for="industry"/> <apex:outputField id="industry" value="{!Opportunity.Account.Type}" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem dataStyle="width: 240px"> <apex:outputLabel value="Stage" for="stage"/> <apex:outputField id="stage" value="{!Opportunity.Stagename}" style="{!if(Opportunity.StageName='Red','background-color:#FE2E2E', if(Opportunity.StageName='Green','background-color:#00FF80',if(Opportunity.stagename='Yellow','background-color:#F3F781','color:black')))};width: 80px; text-align: right;"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Amount" for="amount"/> <apex:outputField id="amount" value="{!Opportunity.Amount}"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Owner" for="owner"/> <apex:outputField id="owner" value="{!Opportunity.OwnerId}"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem dataStyle="width: 240px"> <apex:outputLabel value="Type" for="type"/> <apex:outputField id="type" value="{!Opportunity.Account.Account_Type__c}"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Close Date" for="closedate"/> <apex:outputField id="closedate" value="{!Opportunity.CloseDate}"/> </apex:pageBlockSectionItem> </apex:pageBlockSection> <apex:pageBlockSection title="Description" columns="1"> <apex:pageBlockSectionItem > <apex:outputLabel value="Description" for="description"/> <apex:outputField id="description" value="{!Opportunity.Description}"/> </apex:pageBlockSectionItem> </apex:pageBlockSection> <apex:pageBlockSection title="Goals and Strategies" columns="2"> <apex:pageBlockSectionItem > <apex:outputLabel value="Next Steps" for="next"/> <apex:outputField id="next" value="{!Opportunity.NextStep}"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Last Activity Date" for="lastactivity"/> <apex:outputField id="lastactivity" value="{!Opportunity.lastactivitydate}"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Goal/Objective" for="goal"/> <apex:outputField id="goal" value="{!Opportunity.Goal_Objective__c}"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="ODM Strategy" for="odm"/> <apex:outputField id="odm" value="{!Opportunity.ODM_Strategy__c}"/> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> <apex:pageBlock title="Notes"> <apex:pageBlockButtons > <apex:commandButton action="/002/e?parentid={!opportunity.id}" value="New Note"/> </apex:pageBlockButtons> <apex:pageBlockTable value="{!Opportunity.Notes}" var="note"> <apex:column width="30px"> <apex:facet name="header"><strong>Link</strong></apex:facet> <div> <a href="/{!note.id}">Link</a> </div> </apex:column> <apex:column value="{!note.createddate}" width="120px"/> <apex:column value="{!note.createdbyid}" width="120px"/> <apex:column value="{!note.body}" /> </apex:pageBlockTable> </apex:pageBlock> <apex:pageBlock title="Pending Activity Summary"> <apex:pageBlockTable value="{!Opportunity.OpenActivities}" var="item"> <apex:column width="30px"> <apex:facet name="header"><strong>Link</strong></apex:facet> <div> <a href="/{!item.id}">Link</a> </div> </apex:column> <apex:column value="{!item.summary__c}"/> <apex:column value="{!item.subject}"/> <apex:column value="{!item.status}"/> <apex:column value="{!item.istask}"/> <apex:column value="{!item.activitydate}"/> <apex:column value="{!item.whoid}"/> <apex:column value="{!item.whatid}"/> </apex:pageBlockTable> </apex:pageBlock> <apex:pageBlock title="Meeting/Events"> <apex:pageBlockTable value="{!Opportunity.Events}" var="item"> <apex:column width="30px"> <apex:facet name="header"><strong>Link</strong></apex:facet> <div> <a href="/{!item.id}">Link</a> </div> </apex:column> <apex:column value="{!item.summary__c}"/> <apex:column value="{!item.subject}"/> <apex:column value="{!item.activitydate}"/> <apex:column value="{!item.whatid}"/> </apex:pageBlockTable> </apex:pageBlock> <apex:pageBlock title="Closed Activity Summary"> <apex:pageBlockTable value="{!Opportunity.Activityhistories}" var="item"> <apex:column width="30px"> <apex:facet name="header"><strong>Link</strong></apex:facet> <div> <a href="/{!item.id}">Link</a> </div> </apex:column> <apex:column value="{!item.summary__c}"/> <apex:column value="{!item.subject}"/> <apex:column value="{!item.status}"/> <apex:column value="{!item.activitydate}"/> <apex:column value="{!item.whoid}"/> </apex:pageBlockTable> </apex:pageBlock> <apex:pageBlock title="Contact and Roles"> <apex:pageBlockTable value="{!Opportunity.OpportunityContactRoles}" var="item"> <apex:column value="{!item.role}" width="100px"/> <apex:column value="{!item.Contactid}"width="150px"/> <apex:column value="{!item.Contact.Account.name}" width="300px"/> <apex:column value="{!item.Contact.Title}" width="150px"/> <apex:column value="{!item.Contact.email}"width="150px"/> <apex:column value="{!item.Contact.phone}"width="150px"/> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>

 

bob_buzzardbob_buzzard
And what error are you seeing?
bob_buzzardbob_buzzard

Actually, I think I can guess the error - that you don't have a method of that name.

 

Check the docs for the commandButton component - the action attribute needs to be a method in your controller.  If the URL you have used is correct, try generating a link using the outputLink component.

Anand@SAASAnand@SAAS

I don't believe you can specify URLs in the action attribute. Here's a few ways to go about this:

- Change the command button to a "outputLink" and use CSS to style it and make it look like a button. Use the URLFOR function to get the right URL.

 

<apex:outputLink value="{!URLFOR($Action.Note.New)}"> New Note </apex:outputLink>

 

 

- Create a method in your controller called "CreateNote" that will redirect the user to that page. Refer to the method  in your command button i.e. action="{!createNote}"

 

 

prathap raoprathap rao

I looked at this post yesterday and got a lead on similar functionality that I was trying to implement.

 

You can use command button on any standard controller and create a button to reference standard objects like a Lead, Contact etc...

 

Thanks to my manager who pushed my ass to walk this extra mile of using command button than using a link

 

Use the following code as per your requirement :)

The {URLFOR{$Action.Object.New.ObjectType.Object}} creates the link :)

<apex:page standardcontroller="Account">
<apex:form >
<apex:sectionHeader title="hello"/>
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandbutton action="{!URLFOR($Action.Lead.New, $ObjectType.Lead)}" title="New Lead" value="New Lead"> </apex:commandbutton>
<apex:commandButton action="{!cancel}" value="Cancel"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
samrat.1985@lntinfotechsamrat.1985@lntinfotech

<apex:page standardController="Custom_Object__c" tabStyle="Custom_Object__c">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />   
    <style>
        .activeTab {background-color: #236FBD; color:white; background-image:none}
        .inactiveTab {background-color: lightgrey; color:black; background-image:none}
        .br {mso-data-placement:same-cell;}
    </style>
 </head> 
    <apex:tabPanel switchType="client" selectedTab="tabNotes" id="CustomObjectTabPanel" tabClass="activeTab" inactivetabClass="inactiveTab">          
        <apex:tab label="Notes" name="Notes" id="tabNotes">           
            <apex:form >
                <apex:pageBlock title="Notes">
                    <apex:pageBlockTable value="{!Custom_Object__c.Notes}" var="note">
                        <apex:column value="{!note.createddate}" width="120px"/>
                        <apex:column value="{!note.createdbyid}" width="120px"/>
                        <apex:column value="{!note.body}" />
                    </apex:pageBlockTable>
                    <apex:pageBlockButtons location="top">
                        <apex:commandbutton value="Add Comment" action="/002/e?parent_id={!LEFT(Custom_Object__c.Id,15)}&retURL=%2Fapex%2FCustom_Object%3Fid%3D{!Custom_Object__c.Id}"/>
                    </apex:pageBlockButtons>
                </apex:pageBlock>
            </apex:form>
        </apex:tab>
    </apex:tabPanel>
</apex:page>

 

This should work i tried this out it works.

Even i am new to VF