function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Joe StolzJoe Stolz 

Most likely a simple question: How to pass a static value to a field?

Hello,

I am just learning Visualforce and am finding all sorts of uses for it in my Org. I was given a request for a simple way for internal users to submit cases to a queue. This led me to create a quick Visualfoce page, which works, except for assigning the case to a queue. Could someone help me with how to assign a case completed on this VF page to a specific queue?
 
<apex:page standardController="Case" showHeader="true" sidebar="true">
<apex:form id="theForm">
  <apex:pageBlock title="Submit your CP support requests below" id="casePageBlock" mode="edit">
    <apex:pageMessages />
    <apex:pageBlockButtons location="bottom">
      <apex:commandButton value="Save" action="{!save}" id="theButton"/>
      <apex:commandButton value="Cancel" action="{!cancel}"/>
    </apex:pageBlockButtons>
    <apex:actionRegion >
      <apex:pageBlockSection id="masterPageBlock" title="Master" showHeader="false">
        <apex:inputField id="casTyp" value="{!Case.Type_of_Request__c}"/>
        <apex:inputField id="casOwn" label="Owner" value="{!case.OwnerId}" rendered="false"/>
      </apex:pageBlockSection>
      <apex:pageBlockSection id="thePageBlock" title="The Fields" showHeader="false" columns="2">
        <apex:inputField id="casAcc" label="CP's Account Name" required="true" value="{!case.AccountId}"/>
        <apex:inputField id="casCon" label="Who is your contact?" value="{!case.ContactId}"/>
        <apex:inputField id="casOpp" label="What opportunity is this related to?"  value="{!case.Related_Opportunity__c}"/>
        <apex:inputField id="casPri" label="What is the priority of this request" required="true" value="{!case.Priority}"/>
        <apex:inputField id="casDes" label="Please describe what you would like done" required="true" value="{!case.Description}"/>
      </apex:pageBlockSection>
    </apex:actionRegion>
  </apex:pageBlock>
</apex:form>
</apex:page>

The queue Id is 00Gi00000043ioY.

Thank you,
Joe Stolz
Best Answer chosen by Joe Stolz
Terence_ChiuTerence_Chiu
I am not aware of any way of defaulting the value with just visualforce. You can if you take a custom controller or extension route and default the field. Not sure how comfortable you are with Apex coding, but here is an example of how you could implement defaulting the owner to the queue.

public class CustomCaseController{
    Case c {get; set;}  //custom case variable to be used for vf page

    //controller method for controller class to default the case ownerid to the queue.
    public CustomCaseController(){
        c = new Case();
        c.OwnerId = '00Gi00000043ioY';
    }
}

From your VF page, you would replace all inputfield value attributes with the custom controller's case variable instead of using the standard controller. For instance,

<apex:inputField id="casOwn" label="Owner" value="{!c.OwnerId}" rendered="false"/>


Another non-code workaround could be handling the owner assignment after the case has been created. So you can create a workflow rule or Process Builder flow that will re-assign the owner owner of the case at creation. You can probably also look into assignment rules as well.
 

All Answers

Prosenjit Sarkar 7Prosenjit Sarkar 7
Hi Joe,
This link can help you about assigning queues,
http://prosenjit-sarkar-sfdc.blogspot.in/2015/07/assigning-supported-object-users-to.html (http://prosenjit-sarkar-sfdc.blogspot.in/2015/07/assigning-supported-object-users-to.html" target="_blank)
Joe StolzJoe Stolz
Thank you for the response, but I am trying to do this all within the Visualforce page. The queue is already setup and working correctly. What I am trying to do is make any cases created in the above VF page assign automatically to the queue instead of being assigned to the user who creates the record.
Prosenjit Sarkar 7Prosenjit Sarkar 7
Do you wish to hard code the queue Id ?
Joe StolzJoe Stolz
Yes, I do want to hard code the queue Id.
Terence_ChiuTerence_Chiu
Joe, have you ever considered using a global action for case creation instead ? Users can access it from the Home tab and you can customize the layout and also default certain values. I do not believe you can default case owner to a specific queue, but you can let's say create a custom text field that you default to your queue name. You can then have a workflow rule or process builder flow execute an action to update the case owner to the queue at case creation based on that custom field. 
Joe StolzJoe Stolz
Hello Terence,

No, my requirements are for more of a custom solution than what global actions would allow.
Terence_ChiuTerence_Chiu
I am not aware of any way of defaulting the value with just visualforce. You can if you take a custom controller or extension route and default the field. Not sure how comfortable you are with Apex coding, but here is an example of how you could implement defaulting the owner to the queue.

public class CustomCaseController{
    Case c {get; set;}  //custom case variable to be used for vf page

    //controller method for controller class to default the case ownerid to the queue.
    public CustomCaseController(){
        c = new Case();
        c.OwnerId = '00Gi00000043ioY';
    }
}

From your VF page, you would replace all inputfield value attributes with the custom controller's case variable instead of using the standard controller. For instance,

<apex:inputField id="casOwn" label="Owner" value="{!c.OwnerId}" rendered="false"/>


Another non-code workaround could be handling the owner assignment after the case has been created. So you can create a workflow rule or Process Builder flow that will re-assign the owner owner of the case at creation. You can probably also look into assignment rules as well.
 
This was selected as the best answer
Prosenjit Sarkar 7Prosenjit Sarkar 7
@Joe, I agree with Terence_Chiu_TCCloudDev regaring work flow option. I think that is closer to the requirement of Joe.
Joe StolzJoe Stolz
Thank you both for the help. I was afraid that the answer would be only through Apex which I still need to learn. The issue with the non-code workaround (Workflows / Process Builder) is other users will be creating cases in another way and those cases need to be assigned differently.