function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
vjwvjw 

Checking for empty list

I have a custom button on a contact list view that's connected to a VF page. All I want to do on the VF page is run some DML to update the selected contacts, then go back to the list view, as long as at least one contact was selected. If no contacts were selected, I want to display an err message. When I run the page, whether or not I've selected any contacts, I get this err message: "Unknown method 'ContactBarcodeCreated.updateBarcodeCreated()'" Thanks for any help you can provide.

VF page tag:


Apex:
public class ContactBarcodeCreated {
public sObject[] objs { get; private set; }
public boolean hasSelection { get; private set; }


public pageReference updateBarcodeCreated(ApexPages.StandardSetController controller ){
objs = controller.getSelected();
hasSelection = !objs.isEmpty();
if (hasSelection) {

Contact[] cons = new contact[0];
for (sObject c : objs){
cons.add(new Contact(
id=c.id,
Barcode_Card_Created__c = true,
Barcode_Card_Created_Date__c = system.today()
));
}
update cons;

// go back
string url = ApexPages.currentPage().getParameters().get('retURL');
pageReference prevPage = new PageReference((url != null) ? url : '/006');
prevPage.setRedirect(true);
return prevPage;
}
else {
return null;
}

}


}
dragonmagicldragonmagicl

Unknown method 'ContactBarcodeCreated.updateBarcodeCreated() is because your method takes in a parameter.

 

You need something like this

 

 

private ApexPages.StandardSetController controller; public ContactBarcodeCreated(ApexPages.StandardSetController controller) { this.controller = controller; ... } public pageReference updateBarcodeCreated(){ objs= this.controller.getSelected(); ... }

 

 

vjwvjw
Thanks for the response. When I put the parameter in the constructor and then try to save the VF page, I get "Save error: Index: 0"  I did a search on that in the forums and a couple of folks said it was because you can't pass a parameter in a constructor method in a custom controller ... ? Any other tips would be much appreciated. Thank you!