You need to sign in to do that
Don't have an account?
mramaprasad.ax1826
How to get the Save and cancel button working on custom visual force page ?
I want to overwrite view button of the opportunity products so I can have specific fields based on the product type.
Here is the visual page code:
<apex:page standardController="OpportunityLineItem" extensions="overrideCon" sidebar="true" showHeader="true">
<apex:form >
<input value=" Save " class="btn" title="Save" name="save" type="submit"/>
<input value="Cancel" class="btn" title="Cancel" name="cancel" type="submit"/>
<apex:pageBlock id="xxxpb1">
Opportunity: {!opp.name}<br></br>
Product: {!pro.name}
Quantity: <apex:inputField value="{!OpportunityLineItem.Quantity}"/>
<apex:pageBlockSection id="xxxpbs2" rendered="{!OpportunityLineItem.Product2Id=='01t17000000BmMdAAK'}">
product 1 fields
</apex:pageBlockSection>
<apex:pageBlockSection id="xxxpbs3" rendered="{!OpportunityLineItem.Product2Id=='01t17000000BmMTAA0'}">
product 2 fields
</apex:pageBlockSection>
<apex:pageBlockSection id="xxxpbs4" rendered="{!OpportunityLineItem.Product2Id=='01t17000000BX9SAAW'}">
product 3 fields
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Here is the apex code:
public class overrideCon {
private final ID oliId;
public overrideCon (ApexPages.StandardController stdController) {
this.oliId = (String)stdController.getId();
}
Opportunity opp;
OpportunityLineItem oli;
Product2 pro;
public Product2 getPro(){
if (pro == null) {
pro = [select Id, name from Product2 where id = :getOli().Product2Id];
}
return pro;
}
public Opportunity getOpp(){
if(opp == null){
opp = [select Id, name, amount, Pricebook2.Name from Opportunity where id = :getOli().Opportunityid];
}
return opp;
}
public OpportunityLineItem getOli() {
if(oli == null){
oli = [select Id, Product2Id, OpportunityID from OpportunityLineItem where ID = :oliID];
}
return oli;
}
public PageReference save() {
update oli;
return null;
}
public PageReference cancel() {
return null;
}
}
How do I get the save and cancel button to work so changes are saved.
Here is the visual page code:
<apex:page standardController="OpportunityLineItem" extensions="overrideCon" sidebar="true" showHeader="true">
<apex:form >
<input value=" Save " class="btn" title="Save" name="save" type="submit"/>
<input value="Cancel" class="btn" title="Cancel" name="cancel" type="submit"/>
<apex:pageBlock id="xxxpb1">
Opportunity: {!opp.name}<br></br>
Product: {!pro.name}
Quantity: <apex:inputField value="{!OpportunityLineItem.Quantity}"/>
<apex:pageBlockSection id="xxxpbs2" rendered="{!OpportunityLineItem.Product2Id=='01t17000000BmMdAAK'}">
product 1 fields
</apex:pageBlockSection>
<apex:pageBlockSection id="xxxpbs3" rendered="{!OpportunityLineItem.Product2Id=='01t17000000BmMTAA0'}">
product 2 fields
</apex:pageBlockSection>
<apex:pageBlockSection id="xxxpbs4" rendered="{!OpportunityLineItem.Product2Id=='01t17000000BX9SAAW'}">
product 3 fields
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Here is the apex code:
public class overrideCon {
private final ID oliId;
public overrideCon (ApexPages.StandardController stdController) {
this.oliId = (String)stdController.getId();
}
Opportunity opp;
OpportunityLineItem oli;
Product2 pro;
public Product2 getPro(){
if (pro == null) {
pro = [select Id, name from Product2 where id = :getOli().Product2Id];
}
return pro;
}
public Opportunity getOpp(){
if(opp == null){
opp = [select Id, name, amount, Pricebook2.Name from Opportunity where id = :getOli().Opportunityid];
}
return opp;
}
public OpportunityLineItem getOli() {
if(oli == null){
oli = [select Id, Product2Id, OpportunityID from OpportunityLineItem where ID = :oliID];
}
return oli;
}
public PageReference save() {
update oli;
return null;
}
public PageReference cancel() {
return null;
}
}
How do I get the save and cancel button to work so changes are saved.
So I added
<input value=" Save " class="btn" title="Save" action="{!save}" name="save" type="submit"/>
which gives me [Error] Error: Unknown property 'OpportunityLineItemStandardController.save'
Please help!
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>