1

I am comng across an error that I am unsure how to solve. I am using force:recordData to update a field.

Component

<aura:attribute name="record" type="Object" />
<aura:attribute name="simpleRecord" type="Opportunity" />
<aura:attribute name="recordError" type="String" />
<aura:attribute name="fieldsToQuery" type="String" />

<force:recordData aura:id="recordEditor"
layoutType="FULL"
fields="{!v.fieldsToQuery}"                  
recordId="{!v.recordId}"
targetError="{!v.recordError}"
targetRecord="{!v.record}"
targetFields ="{!v.simpleRecord}"
mode="EDIT" 
/>

Js Controller: (where field1 is a checkbox field)

({
doInit : function(component, event, helper) {

        component.set("v.simpleRecord.Initiate_Scoring__c", true);
                    component.find("recordEditor").saveRecord($A.getCallback(function(saveResult) {
                    if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
                        alert("Save completed successfully.");
                    } else if (saveResult.state === "INCOMPLETE") {
                        alert("User is offline, device doesn't support drafts.");
                    } else if (saveResult.state === "ERROR") {
                        alert('Problem saving record, error: ' + 
                                   JSON.stringify(saveResult.error));
                    } else {
                       alert('Unknown problem, state: ' + saveResult.state + ', error: ' + JSON.stringify(saveResult.error));
                    }
                }));       
},

 onRender: function(component, event, helper) {      

    $A.get("e.force:closeQuickAction").fire();
},      

})

However it is coming up with the following message:

[Error while creating content for lightning component quick action]
quickActionHandlerHelper.js failed to create component - 
forceChatter:lightningComponent

Updated Question with the new error message.

Any Suggestions?

1
  • @M guy- If you have a different error, after update made as per suggested answer, please either use comments or post a new question.
    – Mahmood
    Commented Mar 26, 2018 at 13:50

1 Answer 1

5

You're updating Boolean field with text

component.set("v.simpleRecord.field1", "true");

It should be like this:

 component.set("v.simpleRecord.field1", true);
1
  • 1
    Also you shouldn't set an attribute's field in this way - you should do like that: var simpleRecord = component.get("v.simpleRecord"); then change the field simpleRecord.field1 = true; then set the attribute back component.set("v.simpleRecord", simpleRecord); Commented Mar 27, 2018 at 8:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .