2

Iam using SAVE and DELETE Buttons in Visualforce page. And when i click the SAVE button it will be insert in account object.But How to delete the same record(when i click the DELETE button). How is it possible, Plese Help me.

  • Is this a visualforce page where there is a list of Accounts and associated buttons with them? – ajinkyah Jul 9 '15 at 12:41
2

You can do this way Also.....

    public Account ac;
    public void Create(){

        ac = new Account(name='MyAccount');
        insert ac;

    }
    public void delete(){
       if(ac.id! = null){ 
        delete ac;
       }
    }
1

You can use standard controller action to do this. Use

<apex:commandButton action="{!delete}" value="Delete"/>

to delete the record currently in context.

For this to work, you should pass ?id=001xxxxxxxxxxxx at the end of your url.

Refer: Using Standard Controller Actions

Hope it hleps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.