0

Am writing lightning component on quote object for Billing Address using LDS.

API Name(standard field) - BillingAddress

I have an ui:inputSelect for BillingCountry and trying to save like below,

var record = component.get("v.simpleRecord");
record.BillingCountry = 'India'; //whatever the selected value in ui:inputSelect
var quoteRecordCreator = component.find("recordEditor");
quoteRecordCreator.saveRecord($A.getCallback(function(saveResult) {

}

when am clicking on save button, getting below error

Uncaught Action failed: c:QuoteAirEditPage$controller$handleSaveRecord [Cannot add property BillingCountry, object is not extensible]

BillingAddress field has access to all the profiles and it is editable too in field accessibility.

UPDATE:

Component:

<aura:attribute name="simpleRecord" type="Quote" default="{'sobjectType': 'Quote'}" /> 
<force:recordData aura:id="recordEditor"
                              layoutType="FULL"                              
                              recordId="{!v.QuoteRecId}"
                              targetError="{!v.recordError}"
                              targetRecord="{!v.record}"
                              targetFields="{!v.simpleRecord}"
                              recordUpdated="{!c.handleRecordUpdated}"
                              mode="EDIT" />  
    <ui:inputSelect aura:id="conCountry" class="slds-select" change="{!c.onCountryFieldChange}" />

Note: Populating the country values in doInit function.

Tried saving with controller:

  1. component.set("v.simpleRecord.BillingCountry", "India"); //Not throwing any error but value India is not saving in the field.

  2. var record = component.get("v.simpleRecord");

    record.BillingCountry = 'India'; //Throwing same above error

UPDATE:

It is throwing error only for BillingCountry and BillingState. The BillingStreet, BillingPostalCode and BillingCity fields are saving without any error. Is this salesforce issue?

3
  • Can you Please add console.log to record and show me the answer. I dont think "Billing Country " is in the record
    – Annappa
    Aug 20, 2018 at 11:21
  • have updated the component and controller in the question. Aug 20, 2018 at 12:30
  • Are you using State and Country Picklists? You'll need to use the picklist values, not the labels, if that's the case.
    – David Reed
    Aug 20, 2018 at 13:23

1 Answer 1

0
<aura:attribute name="simpleNewquote" type="Object"/>    

 component.set("v.simpleNewquote.BillingCountry", "India");
    var quoteRecordCreator = component.find("recordEditor");
    quoteRecordCreator.saveRecord($A.getCallback(function(saveResult) {

    }

try this, you will be able to set the values. So your answer will be Address fields are not restricted to save in LDS.

Actually, you were not setting the values properly.Hope it helps you.

Update:-

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >

<aura:attribute name="newquote" type="Object"/>
 <aura:attribute name="simpleRecordQuote" type="Quote" />
<aura:attribute name="newquoteError" type="String"/> 
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

<force:recordData aura:id="quoteRecordCreator"
                  layoutType="FULL" 
                  targetRecord="{!v.newquote}"
                  targetFields="{!v.simpleRecordQuote}"
                  targetError="{!v.newquoteError}" />

<aura:if isTrue="{!not(empty(v.newquoteError))}">
    <div class="recordError">
        <ui:message title="Error" severity="error" closable="true">
            {!v.newquoteError}
        </ui:message></div>
</aura:if>

 <!-- Display the new Quote form -->
<div class="slds-form_stacked">

    <lightning:button label="Save quote" onclick="{!c.handleSaveContact}"
                      variant="brand" class="slds-m-top_medium"/></div>

Controller:-

({
    doInit: function(component, event, helper) {
        // Prepare a new record from template
        component.find("quoteRecordCreator").getNewRecord(
            "Quote", // sObject type (objectApiName)
            null, // recordTypeId
            false, // skip cache?
            $A.getCallback(function() {
                var rec = component.get("v.newquote");
                var error = component.get("v.newquoteError");
                if(error || (rec === null)) {
                    console.log("Error initializing record template: " + error);
                    return;
                }
                console.log("Record template initialized: " + rec.sobjectType);
            })
        );
    },
    handleSaveContact: function(component, event, helper) {
        component.set("v.simpleRecordQuote.OpportunityId", component.get("v.recordId"));
        component.set("v.simpleRecordQuote.BillingCountry", "India");
        component.set("v.simpleRecordQuote.Name", "Sanket lds");
        component.find("quoteRecordCreator").saveRecord(function(saveResult) {
            if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
                // record is saved successfully
                var resultsToast = $A.get("e.force:showToast");
                resultsToast.setParams({
                    "title": "Saved",
                    "message": "The record was saved."
                });
                resultsToast.fire();                
            } else if (saveResult.state === "INCOMPLETE") {
                // handle the incomplete state
                console.log("User is offline, device doesn't support drafts.");
            } else if (saveResult.state === "ERROR") {
                // handle the error state
                console.log('Problem saving contact, error: ' +
                            JSON.stringify(saveResult.error));
            } else {
                console.log('Unknown problem, state: ' + saveResult.state + ', error: ' + JSON.stringify(saveResult.error));
            }
        });
    }
})

I have given a component which have a button to create quote,you need to add this component to Oportunity layout and onclick it will fetch the opportunity id and create quote related to it. I am setting BillingCountry successfully.

Hope it helps you.

Update:-

For update you can try like this:-

<aura:component implements="flexipage:availableForRecordHome,force:appHostable,force:hasRecordId">

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

<force:recordData aura:id="recordHandler"
  recordId="{!v.recordId}"
  layoutType="FULL"
  targetRecord="{!v.record}"
  targetFields="{!v.simpleRecord}"
  targetError="{!v.recordError}"
  mode="EDIT"
  recordUpdated="{!c.handleRecordUpdated}"
  />

<!-- Display a lightning card with details about the record -->
<div class="Record Details"> 
    <lightning:card iconName="standard:quote" title="{!v.simpleRecord.Name}" >
        <div class="slds-p-horizontal--small">
            <p class="slds-text-heading--small">
                <lightning:formattedText title="Billing State" value="{!v.simpleRecord.BillingState}" /></p>
            <p class="slds-text-heading--small">
                <lightning:formattedText title="Billing City" value="{!v.simpleRecord.BillingCity}" /></p>
        </div>
    </lightning:card>
</div>

<!-- Display an editing form -->
<div class="Record Details">
    <lightning:card iconName="action:edit" title="Edit Quote">
        <div class="slds-p-horizontal--small">
           <lightning:input label="quote Name" value="{!v.simpleRecord.Name}"/>
           <br/>
           <lightning:button label="Save quote" variant="brand" onclick="{!c.handleSaveRecord}" />
        </div>
    </lightning:card>
</div>

<!-- Display Lightning Data Service errors, if any -->
<aura:if isTrue="{!not(empty(v.recordError))}">
    <div class="recordError">
        {!v.recordError}</div>
</aura:if>

Controller:-

({
handleSaveRecord: function(component, event, helper) {
    component.find("recordHandler").saveRecord($A.getCallback(function(saveResult) {
        // NOTE: If you want a specific behavior(an action or UI behavior) when this action is successful 
        // then handle that in a callback (generic logic when record is changed should be handled in recordUpdated event handler)
        if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
            // handle component related logic in event handler
        } else if (saveResult.state === "INCOMPLETE") {
            console.log("User is offline, device doesn't support drafts.");
        } else if (saveResult.state === "ERROR") {
            console.log('Problem saving record, error: ' + JSON.stringify(saveResult.error));
        } else {
            console.log('Unknown problem, state: ' + saveResult.state + ', error: ' + JSON.stringify(saveResult.error));
        }
    }));
},

/**
 * Control the component behavior here when record is changed (via any component)
 */

    handleRecordUpdated: function(component, event, helper) {
//here i am setting the field
        component.set("v.simpleRecord.BillingCountry", "India");
        var eventParams = event.getParams();
        if(eventParams.changeType === "CHANGED") {
            // get the fields that changed for this record
            var changedFields = eventParams.changedFields;
            console.log('Fields that are changed: ' + JSON.stringify(changedFields));
            // record is changed, so refresh the component (or other component logic)
            var resultsToast = $A.get("e.force:showToast");
            resultsToast.setParams({
                "title": "Saved",
                "message": "The record was updated."
            });
            resultsToast.fire();

        } else if(eventParams.changeType === "LOADED") {
            // record is loaded in the cache
        } else if(eventParams.changeType === "REMOVED") {
            // record is deleted and removed from the cache
        } else if(eventParams.changeType === "ERROR") {
            // there’s an error while loading, saving or deleting the record
        }
    }

    })

The billingcountry is set similarly in edit mode as creating record.Add this component to quote record home page. here i have added one field on layout, whenever you click the save button, Billing country will get updated to India as i have it default value. Hope it helps you. Mark it as your answer.

5
  • Nope. It is not throwing any error but the value is not saving in the field. Aug 20, 2018 at 12:25
  • Thanks sanket, have updated the component and controller in the question. Aug 20, 2018 at 12:30
  • I have updated my answer. Please have a look Aug 20, 2018 at 13:30
  • Thanks sanket kumar. Am also able to save the value with the provided component. But if we remove the logic in doInit function which is to create empty template, it is not working. Since my component is only for edit, it should bring the old values. Aug 20, 2018 at 15:26
  • @mohammedazarudeen I have updated my answer for edit mode. Nothing is changed, again setting the values as doing earlier. Hope it helps you. Mark it as your answer. Aug 20, 2018 at 16:30

You must log in to answer this question.

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