• Dwayne Jackson
  • NEWBIE
  • 25 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 6
    Replies
Hello,
I have two LWCs that are connected via an LMS channel.
LWC 1:
     - creates a custom record, and the related child records
     - publish a LMS channel and populate it with the ids
     - navigate to the record page the contains LWC 2  
LWC 2:
     - subscribes the LMS channel published by LWC1
     - retrieve the ids from the channel in connectedCallback
     - load the page with the custom record and related child record data

I can see the IDs in LWC 1 prior to navigating to the LWC 2. When LWC 2 loads connectedCallback is called but no ids are there. A snipet of the code is below. Any feedback on what I'm doing wrong?

// LWC 1 - A modal that contains the custom logic for creating a new Custom Object A record when the object +New Component Button is clicked
// - this component also does the following:
//     ** creates the related child component records
//     ** publishes an LMS channel with the Ids of the child components
//     ** navigates to the record page that contains the Custom Object A that was just created and the child component ids
import { LightningElement, api, wire } from 'lwc';
import { publish, MessageContext } from 'lightning/messageService';
import CUSTOM_OBJECT_A from '@salesforce/schema/Custom_ObjectA__c';
...
import MY_CHANNEL from '@salesforce/messageChannel/My_Id__c';

export default class CustomObjectACreator extends NavigationMixin(LightningElement) {
    @wire(MessageContext)
    messageContext;            
    
    customObjectApiName = CUSTOM_OBJECT_A;    
    
    @api recordId;  //The record Id set by the framework

    ...
    
    //Id's of Child Components. These are set when createRecord is executed in the child component 
    @api childComponent1RecordId = 'XXXXXX11111';
    @api childComponent2RecordId = 'YYYYYY22222';
    @api childComponent3RecordId = 'ZZZZZZ33333;  
       
    ...
    
     handleCreateCustomObject(event) {    

        //publish message with ids here...
        const payload = {
            childcomponent1recordid: this.childComponent1RecordId,
            childcomponent2recordid: this.childComponent2RecordId,
            childcomponent3recordid: this.childComponent3RecordId
        };        
        publish(this.messageContext, MY_CHANNEL, payload);  
        
         
        //Navigating to Record Page        
        this[NavigationMixin.Navigate]({
            type: 'standard__recordPage',
            attributes: {
                recordId: this.recordId,
                objectApiName: this.customObjectApiName,
                actionName: 'view'                
            }            
        });  
        
    }            
    
}


// This component is on the record page responsible for displaying the Custom Object A data with the related child components data
// This component also:
// - subscribes to the LMS channel published by LWC 1above
// - in connectedCallback, call the method to retrieve the related child component ids. NO IDs ARE PRESENT
// - load the related child components data based on the ids received from the LMS channel.
import { LightningElement, api, wire } from 'lwc';
...
import { subscribe, MessageContext } from 'lightning/messageService';
import CUSTOM_OBJECT_A from '@salesforce/schema/Custom_ObjectA__c';
...
import MY_CHANNEL from '@salesforce/messageChannel/My_Id__c';

export default class CustomObjectA extends LightningElement {
    
    ...
    //Id's for child components related to the Custom object 
    childComponent1RecordId;
    childComponent2RecordId;
    childComponent3RecordId;
 
    subscription = null;   
    
    //The Custom Object reference
    customObjectApiName = CUSTOM_OBJECT_A.fieldApiName;

    ...  
    
    connectedCallback() {        
        this.subscribeToMessageChannel();            
    }
    
    @wire(MessageContext)
    messageContext;

    // Encapsulate logic for LMS subscribe.        
    subscribeToMessageChannel() {
        this.subscription = subscribe(
            this.messageContext,
            SUBTASK_ID_CHANNEL,
            (message) => this.handleMessage(message)
        );        
    }    

    //Handler for message received by component. WHY CAN'T AM I NOT GETTING IDs HERE?
    handleMessage(message) {    
        console.log('CustomObjectA.handleMessage - childComponent Ids are: ', JSON.stringify(message));
        this.childComponent1RecordId = message.childcomponent1recordid;            //SHOULD BE: XXXXXX11111
        this.childComponent2RecordId = message.childcomponent2recordid;            //SHOULD BE: YYYYYY22222
        this.childComponent3RecordId = message.childcomponent3recordid;            //SHOULD BE: ZZZZZZ33333        
    }    
   ...    
    
}


 
Hello,

