You need to sign in to do that
Don't have an account?
vjw
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;
}
}
}
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;
}
}
}
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(); ... }