function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bretondevbretondev 

Ligghtning Component : Where is the recordId attribute set?

WHere is the recordId attribute set?

First, I want to say I am still new to Lightning Components. Still learning.
I have just taken over a project from another developer.
On the Quote object, we have a Custom Button that is linked to a Lightning Component that will display multiple infos about the Quote.

I understand most of the code :
We retrieve the Id of the Quote because there is an attribute for that :
<aura:attribute name="recordId" type="string" description="The  id of the contact or contact light" />

So in the controller we do :
var recordId =  component.get("v.recordId");

This way we retrieve Quote  recordId, then we put it as a parameter of the Apex method (getDevisInfo) we call.
This Apex method returns all infos we need about the Quote.
Then we can navigate to another component by giving it all the infos and so on.

What I don't understand is where is set the recordId attribute at the beginning of the code.
I don't see anywhere something like :
component.set(v.recordId, someValue);

So from my point of view, the first time we do
var recordId =  component.get("v.recordId");
recordId should be null

When I test with console.log() , indeed the recordId exists.

Please explain me how recordId attribute is set.

Component :
<aura:component access="GLOBAL" controller="LC11_GestionOffre" implements="force:lightningQuickActionWithoutHeader">
    <!-- ************************************************************* -->
    <!-- **************** global / shared attributes *****************-->
    <!-- ************************************************************* -->
    <aura:attribute name="recordId" type="string" description="The  id of the contact or contact light" />
    <aura:attribute name="divHeight" type="string" default="200px" description="" />
     <aura:attribute name="inError" type="boolean" default="false" description="" />    
    <aura:attribute name="message" type="string" default="" description="" />
    <!-- ************************************************************* -->
    <!-- **************** Handler definition         *****************-->
    <!-- ************************************************************* -->
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />

    <div class="slds-grid slds-grid--align-center slds-grid--vertical-align-center" style="{!'height:' + v.divHeight}">
        <h2 class="{! v.inError ? 'slds-hide' : 'slds-text-heading--small'}">Validation en cours..</h2>
        <h2 class="{! v.inError ? 'slds-text-heading--small slds-text-color--error' : 'slds-hide'}">
            {!v.message}
        </h2>
    </div>
</aura:component>

Controller :
 
({
    doInit: function(component, event, helper) {
    	console.log('## navigating to the LC11_GestionOffre component');
    	
    	var action = component.get("c.getDevisInfo");
		var recordId =  component.get("v.recordId");
		console.log('### MAB' + recordId);
        
	    action.setParams({"qId":recordId});
	    action.setCallback(this, function(response) {
	        var state = response.getState();
	        if (state === "SUCCESS") {  
	            var result = response.getReturnValue();
	            if(result.error){
	            	component.set("v.inError",true);
	            	component.set("v.message",result.message);
	            }
	            else{
	            	var evt = $A.get("e.force:navigateToComponent");
			        evt.setParams({
			            componentDef: "c:LC11_GestionOffre",
			            componentAttributes: {
			                recordId: component.get("v.recordId"),
			                record: result.quote,
			                showPanier: true
			            }
	        		});
	        		evt.fire();
	            }	            
	        }
	        else {
	            console.log('## error obj : ',action.getError()[0]);
	            //this.showError(action.getError()[0].messag);
	        }        
	                 
	    });
	    $A.enqueueAction(action);

    }
})



 
Best Answer chosen by bretondev
Alain CabonAlain Cabon
Hi,

Record Id is an exception. It is automatically initialized from the context if you declare this attribute or the interface force:hasRecordId.

The recordId attribute is set only when you place or invoke the component in an explicit record context. For example, when you place the component directly on a record page layout, or invoke it as an object-specific action from a record page or object home.

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_interfaces_force_hasrecordid.htm
 

All Answers

Alain CabonAlain Cabon
Hi,

Record Id is an exception. It is automatically initialized from the context if you declare this attribute or the interface force:hasRecordId.

The recordId attribute is set only when you place or invoke the component in an explicit record context. For example, when you place the component directly on a record page layout, or invoke it as an object-specific action from a record page or object home.

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_interfaces_force_hasrecordid.htm
 
This was selected as the best answer
bretondevbretondev
Thanks. That answers the question