2

I am using LDS to load the Account record. i want to add new comments with new line to existing comments for my textarea(long) field in Account record. i used \n and `\r\n' none of them are working for me . new comment added end of existing comments. is there working work around. cmp

<aura:component controller="SeTesting" implements="force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId,flexipage:availableForRecordHome,forceCommunity:availableForAllPageTypes" 
        access="global" >
<aura:attribute name="addingcomments" type="String"/>
 <aura:attribute name="record" type="Object"/>
<aura:attribute name="accfields" type="List" default="['Name','Comments__c']"></aura:attribute>
<aura:attribute name="recordSaveError" type="String"/>
<force:recordData aura:id="Accrecord"
                  recordId="{!v.recordId}"
                  layoutType="FULL"                      
                  fields="{!v.accfields}"
                  targetFields="{!v.record}"
                  mode="EDIT"
                  targetError="{!v.recordSaveError}"
                  recordUpdated="{!c.recordUpdataction}"
                  />
<lightning:textarea aura:id="verifyhswNoselection" 
                                        required="true"
                                        label="Comments"
                                        value="{!v.addingcomments}"
                                        class="slds-col slds-size_1-of-3 slds-p-horizontal_x-small">
</lightning:textarea>
<lightning:button variant="brand" onclick="{!c.addnewcomment}"/>

controller:

({
  addnewcomment : function (component,event,helper){
    var accrecord = component.get("v.record");
    var newcoments = component.get("v.addingcomments"),
        existingdesc = accrecord.Comments__c,
        todaydt = new Date(),
        existingdesc = (!$A.util.isEmpty(existingdesc)) ? existingdesc + '\n' + newcoments+'--' +todaydt.toLocaleString()+';' : newcoments+'--' +todaydt.toLocaleString()+';';
    accrecord.Comments__c = existingdesc;
    console.log(existingdesc);
    component.set("v.record",accrecord);
      component.find("Accrecord").saveRecord($A.getCallback(function(saveResult) {
        if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
             // record is saved successfully
             self.showStatusToast(component,succmessage,"success");
            $A.get("e.force:refreshView").fire();
            
        }else if(saveResult.state === "INCOMPLETE"){
             self.showStatusToast(component,'error occured',"error");
        }else if(saveResult.state === "ERROR"){
            self.showStatusToast(component,'error occured',"error");
            
        }
    }));
},

})

enter image description here

0

@sdandamud1 I have tried using the code in the initial question. The text area field is being updated perfectly along with the line breaks. I have added images of output in two scenarios

  1. When there is text in the field(initial comment) and we add comment from the component

When there is text in the field and we add comment from the component

2.When there is no text in the field and we add comment from the component.

When there is no text in the field and we add comment from the component

Can you verify if the Comments__c field is on the layout because the field either has to be on the layout or you have to declare a list of fields in an attribute on the component for LDS to fetch the data.

| improve this answer | |
  • i added comment__c field in ` fields="{!v.filedsList}"` even though it's not works for me, what is your field type in salesforce? – sdandamud1 Nov 18 '19 at 20:53
  • Its a text area long field. can you share the component code after adding the fieldsList attribute? – samdev Nov 18 '19 at 21:23
  • updated my question – sdandamud1 Nov 18 '19 at 21:27
  • Can you add the image of the output for "console.log(existingdesc);" in your controller? How does that look? does it have the line break? – samdev Nov 18 '19 at 21:46
  • console.log(existingdesc) gives with separate lines but after render UI it shows all comments in one line. updated image with console.log(existingdesc); – sdandamud1 Nov 18 '19 at 22:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.