You need to sign in to do that
Don't have an account?
MilesS
need help saving a record & refresh the page
I'm trying to create a lwc that updates a field. I'm able to pull the record information in, however I can either save or refresh the record. Once the record is saved I'd like to go back to view mode. What am I missing? Thank you in advance!
Component
Controller
Component
<aura:component controller="apexCls_fiberPortalPageReferences" implements="forceCommunity:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:themeLayout,flexipage:availableForAllPageTypes,force:appHostable,force:lightningQuickAction" access="global"> <aura:attribute name="recordId" type="string"/> <aura:attribute name="su" type="Site_Survey__c"/> <aura:attribute name="updateAction" type="String" default="UNSAVED" /> <aura:handler name="init" value="{!this}" action="{!c.doInitAction}" /> <br/>Update Action: {!v.updateAction}<br/><br/> <aura:if isTrue="{!v.updateAction=='UNSAVED'}"> <lightning:recordEditForm recordId="{!v.recordId}" objectApiName="Site_Survey__c"> <lightning:messages /> <lightning:outputField fieldName="Question__c" /> <lightning:inputField fieldName="Completed_Detail__c" /> <lightning:button class="button" type="submit" label="Save" onclick="{!c.save}" /> </lightning:recordEditForm> <aura:set attribute="else"> Question: {!v.su.Question__c}<br/> Completed Detail: {!v.su.Completed_Detail__c}<br/><br/> <lightning:button class="button" label="Edit" onclick="{!c.handleClick2}"/> </aura:set> </aura:if> </aura:component>
Controller
({ doInitAction : function(component, event, helper) { var action = component.get("c.SiteSurvey_Detail"); action.setParams({ "SiteSurveyRecordId": component.get("v.recordId") }); action.setCallback( this, function(response) { var state = response.getState(); if (state === "SUCCESS") { component.set("v.su", response.getReturnValue()); console.log(response.getReturnValue()); } }); $A.enqueueAction(action); }, print : function(component, event, helper) { window.print(); }, save : function(cmp,event,helper) { cmp.find("edit").get("e.recordSave").fire(); cmp.set("v.updateAction", "SAVED"); }, handleClick2 : function(cmp, event) { var attributeValue = cmp.get("v.updateAction"); console.log("current text: " + attributeValue); var target = event.getSource(); cmp.set("v.updateAction", "UNSAVED"); } })
Do you want to go detail page of the record you saved, then kindly use the concept of pageReference in the Apex controller.
Here is the sample code :- Kinldy mark it as a best answer if it helps.
Thanks!