You need to sign in to do that
Don't have an account?
Soham SFDC
Visualforce Page Button on a Case Detail Record in Lightning Experience
Hi,
My requirement is like this: I had a Javascript button which used to Update the Status field and a Custom field in Case Record. Now, the Javascript button needs to be changed since it is not supported in Lightning. My approach is to create a Visualforce page which calls a Lightning component. But, now I am facing 2 problems:
- After the record has been saved, the Case record page does not get refreshed.
- The Modal popup window which asks for a Confirmation before saving the record is not getting closed. My code is like this:
VF Page:
<apex:page showHeader="false" standardController="Case" standardStylesheets="false" sidebar="false"> <script src="/soap/ajax/38.0/connection.js" type="text/javascript"/> <script src="/soap/ajax/38.0/apex.js" type="text/javascript"/> <!-- Load Lightning dependencies --> <apex:includeLightning /> <div class="slds"> <!-- Target div for the Lightning component --> <div id="RequestEscalationManagement"></div> </div> <script type="text/javascript"> var recordId = '{!Case.Id}'; var myUserContext = "{!$User.UITheme}"; $Lightning.use("c:REM", function() { var attributes = { recordId: recordId }; var targetElementId = 'RequestEscalationManagement'; $Lightning.createComponent('c:RequestEscalationManagement', attributes,targetElementId, function(cmp) { /*if (sforce.one != undefined) { // Lightning console.log('Lightning component'); sforce.one.navigateToSObject(recordId); } else { // Classic window.parent.location = '/' + recordId; }*/ console.log('Finished'); }); }); </script> </apex:page>
RequestEscalationManagement.cmp:
<aura:component controller="REMApexController" implements="force:lightningQuickAction,force:hasRecordId,flexipage:availableForRecordHome,flexipage:availableForAllPageTypes"> <aura:attribute name="recordId" type="Id" /> <aura:attribute name="hasErrors" type="Boolean" /> <!-- <aura:handler name="init" value="{!this}" action="{!c.doInit}" /> --> <aura:if isTrue="{!v.hasErrors}"> <div class="recordSaveError"> <ui:message title="Error" severity="error" closable="true" > An error was encountered trying to save the record </ui:message> </div> </aura:if> <div class="demo-only" style="height: 100%;"> <section class="slds-modal slds-fade-in-open"> <div class="slds-modal__container"> <header class="slds-modal__header"> <button class="slds-button slds-modal__close" title="Close" onclick="{!c.closeMe}"> <lightning:icon class="white slds-icon_small" iconName="utility:close"/> <span class="slds-assistive-text">Close</span> </button> <h2 id="modal-heading-01" class="slds-text-heading_medium slds-hyphenate"> Confirm</h2> </header> <div class="slds-modal__content slds-p-around_medium" > Please confirm if this needs to be escalated. </div> <footer class="slds-modal__footer"> <button class="slds-button slds-button_brand" onclick="{!c.doInit}">Ok</button> <button class="slds-button slds-button_brand" onclick="{!c.closeMe}">Cancel</button> </footer> </div> </section> <div class="slds-backdrop slds-backdrop_open"></div> </div> </aura:component>RequestEscalationManagementController.js:
({ doInit: function(component, event, helper) { var action = component.get("c.saveRecordCtrl"); action.setParams({ "caseRecordId": component.get("v.recordId") }); action.setCallback(this, function(response) { var state = response.getState(); var caseId = component.get("v.recordId"); if(component.isValid() && state == "SUCCESS"){ console.log('Success'); if (sforce.one != undefined) { // Lightning component.destroy(); sforce.one.navigateToSObject(caseId); } else { // Classic window.parent.location = '/' + caseId; } } else { console.log('Error trying to save Case Record'); } }); $A.enqueueAction(action); }, closeMe : function(component, event, helper) { var caseId = component.get("v.recordId"); console.log('caseId: ' + caseId); if (sforce.one != undefined) { // Lightning console.log('Lightning component'); sforce.one.navigateToSObject(caseId); } else { // Classic window.parent.location = '/' + caseId; } helper.closeMe(component, event, helper); } })RequestEscalationManagementHelper.js
({ closeMe : function(comp, event, helper) { comp.destroy(); } })After clicking on OK button, the cursor goes back to the 1396 record but, it does not refresh the page. Also, the current window highlighted in Red box does not get closed.
And the Server Side Controller Code is like this:
REMApexController.cls
Please can someone help me in this regard.
Regards,
Soham