Pages

Wednesday, March 14, 2012

Using the Standard Controller save method with an Extension Controller

When using an Extension Controller it can be useful to wrap the save method of the Standard Controller with a custom save method. This allows for things like:

  • custom validation
  • custom field assignment
  • altering the resuling PageReference redirection
public with sharing class CustomExtensionController {
    
    Opportunity opp;
    ApexPages.StandardController sController;
    
    public CustomExtensionController (ApexPages.StandardController controller) {
        sController = controller;
        opp = (Opportunity)controller.getRecord();
    }
    
    public PageReference saveCustom() {
        
        // Custom Save code here...
        
        PageReference pr = sController.save();
        return pr;
        
        // Alternatively, could return a PR to the view page.
        //pageReference pv = sController.view();

    }
}

2 comments:

  1. Hi ,
    How to give save functionality Dynamically comming object through URL?

    Here object name through URL will come look like

    https://Raju.ap1.visual.force.com/apex/Dynamicsetpage?DFN=ramobj
    In My apex class i get this objects as using schema method and i displayed all fields Dynamically

    strtemp=ApexPages.currentPage().getParameters().get('DFN');

    this.DFN=strtemp;

    system.debug('*********objectselected//**********'+strtemp);
    String strFieldName = 'raju__'+DFN + '__c'; //Object name
    system.debug('*********objects**********'+strtemp);

    My Question:How to give save functonality of this Dyamically getting object?

    help me..........

    ReplyDelete
    Replies
    1. Hello,

      Try asking your question on http://salesforce.stackexchange.com. It is better medium for such questions. You might want to lookup dynamic SOQL and the associated Database methods.

      Regards,
      Daniel

      Delete