0

// Apex Class //This problem is occurred while I Use extension concept in VisualForce Page it give error Here is Code//

public class MassDelete {

    public List<Account>accounts{set;get;}
    public  MassDelete(ApexPages.StandardSetController controller){
        accounts=(List<Account>)controller.getSelected();
         List<String> fields=new List<String>          {'Name','Phone','Industry','Rating'};
           controller.addFields(fields);

    }
    public PageReference Deletee(){
        Database.delete(accounts ,false);
        PageReference p=new PageReference('/001/0');
        return p; 
    }
}

//VisualForce page
<apex:page  standardController="Account" extensions="MassDelete">
    <apex:form>
     <apex:pageBlock>
        <apex:pageBlockButtons>
            <apex:commandButton value="Delete" action="{!Deletee}"/>
         </apex:pageBlockButtons>
         <apex:pageBlockTable value="{!accounts}" var="a">
             <apex:column value="{!a.Name}"/>
             <apex:column value="{!a.Phone}"/>
             <apex:column value="{!a.Industry}"/>
             <apex:column value="{!a.Rating}"/>
         </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>
2

As I can see, in your extension you are using StandardSetController. You have to alter your VF page to use recordSetVar. StandardSetController is used for showing records in bulk and in pagination, the VF page iterates over them. The list variable used for iteration is recordSetVar.

<apex:page  standardController="Account" extensions="MassDelete" recordSetVar="accounts">
    <apex:form>
     <apex:pageBlock>
        <apex:pageBlockButtons>
            <apex:commandButton value="Delete" action="{!Deletee}"/>
         </apex:pageBlockButtons>
         <apex:pageBlockTable value="{!accounts}" var="a">
             <apex:column value="{!a.Name}"/>
             <apex:column value="{!a.Phone}"/>
             <apex:column value="{!a.Industry}"/>
             <apex:column value="{!a.Rating}"/>
         </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Src: What is recordSetVar and where is it used?

Src : How to use StandardSetController in extension class

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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