• Peter Schmitke
  • NEWBIE
  • 0 Points
  • Member since 2014
  • Developer
  • Torrent Consulting

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hey there,

I have a Cancel button on my visualforce page, it works for every single one of my custom objects except the transactions object. Upon testing it out manually It would not cancel the record creation page and return to my tabbed VF page because of required fields. I searched a bit and learnt about immediate="true" which would trigger the cancel function before the validation rules can take effect. 

Upon inserting the immediate="true" parameter into my visualforce page and testing, I was re-directed to a page that said I had insufficient privledges to access the page.

Below are my extension and VF page with relevent sections highlighted. Any light on the subject would be appreciated.

Extension:

public class extSaveTraButton {

    public Transaction__c tra {get;set;}
   
    public extSaveTraButton(ApexPages.StandardController controller) {
  
        this.tra = (Transaction__c)controller.getRecord();

    }
   
   
    Public PageReference saveDestinyTransaction(){
   


    if(System.currentPageReference().getParameters().get('clone') == '1'){

        //Set record id to null

        tra.Id = null;

    }
   
        insert tra;
        // Send the user to the detail page for the new account.
       PageReference pageRef= new PageReference('/apex/DestinyAccount?id='+tra.account__c+'&Sfdc.override=1');
        pageRef.getParameters().put('tab','Transactions');
        return pageRef;
   
    }
   
    Public PageReference cancelDestinyTransaction(){
    PageReference pageRef = new PageReference('/apex/DestinyAccount?id='+tra.account__c+'&Sfdc.override=1');
    pageRef.getParameters().put('tab','Transactions');
    return pageRef;

   
    }

}

VF page:

<apex:page standardController="Transaction__c" extensions="extSaveTraButton">
    <apex:form >
        <apex:pageBlock >
       
       
            <apex:commandButton value="Save" action="{!saveDestinyTransaction}"/>
            <apex:commandButton value="Cancel" immediate="true" action="{!cancelDestinyTransaction}"/>
           
            <apex:pageBlockSection >
           
           
            <apex:repeat value="{!$ObjectType.Transaction__c.FieldSets.TransactionsFieldSet}" var="f"> 
                <apex:inputfield value="{!Transaction__c[f]}"> 
            </apex:inputfield></apex:repeat>
          
          </apex:pageBlockSection>
           

 
                  
</apex:pageBlock>
    </apex:form>
   
    </apex:page>