I have two required fields inside a Visualforce Page: prodottoservizio, quant. Inside the page I can build a list of objects shown inside a table. Now I want to insert a Delete Button that deletes all the object records created inside the controller extension and return to the previous URL.

Here my VF code:

 <apex:PageBlock id="contratto">
    <apex:pageBlockButtons location="bottom">
        <apex:commandButton action="{!createContr}" value="Scegli i Prodotti" reRender="panprodotti" />
        <apex:commandButton action="{!deleteContract}" value="Elimina Contratto e prodotti selezionati" onclick="window.history.back()" />
    <apex:pageBlockSection title="Specifiche Contratto">
        <apex:input required="true" label="Data inizio contratto" value="{!cData}" type="date" id="datainiziocontr" />
        <apex:input required="true" label="Durata contratto(mesi)" value="{!cDurata}" type="number" id="durcontr" />
        <apex:input label="Condizioni speciali" value="{!cCondizioni}" type="text" id="condizioni" />
    apex:outputPanel id="panprodotti">
        <apex:pageBlock rendered="{!cData<>null}">
            <apex:pageBlock id="pselected">
                <apex:pageBlockSection title="Inserisci i Prodotti" collapsible="false" >
                    <apex:inputField required="true" id="prodottoservizio" value="{!prodotto.Scelta__c}"/>
                    <apex:inputField id="gionol" value="{!prodotto.Giorni_durata_noleggio__c}"/>
                    <apex:inputField required="true" id="quant" value="{!prodotto.Quantit_prodotto__c}"/>
                    <apex:inputField id="sconto" value="{!prodotto.Sconto__c}"/>
            <apex:pageBlock >
                <apex:pageBlockButtons location="top">
                    <apex:commandButton action="{!addFromShoppingCart}" value="Aggiungi al Contratto" reRender="pinserted,panprodotti" />

and this is my function:

public void deleteContract(){
    delete shoppingCart;
    delete nuovocontratto;

When I click the button I have an error because that two fields are required. How How can I solve this Problem?

P.S. I posted a code's portion because the controller is huge.

  • Seems like you included the wrong commandButton in your posted markup? It calls addFromShoppingCart, not deleteContract.
    – Adrian Larson
    Jul 15, 2016 at 13:25
  • sorry, I post an old version, now I edit the post. Thank you for helping me Jul 15, 2016 at 13:26
  • Use immediate =false Jul 15, 2016 at 13:26
  • @SantanuBoral false is the default value for the immediate property...
    – Adrian Larson
    Jul 15, 2016 at 13:27
  • Actually I meant to say true, but at time of writing wrongly written Jul 15, 2016 at 13:29

1 Answer 1


You can bypass page-side validations by setting the immediate="true" property on a commandButton tag. In the case of a delete operation, it seems like that may be the appropriate course of action.

Here is the description of the immediate attribute in the documentation:

A Boolean value that specifies whether the action associated with this component should happen immediately, without processing any validation rules associated with the fields on the page. If set to true, the action happens immediately and validation rules are skipped. If not specified, this value defaults to false.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .