This is my first subject since I'm very new to Salesforce. My problem is that I'm trying to create simple Lightning component which could clone record with custom logic. This component suppose to be available through Lightning Quick Action on the record page. I'm trying to use force:recordData to retrieve original record from database, then change some of the fields values according to my needs, and then fill the form inside my component, so the user either can just clone it as it is or change some details and save the record as new one. But while calling my Apex controller from the component, I'm getting very strange error with this message:
Unfortunately, there was a problem. Please try again. If the problem continues, get in touch with your administrator with the error ID shown here and any other related details. Action failed: forceChatter:lightningComponent$controller$doInit [Error while creating content for lightning component quick action] quickActionHandlerHelper.js failed to create component - forceChatter:lightningComponent
Please take a look at my code, maybe I do not see something what is really simple...
PS. I'm aware of not completed code f.e. lack of save and cancel methods and maybe something more. But if the component cannot even start itself, I believe we can skip the rest of the code for now :)
Lightning Component:
<aura:component description="TargetRealizationReplicator" implements="force:hasRecordId,force:lightningQuickAction " access="global" controller="TargetRealizationCloneController" >
<aura:attribute name="Record" type="Target_Realization__c" />
<aura:attribute name="SimpleRecord" type="Target_Realization__c" />
<aura:attribute name="recordError" type="String"/>
<force:recordData aura:id="RecordReplicator"
layoutType="FULL"
targetFields="{!v.SimpleRecord}"
targetRecord="{!v.Record}"
targetError="{!v.recordError}"
fields="Start_Date__c, End_Date__c, Target__c, Value__c, Value_Distribution_Type__c"
recordUpdated="{!c.recordUpdated}"
mode="EDIT"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<div aura:id="editDialog" role="dialog" tabindex="-1" aria-labelledby="header43" class="slds-modal slds-fade-in-open">
<div class="slds-modal__container">
<div class="slds-modal__header">
<h2 class="slds-text-heading--medium">Clone Target Realization Record</h2>
</div>
<div class="slds-modal__content slds-p-around--medium slds-grid slds-wrap ">
<ui:inputDate aura:id="StartDate" label="Start Date" value="{!v.SimpleRecord.Start_Date__c}" displayDatePicker="true"/>
<ui:inputDate aura:id="EndDate" label="End Date" value="{!v.SimpleRecord.End_Date__c}" displayDatePicker="true"/>
<lightning:select aura:id="Value_Distribution_Type__c" name="Value_Distribution_Type__c" value="{!v.SimpleRecord.Value_Distribution_Type__c}" required="true" label="Target Type" class="slds-size--1-of-2 slds-p-horizontal_x-small">
<option>Select Distribution Type</option>
<option value="Individual" >Individual</option>
<option value="Group">Group</option>
</lightning:select>
</div>
<div class="slds-modal__footer">
<lightning:button variant="neutral" label="Cancel" onclick="{!c.cancelDialog}"/>
<lightning:button variant="brand" label="Submit" onclick="{!c.saveRecord}"/>
</div>
</div>
</div>
</aura:component>
Component Controller:
({
doInit : function(component, event, helper){
var action = component.get("c.getCurrentRecordValues");
action.setParam({"recordId": component.get("v.recordId")});
action.setCallback(this, function(response) {
var result = response.getReturnValue();
component.set("v.SimpleRecord", result);
console.log(result);
})
$A.enqueueAction(action);
},
})
Apex Controller:
public with sharing class TargetRealizationCloneController {
@AuraEnabled
public static Target_Realization__c getCurrentRecordValues(String recordId){
Target_Realization__c record = [SELECT Start_Date__c, End_Date__c, Value_Distribution_Type__c, Value__c, Target__c FROM Target_Realization__c WHERE Id = :recordId LIMIT 1];
return record;
}
EDIT:
After adding this to my Init method, I have finally got the object loaded properly with all the fields I need:
doInit : function(component, event, helper){
// Prepare a new record from template
component.find("RecordReplicatorLoad").getNewRecord(
"Target_Realization__c", // sObject type (entityAPIName)
null, // recordTypeId
false, // skip cache?
$A.getCallback(function() {
var rec = component.get("v.RecordLoad");
var error = component.get("v.recordError");
if(error || (rec === null)) {
console.log("Error initializing record template: " + error);
}
else {
console.log("Record template initialized: " + rec.sobjectType);
}
})
);
},
QueryException
from yourLIMIT 1
hiding behind the error from the Chatter component. Can you validate that that query returns an object for the running user?