I having an issue creating a record using createRecord.  The error details in the console shows REQUIRED_FIELD_MISSING. I don't quite understand because I am passing in the two required fields in the recordInput property when createRecord method is being called. I verify this when I use stringify to see the content of the recordInput prior to the createRecord method call in the next statement. But when it's called immediately this error is thrown that shows the REQUIRED_FIELD_MISSING. See two console logs:

apiAccountRecoveryHelper.createAccountRecovery.recordInput = {"apiName":"Account_Recovery__c","theRecord":{"Platform_Change__c":"a1u18000000cu*****","Account_Name__c":"00118000011im*****","Launch__c":"a3l18000000AL*****"}}

apiAccountRecoveryHelper.createAccountRecovery.createRecord.error = {"status":400,"body":{"message":"An error occurred while trying to update the record. Please try again.","statusCode":400,"enhancedErrorType":"RecordError","output":{"errors":[],"fieldErrors":{"Account_Name__c":[{"constituentField":null,"duplicateRecordError":null,"errorCode":"REQUIRED_FIELD_MISSING","field":"Account_Name_c","fieldLabel":"Account Name","message":"Required fields are missing: [Platform_Change__c, Account_Name__c]"}],"Platform_Change__c":[{"constituentField":null,"duplicateRecordError":null,"errorCode":"REQUIRED_FIELD_MISSING","field":"Platform_Change__c","fieldLabel":"Platform Change","message":"Required fields are missing: [Platform_Change__c, Account_Name__c]"}]}}},"headers":{}}

 It's obvious that I'm missing something but can't figure out what it is. I've considered using generateRecordInputForCreate and getRecordCreateDefaults but not real sure why I should. Seems to me that createRecord should work. Any help is much appreciated. 
Hello,
 
Reaching out to ask if there are suggestions/guidance on how to approach implementing a lightning app page with custom LWCs (using LDS) and conditional rendering based on the below structure? The child LWCs displayed will be dependent on the selections made in a multi-select picklist in LWC A. The goal of this is render the essential fields based on the options selected as there are over 300+ fields. Need to CRU all from one action on the page.  Any guidance is much appreciated. Thanks in advance.
 
LWC A -> parent object A
  • LWC 1 -> child object 1
  • LWC 2 -> child object 2
  • LWC 3 -> child object 3
  • LWC 4 -> child object 4
  • LWC n -> child object n
Hi, I'm implementing the Lightning Web Components and Salesforce Data -> Handle Server Errors part of theTrailhead module.
 
The instructions say…
Handle Errors in the accountList Component
Let’s add error handling to the accountList component that you created.
  1. In the accountList.html file, after the <template> that includes the lightning-datatable, add this code:
    <template if:true={errors}>
        <p>{errors}</p>
    </template>

    Copy
  2. Copy the ldsUtils component from LWC recipes and include it in the force-app/main/default/lwc folder in your project. This component contains the reduceErrors function.
  3. Import the reduceErrors function near the beginning of accountList.js.
    import { reduceErrors } from 'c/ldsUtils';
    Copy
  4. In accountList.js, insert this getter, which defines an errors property:
    get errors() {
        return (this.accounts.error) ?
            reduceErrors(this.accounts.error) : [];
    }

    Copy
 
 
My issue is in step 2 and 3. I copied the ldsUtils component as instructed, but following problem shows up in Visual Studio Code Output panel and I cannot deploy it to my dev instance:
 
 
=== Deploy Errors
PROJECT PATH  ERRORS                                                                                                                                         
────────────  ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
              LWC1011: Failed to resolve import "../ldsUtils/ldsUtils" from "accountList.js". Please add "../ldsUtils/ldsUtils" file to the component folder.
 
 
So I changed the import in the accountList.js from:
import { reduceErrors } from 'c/ldsUtils';
To
import { reduceErrors } from '../ldsUtils/ldsUtils';
 
The ldsUtils component is in the same component folder as the rest of my LWC components, which is:
C:\...lwc-tutorials\workingWithDataInLWC\force-app\main\default\lwc\ldsUtils
 
