I have custom visualforce page to create a new case and I'd like to have a New Case button on the Acocunt page in the Cases list. Can I hack the url to push the Account Id into the Account field? If my list button is URL:
/apex/CaseCreateCTM1
Can I hack it with something like:
/apex/CaseCreateCTM1?Account={!Account.id}
Or do I need to add something else? thanks Also, there are other things I am doing with this page - pushing users to a second page to add case team members. thanks!
Case controller class:
public class CasewithCaseTeamExtension {
private ApexPages.StandardController sc;
public CaseTeamMember CTM {get; set;}
public List<CaseTeamMember> CTMS {get; set;}
public Account ActID {get; set;}
public String selectedCaseTeamMember {get; set;}
public User ProxyUser {get; set;}
public string Username {
get {
return [
select Name
from User
where Id = :Userinfo.getUserId()
].Name;
}
set;
}
public String userProfileName1 {
get {
return [
select Profile.Name
from User
where Id = :Userinfo.getUserId()
].Profile.Name;
}
}
public PageReference Init()
{
String userProfileName = [ select Profile.Name
from User
where Id = :Userinfo.getUserId()
].Profile.Name;
if (userProfileName.contains('B') )
{
PageReference redirecturl = new PageReference('/recordtypeselect.jsp?ent=Case&retURL=%2F500%2Fo&save_new_url=%2F500%2Fe%3FretURL%3D%252F500%252Fo');
return redirecturl;
}
// Stay on the page
return null;
}
public CasewithCaseTeamExtension (ApexPages.StandardController StandardController) {
//Store a reference to the standard controller
sc = standardController;
//create a new sprint instance to collect user input
CTM = new CaseTeamMember();
//create a new list to store the sprints added by the user
CTMS = new List<CaseTeamMember>();
ActID = [select id from Account where Id=: (ApexPages.currentPage().getParameters().get('AccountId'))];
objCase = new Case();
objCase.AccountID=ActID.id;
}
public PageReference ToPage2() {
if(ApexPages.CurrentPage().GetURL().ToLowerCase().StartsWith('/apex/CaseCreateCTM1')){
//Save code
}
sc.save();
return Page.CaseCreateCTM2;
}
public PageReference SaveCTM() {
Case Case1 = (Case)sc.GetRecord();
CaseTeamRole CTRole = [select id from CaseTeamRole where name =:'Sales'];
CTM.ParentId = Case1.Id;
CTM.TeamRoleId = CTRole.Id;
insert CTM;
CTMS.Add(CTM);
CTM = new CaseTeamMember();
return null;
}
public PageReference SaveAndFinish() {
Case Case1 = (Case)sc.GetRecord();
CaseTeamRole CTRole = [select id from CaseTeamRole where name =:'Sales'];
CTM.ParentId = Case1.Id;
CTM.TeamRoleId = CTRole.Id;
CTMS.Add(CTM);
CTM = new CaseTeamMember();
PageReference redirecturl = new PageReference('/'+Case1.id);
return redirecturl;
}
public PageReference FinishEntry() {
Case Case1 = (Case)sc.GetRecord();
PageReference redirecturl = new PageReference('/'+Case1.id);
return redirecturl;
}
}
Page:
<apex:page standardController="Case" extensions="CasewithCaseTeamExtension" action="{!Init}" >
{!userProfileName1}
<apex:form >
<apex:pageBlock title="New Case" >
<apex:pageBlockButtons location="bottom">
<apex:commandButton action="{!ToPage2}" value="Continue" />
</apex:pageBlockButtons>
<apex:pageBlockSection columns="2" title="Case Details">
<b> Case Owner:{!$User.FirstName} {!$User.LastName}</b>
<apex:inputField value="{!ObjCase.AccountId}" />
<apex:inputField value="{!Case.Origin}" />
<apex:inputField value="{!Case.ContactId}" />
</apex:page>
Page truncated for ease.