+ Start a Discussion
MSVRadMSVRad 

Custom Button in Custom Controller Help

I need help with the controller side of this custom button.  I have created a custom vf page that is similar to the view all button on Activity History.  I am trying to create a Back or Cancel button and I am not sure what the syntax should look like.  The vf page comes from a button on the Case related list on the Account page. So I am trying to go from a custom case page to a standard account page.

 

This is my custom controller.  I am not sure what to do in my account query so that when the Cancel method calls it the account page is returned.  Any help or suggestions would be greatly appreciated. thanks!

public class ViewAllIncidents {

public Account acct{
get{
if(acct == null){
acct = [SELECT a.id, a.name
FROM Account a
WHERE id =: apexpages.currentpage().getParameters().get('id')];
}
return acct;
}
set;
}

public ViewAllIncidents() {

this.theIncidents = [SELECT c.Account.Name, c.CaseNumber, c.Status, c.due_date__c, c.subject, c.Contact.Email, c.description
FROM Case c
WHERE c.AccountId = :ApexPages.currentPage().getParameters().get('acctId')];

}
public List<Case> theIncidents { get; set; }

public PageReference cancel() {
//cancel method to return to the account detail page
return new ApexPages.StandardController(acct).view();
}
}

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
wesnoltewesnolte

Hey

 

Try this,

 

public String aId = apexpages.currentpage().getParameters().get('id'); 

 

 public PageReference cancel() {

//cancel method to return to the account detail page
return new PageReference('/'+aId);
}

 

The return new ApexPages.StandardController(acct).view(); call can only be used from within a standard controller extension.

 

Wes 

All Answers

wesnoltewesnolte

Hey

 

Try this,

 

public String aId = apexpages.currentpage().getParameters().get('id'); 

 

 public PageReference cancel() {

//cancel method to return to the account detail page
return new PageReference('/'+aId);
}

 

The return new ApexPages.StandardController(acct).view(); call can only be used from within a standard controller extension.

 

Wes 

This was selected as the best answer
MSVRadMSVRad

Thanks for the Response!

 

It was very helpful, I made a slight tweak and now it works exactly as it should.

 

Here is what I put in my controller:

 

 

public class ViewAllIncidents { public ViewAllIncidents() { this.theIncidents = [SELECT c.Account.Name, c.CaseNumber, c.Status, c.due_date__c, c.subject, c.Contact.Email, c.description, c.Contact.Phone, c.Contact.Name FROM Case c WHERE c.AccountId = :ApexPages.currentPage().getParameters().get('acctId')]; } public List<Case> theIncidents { get; set; } public string aId = apexpages.currentpage().getParameters().get('acctid'); public PageReference cancel() { //cancel method to return to the account detail page return new PageReference('/'+ aId); } }