<aura:attribute name="simpleRecord" type="Object"/>
<aura:handler name="init" value="{!this}" action="{!c.displayAttach}"/> 
 <force:recordData aura:id="recordLoader"
        <lightning:button  onclick="{!c.handleClick}" label="Attach file">

  handleClick : function(component, event, helper){
    var recordId = component.get("v.recordId");
           console.log('Case number ====>'+ component.get("v.simpleRecord").CaseNumber);
     var urlEvent = $A.get("e.force:navigateToURL");
         "url":  '/p/attach/NoteAttach?pid='+component.get("v.recordId")+'/parentname='+component.get("v.simpleRecord").CaseNumber+'/'+'&retURL=%2F'+component.get("v.recordId")         });

on click of my lightning button I want to create a dynamic URL like this

https://garvitasb2bsc--4hdev.cs60.my.salesforce.com/p/attach/NoteAttach?pid=5003C000003bdmt&parentname=0114054744&retURL=%2F5003C000003bdmtQAA where ‘500..’ is case id, ‘001’ is the case number.

I'm able to pass the case id I'm stuck how can I get case number

I'm getting this error

This page has an error. You might just need to refresh it. Action failed: c:CustomAttachmentRelatedList$controller$handleClick [Cannot read property 'setParams' of undefined] Failing descriptor: {c:CustomAttachmentRelatedList$controller$handleClick}


Have you tried loading a record using force:recordData? For example, you can put this markup on your lightning component and it should be able to load your data without using Apex at all. This feature is a part of the Lightning Data Service.

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

  <force:recordData aura:id="recordLoader"

   "url": '/p/attach/NoteAttach?pid='+component.get("v.recordId")+'/parentname='component.get("v.simpleRecord.CaseNumber")+'/'+'&retURL=%2F'+component.get("v.recordId")

To access the record fields in the JavaScript controller, use the component.get("v.simpleRecord.fieldName") syntax. See this.

| improve this answer | |
  • yes, I did this as well I'm getting the error I have updated the above code with comment @the_phantom – garvita asthana Aug 6 at 12:59
  • Are you using component.get("v.simpleRecord").CaseNumber? The CaseNumber field should be inside the parenthesis - component.get("v.simpleRecord.fieldName") – the_phantom Aug 6 at 13:13
  • both will work component.get("v.simpleRecord").CaseNumber this and component.get("v.simpleRecord.fieldName") this as well but still I'm getting error "Cannot read property 'setParams' of undefined] Failing descriptor: {c:CustomAttachmentRelatedList$controller$handleClick}' – garvita asthana Aug 6 at 13:21
  • Try adding this dependency in the markup: <aura:dependency resource="markup://force:navigateToURL" type="EVENT"/>, refresh your browser multiple times and try again. – the_phantom Aug 6 at 13:38
  • same error with this also – garvita asthana Aug 6 at 13:45

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.