You need to sign in to do that
Don't have an account?
ppiyush
Testing Pagereferences
How can I test a pagereference method such as below:
public class childContact { private List<Contact> cntz; private Account acct; public childContact(ApexPages.StandardController controller) { this.acct= (Account)controller.getRecord(); } public Account getAt() { Account[] at = [Select id,name FROM Account where id= :acct.id]; if(at.size()>0){ return at[0]; } else{ return null; } } public List<Contact> getCntz() { Account act = [Select id FROM Account where id = :acct.id]; cntz = [Select id, Name, Client_Potential__c, title, Address_City__c, Direct_Phone__c, Email, Open_Projects__c, Days_Since_Last_Contact__c, Account.name, Ownerid from Contact where (account.parentid = :act.id OR account.id = :act.id)]; return cntz; } public PageReference UpdateRecords() { // this simple line of code finds out which column was changed and update the // relevant account record accordingly! update cntz; return null; } }
The Visual Force pageBlockButton using the pagereference method looks like this:
<apex:pageBlockButtons location="top"> <apex:commandButton value="Update" action="{!UpdateRecords}" id="theButton" rerender="page" status="status" onComplete="window.location.reload()"></apex:commandButton> </apex:pageBlockButtons>
Any help is much appreciated - thanks!
Yup, but I would change it to a void method. PageReference will work but if you aren't sending the user anywhere it doesn't really make sense from a self documenting point of view.
All Answers
Once you instantiate your controller, you can call the pagereference like a method.
Yup, but I would change it to a void method. PageReference will work but if you aren't sending the user anywhere it doesn't really make sense from a self documenting point of view.