+ Start a Discussion
PuranKishorePuranKishore 

How to create Cancel() and Save() when we use button

public class AllAccountEx1_Controller
{
    public AllAccountEx1_Controller()
    {
        acct = new Account();
        
        accontblock=true;
    }
 
    public Account acct{set;get;}
    public Account getAcc()
    {
        return acct;
    }
    public list<Account> lst = new list<Account>();
    public list<Account> getAccounts()
    {
        lst = [Select Name,Site,BillingStreet,BillingCity,BillingState,Billingpostalcode,Billingcountry,Phone,Type,OwnerId, Account_Email__c from Account limit 100];
        
        return lst;
    }
    
    public boolean accountedit{set;get;}
    public boolean accontblock{set;get;}
    public pagereference onClick()
    {
        string idval = apexpages.currentpage().getparameters().get('accid');
        pagereference ref = new pagereference('/'+idval);
        return ref;
        
    }
    public account ac{set;get;}
    public pagereference Edit()
    {
        string selectedid=apexpages.currentpage().getparameters().get('acid');
        ac=[select id,name,Annualrevenue,Accountnumber from account where id=:selectedid];
        accountedit=true;
        accontblock=false;
    return null;
    }
    
    public void Del()
    {
       
       string selectedid=apexpages.currentpage().getparameters().get('accountid');
        account ac=[select id,name,Annualrevenue,Accountnumber from account where id=:selectedid];
        delete ac;
       
    }
    
    public void cancel()
    {
        
       
        //pagereference ref1 = new pagereference(acct.view());
        accountedit=false;
        accontblock=true;
        //return ref1;
    }
    public void getSave()
    {
              //string selectedid=apexpages.currentpage().getparameters().get('acid');
              
          // Account   acc1 = new Account();
              //acc1=[select id,name,Annualrevenue,Accountnumber from account where id=:selectedid];
                update ac;
                accountedit=false;
                accontblock=true;
        
    }
}

ForceMantis (Amit Jain)ForceMantis (Amit Jain)

Bhawani SharmaBhawani Sharma
You can use standard cancel functionality as you are nothing doing special in your cancel method. Like
<apex:commandButton value="Cancel" action="{!cancel}" />

for Save
<apex:commandButton value="Save" action="{!getSave}" />
PuranKishorePuranKishore

I had tryed for that i got for save()

But for cancel() I used javascript Confirm() in that i applyed for delete when i click ok it will delete when i click cancel it is also deleting and for cancel().

If i want to press cancel i want to get the previous page how can i get it can u please tell me

ForceMantis (Amit Jain)ForceMantis (Amit Jain)

<apex:commandButton value="Cancel" onclick="return confirm('Are you sure?');" action="{!Cancel}" />