You need to sign in to do that
Don't have an account?
Cloud Elite
build lightning component to accept cases
Hello All,
I tried to build a lightning component to have a button that when clicked, the case is accepted to the user who cliced it, mainly a case that was assigned to a queue.
here is the code i have so far but need your help in what is missing, when i try to save the controller, i get an error. can you please review and correct ?
I tried to build a lightning component to have a button that when clicked, the case is accepted to the user who cliced it, mainly a case that was assigned to a queue.
here is the code i have so far but need your help in what is missing, when i try to save the controller, i get an error. can you please review and correct ?
component ========== <aura:component implements="force:hasRecordId,force:lightningQuickActionWithoutHeader"> <aura:attribute name="record" type="Case" default="{ 'sobjectType': 'Case' }" /> <aura:attribute name="complete" type="Boolean" default="false" /> <force:recordData recordId="{!v.recordId}" fields="['CaseNumber','OwnerId','OwnerFullName']" targetFields="{!v.record}" aura:id="recordData" recordUpdated="{!c.recordLoaded}" /> </aura:component> ==== controller ======= ({ recordLoaded: function(component, event, helper) { var caseRecord = component.get("v.record"), recordData = component.find("recordData"); caseRecord.OwnerId = component.get("$SObjectType.CurrentUser.Id"); if(!component.get("v.complete")) { // Avoid infinite loop component.set("v.complete", true); component.set("v.record", caseRecord); recordData.saveRecord($A.getCallback(function(result) { if(result.state === "SUCCESS" || result.state === "DRAFT") { $A.get("e.force:closeQuickAction").fire(); $A.get("e.force:refreshView").fire(); } else { /* show an error here */ } })); } })
You can get more details when there is an error with the console.log by testing all the states.
By giving the exact error: console.log('Problem saving record, error: ' + JSON.stringify(saveResult.error)); that may help in understanding the problem.
You are just using result instead of saveResult (but that is not important).
Get the Current User’s ID: https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.get_current_user
... but that is not Aura anymore but the replacing framework of Aura called Lightning Web Components
and it needs Salesforce DX: https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.install_setup_develop
You can try; https://success.salesforce.com/ideaView?id=0873A000000E7lFQAS
Undocumented workaround: JS Controller: $A.get('$SObjectType.CurrentUser.Id');
A complete solution by reading the user with an Apex class:
http://sfdcmonkey.com/2018/01/08/display-current-user-information/
They also talked about the undocumented workaround but that doesn't work anymore since the version 43.
For a so basic need, the Apex controller could be the only remaining technique (outside the LWC and the complete rewriting of your code + DX).