Any help as to what I'm doing is wrong. Thanks in advance.
 
Hello,
I have two LWCs that are connected via an LMS channel.
LWC 1:
     - creates a custom record, and the related child records
     - publish a LMS channel and populate it with the ids
     - navigate to the record page the contains LWC 2  
LWC 2:
     - subscribes the LMS channel published by LWC1
     - retrieve the ids from the channel in connectedCallback
     - load the page with the custom record and related child record data

I can see the IDs in LWC 1 prior to navigating to the LWC 2. When LWC 2 loads connectedCallback is called but no ids are there. A snipet of the code is below. Any feedback on what I'm doing wrong?

// LWC 1 - A modal that contains the custom logic for creating a new Custom Object A record when the object +New Component Button is clicked
// - this component also does the following:
//     ** creates the related child component records
//     ** publishes an LMS channel with the Ids of the child components
//     ** navigates to the record page that contains the Custom Object A that was just created and the child component ids
import { LightningElement, api, wire } from 'lwc';
import { publish, MessageContext } from 'lightning/messageService';
import CUSTOM_OBJECT_A from '@salesforce/schema/Custom_ObjectA__c';
...
import MY_CHANNEL from '@salesforce/messageChannel/My_Id__c';

export default class CustomObjectACreator extends NavigationMixin(LightningElement) {
    @wire(MessageContext)
    messageContext;            
    
    customObjectApiName = CUSTOM_OBJECT_A;    
    
    @api recordId;  //The record Id set by the framework

    ...
    
    //Id's of Child Components. These are set when createRecord is executed in the child component 
    @api childComponent1RecordId = 'XXXXXX11111';
    @api childComponent2RecordId = 'YYYYYY22222';
    @api childComponent3RecordId = 'ZZZZZZ33333;  
       
    ...
    
     handleCreateCustomObject(event) {    

        //publish message with ids here...
        const payload = {
            childcomponent1recordid: this.childComponent1RecordId,
            childcomponent2recordid: this.childComponent2RecordId,
            childcomponent3recordid: this.childComponent3RecordId
        };        
        publish(this.messageContext, MY_CHANNEL, payload);  
        
         
        //Navigating to Record Page        
        this[NavigationMixin.Navigate]({
            type: 'standard__recordPage',
            attributes: {
                recordId: this.recordId,
                objectApiName: this.customObjectApiName,
                actionName: 'view'                
            }            
        });  
        
    }            
    
}


// This component is on the record page responsible for displaying the Custom Object A data with the related child components data
// This component also:
// - subscribes to the LMS channel published by LWC 1above
// - in connectedCallback, call the method to retrieve the related child component ids. NO IDs ARE PRESENT
// - load the related child components data based on the ids received from the LMS channel.
import { LightningElement, api, wire } from 'lwc';
...
import { subscribe, MessageContext } from 'lightning/messageService';
import CUSTOM_OBJECT_A from '@salesforce/schema/Custom_ObjectA__c';
...
import MY_CHANNEL from '@salesforce/messageChannel/My_Id__c';

export default class CustomObjectA extends LightningElement {
    
    ...
    //Id's for child components related to the Custom object 
    childComponent1RecordId;
    childComponent2RecordId;
    childComponent3RecordId;
 
    subscription = null;   
    
    //The Custom Object reference
    customObjectApiName = CUSTOM_OBJECT_A.fieldApiName;

    ...  
    
    connectedCallback() {        
        this.subscribeToMessageChannel();            
    }
    
    @wire(MessageContext)
    messageContext;

    // Encapsulate logic for LMS subscribe.        
    subscribeToMessageChannel() {
        this.subscription = subscribe(
            this.messageContext,
            SUBTASK_ID_CHANNEL,
            (message) => this.handleMessage(message)
        );        
    }    

    //Handler for message received by component. WHY CAN'T AM I NOT GETTING IDs HERE?
    handleMessage(message) {    
        console.log('CustomObjectA.handleMessage - childComponent Ids are: ', JSON.stringify(message));
        this.childComponent1RecordId = message.childcomponent1recordid;            //SHOULD BE: XXXXXX11111
        this.childComponent2RecordId = message.childcomponent2recordid;            //SHOULD BE: YYYYYY22222
        this.childComponent3RecordId = message.childcomponent3recordid;            //SHOULD BE: ZZZZZZ33333        
    }    
   ...    
    
}


 
Hello,

I having an issue creating a record using createRecord.  The error details in the console shows REQUIRED_FIELD_MISSING. I don't quite understand because I am passing in the two required fields in the recordInput property when createRecord method is being called. I verify this when I use stringify to see the content of the recordInput prior to the createRecord method call in the next statement. But when it's called immediately this error is thrown that shows the REQUIRED_FIELD_MISSING. See two console logs:

apiAccountRecoveryHelper.createAccountRecovery.recordInput = {"apiName":"Account_Recovery__c","theRecord":{"Platform_Change__c":"a1u18000000cu*****","Account_Name__c":"00118000011im*****","Launch__c":"a3l18000000AL*****"}}

apiAccountRecoveryHelper.createAccountRecovery.createRecord.error = {"status":400,"body":{"message":"An error occurred while trying to update the record. Please try again.","statusCode":400,"enhancedErrorType":"RecordError","output":{"errors":[],"fieldErrors":{"Account_Name__c":[{"constituentField":null,"duplicateRecordError":null,"errorCode":"REQUIRED_FIELD_MISSING","field":"Account_Name_c","fieldLabel":"Account Name","message":"Required fields are missing: [Platform_Change__c, Account_Name__c]"}],"Platform_Change__c":[{"constituentField":null,"duplicateRecordError":null,"errorCode":"REQUIRED_FIELD_MISSING","field":"Platform_Change__c","fieldLabel":"Platform Change","message":"Required fields are missing: [Platform_Change__c, Account_Name__c]"}]}}},"headers":{}}

 It's obvious that I'm missing something but can't figure out what it is. I've considered using generateRecordInputForCreate and getRecordCreateDefaults but not real sure why I should. Seems to me that createRecord should work. Any help is much appreciated. 
Hello,
 
Reaching out to ask if there are suggestions/guidance on how to approach implementing a lightning app page with custom LWCs (using LDS) and conditional rendering based on the below structure? The child LWCs displayed will be dependent on the selections made in a multi-select picklist in LWC A. The goal of this is render the essential fields based on the options selected as there are over 300+ fields. Need to CRU all from one action on the page.  Any guidance is much appreciated. Thanks in advance.
 
LWC A -> parent object A
  • LWC 1 -> child object 1
  • LWC 2 -> child object 2
  • LWC 3 -> child object 3
  • LWC 4 -> child object 4
  • LWC n -> child object n
Hi, I'm implementing the Lightning Web Components and Salesforce Data -> Handle Server Errors part of theTrailhead module.
 
The instructions say…
Handle Errors in the accountList Component
Let’s add error handling to the accountList component that you created.
  1. In the accountList.html file, after the <template> that includes the lightning-datatable, add this code:
    <template if:true={errors}>
        <p>{errors}</p>
    </template>

    Copy
  2. Copy the ldsUtils component from LWC recipes and include it in the force-app/main/default/lwc folder in your project. This component contains the reduceErrors function.
  3. Import the reduceErrors function near the beginning of accountList.js.
    import { reduceErrors } from 'c/ldsUtils';
    Copy
  4. In accountList.js, insert this getter, which defines an errors property:
    get errors() {
        return (this.accounts.error) ?
            reduceErrors(this.accounts.error) : [];
    }

    Copy
 
 
My issue is in step 2 and 3. I copied the ldsUtils component as instructed, but following problem shows up in Visual Studio Code Output panel and I cannot deploy it to my dev instance:
 
 
=== Deploy Errors
PROJECT PATH  ERRORS                                                                                                                                         
────────────  ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
              LWC1011: Failed to resolve import "../ldsUtils/ldsUtils" from "accountList.js". Please add "../ldsUtils/ldsUtils" file to the component folder.
 
 
So I changed the import in the accountList.js from:
import { reduceErrors } from 'c/ldsUtils';
To
import { reduceErrors } from '../ldsUtils/ldsUtils';
 
The ldsUtils component is in the same component folder as the rest of my LWC components, which is:
C:\...lwc-tutorials\workingWithDataInLWC\force-app\main\default\lwc\ldsUtils
 
Any help as to what I'm doing is wrong. Thanks in advance.