You need to sign in to do that
Don't have an account?
msantana
How to pass data(Id, etc) from the Console Primary Object to controller. AKA Custom Console Component or Footer widget
This is my first time developing a Custom Console Component.
Situation: I created a VF page that got added to a Custom Console Component in order to open as a Footer widget in the console.
This is what I need to do: The VF page should do: When you open a Case in the Console as a Primary TAB and the field__c is empty then the VF page should display Case.field1__c(lookup) in order update the case field when a Save button is click, to then later find the data from a related Object and display this data within VF page with or without the previously rendered filed that we just updated.
If the mentionded field already has a value then it would display the data from a related Object.
The PROBLEM that I am having:
Not able to pass the CASE data from my currently open case in the Console as Primary tab to my custom Controller in order to find the data from a related Object.
My VF page:
My questions:
Situation: I created a VF page that got added to a Custom Console Component in order to open as a Footer widget in the console.
This is what I need to do: The VF page should do: When you open a Case in the Console as a Primary TAB and the field__c is empty then the VF page should display Case.field1__c(lookup) in order update the case field when a Save button is click, to then later find the data from a related Object and display this data within VF page with or without the previously rendered filed that we just updated.
If the mentionded field already has a value then it would display the data from a related Object.
The PROBLEM that I am having:
Not able to pass the CASE data from my currently open case in the Console as Primary tab to my custom Controller in order to find the data from a related Object.
My VF page:
<apex:page standardController="Case" extensions="CaseConsoleControllerExt2"> <apex:includeScript value="/support/console/42.0/integration.js"/> <script type="text/javascript"> //sforce.console.onCustomConsoleComponentButtonClicked(sforce.console.getFocusedPrimaryTabObjectId(response)); function testGetFocusedPrimaryTabObjectId() { sforce.console.getFocusedPrimaryTabObjectId(showObjectId); } var showObjectId = function showObjectId(result) { //Display the object ID alert('Object ID: ' + result.id); }; </script> <apex:pageMessages /><br/> <apex:form > <apex:pageBlock title="Edit Case" mode="edit"> <apex:pageBlockSection columns="1"> <apex:inputField value="{!Case.CaseNumber}"/> <!-- Not able to get data from the primary tab to display CaseNumber, ID, ETC --> <apex:repeat value="{!editableFields}" var="f"> <apex:inputField value="{!Case[f]}"/> </apex:repeat> </apex:pageBlockSection> <apex:pageBlockButtons> <apex:commandButton action="{!save}" value="Save"/> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> <A HREF="#" onClick="testGetFocusedPrimaryTabObjectId();return false"> Click here to get the focused primary tab object ID</A> </apex:page>My Custom controller:
public class CaseConsoleControllerExt2 { private final Case MyCase; public CaseConsoleControllerExt2(ApexPages.StandardController stdController) { //this.editCase = [Select Id, CaseNumber,SAP_Customer__c FROM Case Where Id = :ApexPages.currentPage().getParameters().get('id') ]; // this.MyCase = (Case)ApexPages.currentPage().getParameters().get('id'); this.MyCase = (Case)stdController.getRecord(); // ALWAYS NULL system.debug('My current Case is: '+MyCase); // ALWAYS NULL //stdController.addFields(editableFields); } public Case MyCase() { return MyCase; } public List<String> editableFields { get { if (editableFields == null) { editableFields = new List<String>(); editableFields.add('SAP_Customer__c'); } return editableFields ; } private set; } }
My questions:
- Why my controller in not getting the data from my current record in the primary tab when doing this.MyCase = (Case)stdController.getRecord();
- How can I pass data from VF page script (Case data) to the controller since the I am getting the case Id with the script sforce.console.getFocusedPrimaryTabObjectId
- Any problem with my controller?
In any case, I copy your code to my environment and had to modify it a bit because I couldn't even save it, it general I just made some minor changes and it worked.
In reference to your concerns about what's the best way to do it, well, it depends on your requirements in terms of security, accessibility, process flow, environment (Classic/Lightning Experience), etc.
I am adding a couple of screenshots to confirm with you, at least, a part of your requirements:
In the first screenshot, I selected a case and clicked on the bottom console button to open the popup screen. You can see the data of the case in the Primary Tab is displayed in the popup screen:
Then, I clicked on a second case. My code doesn't close the popup window but just refresh the data in it:
If that's what you want as behavior, this is the code:
-Visualforce Page -Controller:
I modified just a bit of your code, that way you can continue from there.
Hope that helps.
JL
All Answers
If you want to pass a parameter to your controller with the popup console you can use this code:
I tried to get something similar to your code,
This is the Visualforce page
This is the controller:
Let me know if that works for you.
JL
This is what it has been working for me so far: Controller:
Eventhoguht that I am able to get the case Id in the controller I am not sure if this is the best way to able to populate the information back of the case in the VF page. I thought I would need to use psgeReference to redirect the page to
In any case, I copy your code to my environment and had to modify it a bit because I couldn't even save it, it general I just made some minor changes and it worked.
In reference to your concerns about what's the best way to do it, well, it depends on your requirements in terms of security, accessibility, process flow, environment (Classic/Lightning Experience), etc.
I am adding a couple of screenshots to confirm with you, at least, a part of your requirements:
In the first screenshot, I selected a case and clicked on the bottom console button to open the popup screen. You can see the data of the case in the Primary Tab is displayed in the popup screen:
Then, I clicked on a second case. My code doesn't close the popup window but just refresh the data in it:
If that's what you want as behavior, this is the code:
-Visualforce Page -Controller:
I modified just a bit of your code, that way you can continue from there.
Hope that helps.
JL
Your concerns about the "best way" of doing this depend on different factors, ex. your environment (Classic / Lightning), your security needs, accessibility requirements, etc, this is because there are a couple of ways to get to your objective (if I understood it properly)
Look, I took your code and modified a bit to make it run and this is what I got:
-Selected an existing case and opened the bottom consoled widget. The case info is displayed in the window:
-Then, I selected another existing case and the information in the window changed accordingly. I didn't want the popup window to close automatically, it could be a bit annoying for the user, so I left it open.
If this is your intended behavior, this is the code for that. Again, I just took your code and modified it slightly.
Visualforce Page:
Controller: