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
amar joshiamar joshi 

can extension's save method call standard controller's save method.......

Hi Experts,

can i call standard controller's save action in my extension controller...

 

 

<apex:page standardcontroller="opportunity" extension="oppoExtesion"> <apex:form> <apex:pageblock> <apex:pageblockbutton> <apex:commandbutton value="Save" action="{!mysave}"/> </apex:pageblockbutton> <apex:inputfield value="{!opportunity.name}"/> <apex:inputfield value="{!opportunity.amount}"/> <apex:inputfield value="{!opportunity.closedate}"/> </apex:pageblock> </apex:form> </apex:page> ********Extension************* public class oppoextension { public pagereference mysave() { my validation check...... //Here i wnat to call standard controller's Save Action to perform the save operation as standard way... save(); } }

 

i want to experience standard salesforce validation check , field level security , profile base permission 

as well as my custom validation through apex code

 

so how can i standard controller's Save from my extension's save method...


 

Best Answer chosen by Admin (Salesforce Developers) 
amar joshiamar joshi

hi all,

 

i found the solution u can invoke the save of standard controller

 

public with sharing class oppoextension { public opportunity oppo; ApexPages.StandardController GstdController; // The extension constructor initializes the private member // variable acct by using the getRecord method from the standard // controller. public oppoextension(ApexPages.StandardController stdController) { GstdController = stdController; this.oppo= (opportunity)GstdController.getRecord(); } public pagereference mysave() { if(oppo.First_Name != 'amar') { oppo.adderror('Error'); } else { ApexPages.StandardController sc = new ApexPages.StandardController(stdController); PageReference pr = GstdController.save(); pageReference pv = GstdController.view(); return pv; } return null; } }

 


 

All Answers

amar joshiamar joshi

hi all,

 

i found the solution u can invoke the save of standard controller

 

public with sharing class oppoextension { public opportunity oppo; ApexPages.StandardController GstdController; // The extension constructor initializes the private member // variable acct by using the getRecord method from the standard // controller. public oppoextension(ApexPages.StandardController stdController) { GstdController = stdController; this.oppo= (opportunity)GstdController.getRecord(); } public pagereference mysave() { if(oppo.First_Name != 'amar') { oppo.adderror('Error'); } else { ApexPages.StandardController sc = new ApexPages.StandardController(stdController); PageReference pr = GstdController.save(); pageReference pv = GstdController.view(); return pv; } return null; } }

 


 

This was selected as the best answer
Marc C.Marc C.

Where are you doing upsert oppo? I don't see how the standard save() method knows anything about your oppo and it's fields...

Jaap BranderhorstJaap Branderhorst
The stdController in the constructor oppoextension gets the id of the opportunity from the URL (standard functionality). In the mysave method the save method on that stdcontroller is called and in that save method the upsert is done.
cloud explorer.ax1858cloud explorer.ax1858

This is absolute awesome man.........................