+ Start a Discussion
Sakthi169Sakthi169 

How to create the link and after click link open the form in vf

Hi,

I need to create the link and when i click the link it open the form in 

Account page. My form is 

<apex:page standardcontroller="Account" tabstyle="Account" extensions="MyExtension" >
 
 <apex:form >
 
 <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:page>
how to create link for this page????
Best Answer chosen by Sakthi169
Abu HashimAbu Hashim
public with sharing class MyExtension {
    public ApexPages.StandardController sc;
    public boolean showForm{get;set;}
    public MyExtension(ApexPages.StandardController sc) {
        this.sc = sc;
        showForm = false;
    }
    public PageReference save() {
        Account a = (Account) sc.getRecord();
        a.OwnerId = [select Id from User where LastName = 'Umadevi'].Id;
        return sc.save();
    }
     public void showForm2(){
           showForm = true;
      }
}

Please try this!!

All Answers

Abu HashimAbu Hashim
@Umadevi, 
Js create a boolean flag in ur extension and default it to false. Put ur form inside a apex:outputpanel - rendered with that boolean flag u created. Create a command link on vf page - on click of which js flip the flag value to true in ur extension and reRender the outputpanel created on this commandlink. Let me know if u need anything.
Sakthi169Sakthi169
@Abu Hashim,

Can u provide any example???
Abu HashimAbu Hashim
@Umadevi, Please try the below snippet and c if that works out.!!!

<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>

Controller code:
public showForm{get;set;}

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

public void showForm2(){
 showForm = true;
}
Sakthi169Sakthi169
Hi Abu Hashim,

I got the following error...

Compile Error: unexpected token: '{' at line 13 column 15
Abu HashimAbu Hashim
Please use this line:
public boolen showForm{get;set;}

Forgt to declare the type. Also, r u receiving the error in controller ?? If so, please add the boolean type and re-check.
Sakthi169Sakthi169
I added the controller after i got this error

Error: Compile Error: unexpected token: '=' at line 15 column 9

And in my page,i got this error 

Unknown method 'AccountStandardController.showForm2()'

 
Sakthi169Sakthi169
Hi Abu Hashim,

I forget to put 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 = 'Umadevi'].Id;
      
        return sc.save();
    }
}
Abu HashimAbu Hashim
public with sharing class MyExtension {
    public ApexPages.StandardController sc;
    public boolean showForm{get;set;}
    public MyExtension(ApexPages.StandardController sc) {
        this.sc = sc;
        showForm = false;
    }
    public PageReference save() {
        Account a = (Account) sc.getRecord();
        a.OwnerId = [select Id from User where LastName = 'Umadevi'].Id;
        return sc.save();
    }
     public void showForm2(){
           showForm = true;
      }
}

Please try this!!
This was selected as the best answer