简体   繁体   English

自定义按钮或使用标准控制器链接到Visualforce页面

[英]Custom Button or Link to a Visualforce page with a standard controller

I create page using visual force.How to create the custom button/link for the standard page. 我使用视觉力创建页面。如何为标准页面创建自定义按钮/链接。 I need to open the page after click the custom button/link. 单击自定义按钮/链接后,我需要打开页面。 how to do this. 这个怎么做。 My code is below 我的代码如下

<apex:page standardcontroller="Account" tabstyle="Account" extensions="MyExtension" >
 <apex:form id="form1">
  <apex:commandlink action="{!showForm2}" value="Show the Form" rendered="{!showForm}" reRender="form2,op1"/>
</apex:form>
<apex:outputpanel id="op1">
 <apex:form id="form2">
 <apex:sectionheader title="Account Details" subtitle="{!if(Account.Id==null,'New Account',Account.Name)}"></apex:sectionheader>
<apex:pageblock mode="edit" id="leadPB" title="Account Edit">

 <apex:pageblockbuttons >
<apex:commandbutton action="{!save}" value="Save"></apex:commandbutton>
 <!-- If you wish to implement Save & New functionality you will have to write an Apex Extension with your own Save & New Method -->
 <apex:commandbutton action="{!cancel}" value="Cancel"></apex:commandbutton>
 </apex:pageblockbuttons>

        <apex:pageBlockSection >
            <apex:inputtext value="{!Account.LastName}" label="Customer Name"/>
            <apex:inputtext value="{!Account.PersonMobilePhone}"/>
            <apex:inputtext value="{!Account.CustomLandLine__c}"/>
            <apex:inputField value="{!Account.City__c}"/>
            <apex:inputField value="{!Account.PersonEmail}"/>
             <apex:inputField value="{!Account.Source__c}"/>

            <!-- <apex:commandButton action="{!save}" value="Save!"/>-->
        </apex:pageBlockSection>
    </apex:pageBlock>
<apex:pageMessages />
</apex:form>
</apex:outputpanel>
</apex:page>`

My class code 我的班级代码

public with sharing class MyExtension {
    private ApexPages.StandardController sc;
    public MyExtension(ApexPages.StandardController sc) {
        this.sc = sc;
    }
    public PageReference save() {
        Account a = (Account) sc.getRecord();
        a.OwnerId = [select Id from User where LastName = 'Kapoor'].Id;
        a.OwnerId = [select Id from User where FirstName = 'Raoul'].Id;
        return sc.save();
    }
public boolean showForm{get;set;}

// default the var to false;
showForm = false;

public void showForm2(){
 showForm = true;
}
}

But it shows the following error 但它显示以下错误

the controller 控制器

Error: Compile Error: unexpected token: '=' at line 15 column 9 错误:编译错误:意外令牌:第15行第9列为'='

And in my page,i got this error 在我的页面上,我收到了这个错误

Unknown method 'AccountStandardController.showForm2()' 未知方法'AccountStandardController.showForm2()'

how to solve this 如何解决这个问题

Please put showForm = false; 请把showForm = false; right below this.sc = sc; this.sc = sc;正下方this.sc = sc; . Everything inside the constuctor is for initialization/default values. 构造函数中的所有内容均用于初始化/默认值。
You got the second error because the controller extension is not saved successfully. 您收到第二个错误,因为控制器扩展未成功保存。 Once you fix the first one, both errors should disappear. 修复第一个错误后,两个错误均应消失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM