1

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.

  • I made a lot of changes but the above is the working code - i wonder if there is inefficiency in this part - ActID = [select id from Account where Id=: (ApexPages.currentPage().getParameters().get('AccountId'))]; objCase = new Case(); objCase.AccountID=ActID.id; – jaw999 Feb 29 '16 at 20:14
2
/apex/CaseCreateCTM1?AccountId={!Account.id}

Pass Id in url and get id in controller and assign to Case AccountId

Controller

public class CaseCreateCTM1Controller
{
   public Case objCase   {get;set;}
   public CaseCreateCTM1Controller()
   {
       objCase = new Case();
       objCase.AccountId = ApexPages.currentPage().getParameters().get('AccountId')
   }
}

And in your vf page

<apex:inputField value="{!objCase.AccountId}"> 

You can use {!$CurrentPage.parameters.AccountId} since this is lookup field you need to use <apex:inputField>

--

Updates

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();

    //grab AccounId and assign to CaseTeamMember.
    CTM.AccounId = ApexPages.currentPage().getParameters().get('AccountId');


    //create a new list to store the sprints added by the user
    CTMS = new List<CaseTeamMember>();

}    

AND VF page

<apex:inputField value="{!CTM.AccountId}"> 
  • I already have a controller extension – jaw999 Feb 25 '16 at 18:23
  • @jaw999 are you looking for something else.. I dn't think you will find another except this.. – Ratan Paul Feb 26 '16 at 2:47
  • I am having trouble getting this to push. I will add my code to the question – jaw999 Feb 29 '16 at 16:03
  • getting the CTM.AccounId = ApexPages.currentPage().getParameters().get('AccountId'); to compile an issue. – jaw999 Feb 29 '16 at 18:10
  • @jaw999 what issue you are getting? – Ratan Paul Feb 29 '16 at 18:12
0

Use

/apex/CaseCreateCTM1?def_account_id={!Account.id}

0

You can also pass parameter to your VF page in URL, then read this parameter in your controller and populate Account field based on that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.