You need to sign in to do that
Don't have an account?
fiona gentry
How To Upsert On Existing Lightning CMP
Current Behaviour of my Lightning component:- Lightning component is used on Case Type to create multi levels Level1 then Dependent Level2 then dependent Level3 selected and clicking in Save saves entire Record to Case,works fine till here on one of custom object Case Type
Expected behavior:- Now I want to extend the functionality of above lightning component so that user who wishes to change Record data on Case can just update the value of Level1, Level2 and Level3 and do an Upsert on the same case
Now to achieve Edit a record functionality,added lightning:actionOverride in apex cmp and then overridden the standard Edit button of ERT case type custom object with the Lightning component as below
Here comes the problem when I use the same component in Edit button
Then select levels
I see error as below
Now my question is what changes is needed in the below Apex controller or Lightning Component Bundle to successfully update the previously saved Level1, Level2, Level3 on the Case
Here is Apex controller
here is CMP file
Fiona
Expected behavior:- Now I want to extend the functionality of above lightning component so that user who wishes to change Record data on Case can just update the value of Level1, Level2 and Level3 and do an Upsert on the same case
Now to achieve Edit a record functionality,added lightning:actionOverride in apex cmp and then overridden the standard Edit button of ERT case type custom object with the Lightning component as below
Here comes the problem when I use the same component in Edit button
Then select levels
I see error as below
Now my question is what changes is needed in the below Apex controller or Lightning Component Bundle to successfully update the previously saved Level1, Level2, Level3 on the Case
Here is Apex controller
public class PickListHandler { @AuraEnabled public static List<String> getLevel1(){ List<String> tempLst1 = new List<String>(); for(AggregateResult ar : [select Level_1__c,COUNT(id) from Case_Type_Data__c group by Level_1__c]) { tempLst1.add(''+ar.get('Level_1__c')); } return tempLst1; } @AuraEnabled public static List<String> getLevel2(string strName){ List<String> tempLst2 = new List<String>(); for(AggregateResult ar : [select Level_2__c,COUNT(id) from Case_Type_Data__c where Level_1__c=:strName group by Level_2__c]) { tempLst2.add(''+ar.get('Level_2__c')); } return tempLst2; } @AuraEnabled public static List<String> getLevel3(string strName1,string strName2){ List<String> tempLst3 = new List<String>(); for(AggregateResult ar : [select Level_3__c,COUNT(id) from Case_Type_Data__c where Level_1__c=:strName1 and Level_2__c=:strName2 group by Level_3__c]) { tempLst3.add(''+ar.get('Level_3__c')); } return tempLst3; } @AuraEnabled public static String savecasetype(string level1,string level2,string level3,string id){ string strMsg='successfull'; try{ ERT_Case_Type__c obj=new ERT_Case_Type__c(); Obj.Case__c = id; System.debug('CASE = '+ Obj.Case__c); Obj.Level_1__c=level1; System.debug('Level1 = '+ Obj.Level_1__c); Obj.Level_2__c=level2; System.debug('Level2 = '+ Obj.Level_2__c); Obj.Level_3__c=level3; System.debug('Level3 = '+ Obj.Level_3__c); Insert obj; } catch(Exception ex){ strMsg='error'; } return strMsg; } }
here is CMP file
<aura:component controller="PickListHandler" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction,lightning:actionOverride" access="global" > <!-- Actions--> <aura:handler name="init" value="{!this}" action="{!c.doInit}" /> <aura:handler event="force:refreshView" action="{!c.isRefreshed}" /> <!-- variable--> <aura:attribute name="lstLevel1" type="String[]" /> <aura:attribute name="lstLevel2" type="String[]" /> <aura:attribute name="lstL3" type="String[]" /> <aura:attribute name="firstlevel1selected" type="String" default="" /> <aura:attribute name="secondlevelselected" type="String" default="" /> <aura:attribute name="thirdlevelselected" type="String" default="" /> <div class="slds-container--center slds-container--small slds-m-top--small"> <div class="slds-form--stacked"> <lightning:select name="parentPicklist" label="Level 1" aura:id="ddLevel1" onchange="{!c.getLvl1}"> <option value="">--- None ---</option> <aura:iteration items="{!v.lstLevel1}" var="item1"> <option value="{!item1.value}" selected="{!item1.selected}" >{!item1}</option> </aura:iteration> </lightning:select> <lightning:select name="Level2Picklist" label="Level 2" aura:id="ddLevel2" onchange="{!c.getSelectedValue}" > <option value="">--- None ---</option> <aura:iteration items="{!v.lstLevel2}" var="item2"> <option value="{!item2.value}" selected="{!item2.selected}" >{!item2}</option> </aura:iteration> </lightning:select> <lightning:select name="Level3Picklist" label="Level 3" aura:id="ddLevel3" onchange="{!c.getlevel3}" > <option value="">--- None ---</option> <aura:iteration items="{!v.lstL3}" var="item3"> <option value="{!item3.value}" selected="{!item3.selected}" >{!item3}</option> </aura:iteration> </lightning:select> </div> </div> <lightning:button variant="brand" label="Save" onclick="{!c.onConfirm}" /> </aura:component>Your help is highly appreciated
Fiona
Is there a detailed error message from logs on why the record has not been inserted successfully. Thanks