• numberforty1
  • NEWBIE
  • 20 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies
I am writing a component that allows the user to designate the API names of the fields they want to see in a related list. I am trying to pass these API field names into the "fields" parameter of a lightning record component, but I am getting the following error. If I hard code the field names in, everything works fine. It seems that in JavaScript I need to do something to convert the @api values to a string, even though it seems to be working just fine as a string when I am successfully passing it to my aura enabled Apex class.

Basically it will not accept ```const fields``` in my JS.

Error: "[Cannot read property 'fieldApiName' of undefined]"

It seems to me that all values are defined by @api, but I must be missing something. What am I missing?

Many thanks

User-added image


    <template>  
          
        <lightning-card title={strTitle} icon-name="standard:record">
    
            <lightning-button class="slds-m-around_medium" label="New" onclick={navigateToNew}></lightning-button>
    
            <div class="slds-m-around_medium">  
      
                <div if:true={records.data}>  
      
                    <template for:each={records.data} for:item="rec">    
      
                        <div key={rec.Id} class="slds-box">  
      
                            <lightning-record-form
                                record-id={rec.Id}   
                                object-api-name={objectName}   
                                fields={fields}    
                                mode="view"  
                                columns="3">                                                
                            </lightning-record-form>
      
                        </div>  
                          
                    </template>  
      
                </div>  
      
            </div>  
      
        </lightning-card>  
          
    </template>

JS

    import { LightningElement, api, wire } from 'lwc';  
    import fetchRecords from '@salesforce/apex/RelatedListController.fetchRecords';
    import { NavigationMixin } from 'lightning/navigation';
      
    export default class RelatedList extends NavigationMixin(LightningElement) {   
      
        @api objectName;   
        @api parentFieldAPIName;  
        @api recordId;  
        @api strTitle;
        @api fieldName1;
        @api fieldName2;
        @api fieldName3;
        @api fieldName4;
        @api fieldName5;
        @api fieldName6;  
    
        @track vals;

     connectedCallback() {
        const fields = [];
        
        if (this.fieldName1) {
            fields.push(this.fieldName1);
        }
        if (this.fieldName2) {
            fields.push(this.fieldName2);
        }
        if (this.fieldName3) {
            fields.push(this.fieldName3);
        }       
        
        if (fields.length) {
            this.vals = this.recordId + ',' + this.objectName + ',' +   
               this.parentFieldAPIName + ',' + this.fieldName1 + ',' +
               this.fieldName2 + ',' + this.fieldName3;
        }
     }
          
        @wire(fetchRecords, {listValues: '$vals'})  
        records;
    
        navigateToNew() {
            this[NavigationMixin.Navigate]({
                type: 'standard__objectPage',
                attributes: {
                    objectApiName: 'POC_Use_Case__c',
                    actionName: 'new'
                }        
            });
        }
    }

Meta

    <?xml version="1.0" encoding="UTF-8"?>
    <LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="RelatedList">
        <apiVersion>45.0</apiVersion>
        <isExposed>true</isExposed>
        <targets>
            <target>lightning__RecordPage</target>
        </targets>
        <targetConfigs>
            <targetConfig targets="lightning__RecordPage">
                <property name="strTitle" type="String" label="Title" description="Enter the title"/>
                <property name="objectName" type="String" label="Object Name" description="Enter the object API name"/>
                <property name="parentFieldAPIName" type="String" label="Parent Field API Name" description="Enter the parent field API Name"/>
                <property name="fieldName1" type="String" label="Field 1 API Name" description="Enter the field API name"/>
                <property name="fieldName2" type="String" label="Field 2 API Name" description="Enter the field API name"/>
                <property name="fieldName3" type="String" label="Field 3 API Name" description="Enter the field API name"/>
                <property name="fieldName4" type="String" label="Field 4 API Name" description="Enter the field API name"/>
                <property name="fieldName5" type="String" label="Field 5 API Name" description="Enter the field API name"/>
                <property name="fieldName6" type="String" label="Field 6 API Name" description="Enter the field API name"/>
            
            </targetConfig>
        </targetConfigs>
    </LightningComponentBundle>


Apex

    public class RelatedListController {  
      
        @AuraEnabled(cacheable=true)  
        public static List <sObject> fetchRecords(String listValues){      
            
            List <String> strList = listValues.split(',');  
            system.debug('values are ' + strList);  
              
            if (strList.size() == 6) {  
              
                String recordId = strList.get(0);  
                String objectName = strList.get(1);  
                String parentFieldAPIName = strList.get(2);  
                String fieldName1 = strList.get(3);  
                String fieldName2 = strList.get(4);
                String fieldName3 = strList.get(5);
                  
                String strSOQL = 'SELECT Id, '+fieldName1+', '+fieldName2+', '+fieldName3+
                                 ' FROM '+objectName+' WHERE '+parentFieldAPIName+' = \''+recordId+'\' ';
                
                system.debug('-------->strSOQL = '+strSOQL);                        
                
                return Database.query(strSOQL);  
                  
            } else   
                return null;            
        }          
    }

 
I am writing a component that allows the user to designate the API names of the fields they want to see in a related list. I am trying to pass these API field names into the "fields" parameter of a lightning record component, but I am getting the following error. If I hard code the field names in, everything works fine. It seems that in JavaScript I need to do something to convert the @api values to a string, even though it seems to be working just fine as a string when I am successfully passing it to my aura enabled Apex class.

Basically it will not accept ```const fields``` in my JS.

Error: "[Cannot read property 'fieldApiName' of undefined]"

It seems to me that all values are defined by @api, but I must be missing something. What am I missing?

Many thanks

User-added image


    <template>  
          
        <lightning-card title={strTitle} icon-name="standard:record">
    
            <lightning-button class="slds-m-around_medium" label="New" onclick={navigateToNew}></lightning-button>
    
            <div class="slds-m-around_medium">  
      
                <div if:true={records.data}>  
      
                    <template for:each={records.data} for:item="rec">    
      
                        <div key={rec.Id} class="slds-box">  
      
                            <lightning-record-form
                                record-id={rec.Id}   
                                object-api-name={objectName}   
                                fields={fields}    
                                mode="view"  
                                columns="3">                                                
                            </lightning-record-form>
      
                        </div>  
                          
                    </template>  
      
                </div>  
      
            </div>  
      
        </lightning-card>  
          
    </template>

JS

    import { LightningElement, api, wire } from 'lwc';  
    import fetchRecords from '@salesforce/apex/RelatedListController.fetchRecords';
    import { NavigationMixin } from 'lightning/navigation';
      
    export default class RelatedList extends NavigationMixin(LightningElement) {   
      
        @api objectName;   
        @api parentFieldAPIName;  
        @api recordId;  
        @api strTitle;
        @api fieldName1;
        @api fieldName2;
        @api fieldName3;
        @api fieldName4;
        @api fieldName5;
        @api fieldName6;  
    
        @track vals;

     connectedCallback() {
        const fields = [];
        
        if (this.fieldName1) {
            fields.push(this.fieldName1);
        }
        if (this.fieldName2) {
            fields.push(this.fieldName2);
        }
        if (this.fieldName3) {
            fields.push(this.fieldName3);
        }       
        
        if (fields.length) {
            this.vals = this.recordId + ',' + this.objectName + ',' +   
               this.parentFieldAPIName + ',' + this.fieldName1 + ',' +
               this.fieldName2 + ',' + this.fieldName3;
        }
     }
          
        @wire(fetchRecords, {listValues: '$vals'})  
        records;
    
        navigateToNew() {
            this[NavigationMixin.Navigate]({
                type: 'standard__objectPage',
                attributes: {
                    objectApiName: 'POC_Use_Case__c',
                    actionName: 'new'
                }        
            });
        }
    }

Meta

    <?xml version="1.0" encoding="UTF-8"?>
    <LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="RelatedList">
        <apiVersion>45.0</apiVersion>
        <isExposed>true</isExposed>
        <targets>
            <target>lightning__RecordPage</target>
        </targets>
        <targetConfigs>
            <targetConfig targets="lightning__RecordPage">
                <property name="strTitle" type="String" label="Title" description="Enter the title"/>
                <property name="objectName" type="String" label="Object Name" description="Enter the object API name"/>
                <property name="parentFieldAPIName" type="String" label="Parent Field API Name" description="Enter the parent field API Name"/>
                <property name="fieldName1" type="String" label="Field 1 API Name" description="Enter the field API name"/>
                <property name="fieldName2" type="String" label="Field 2 API Name" description="Enter the field API name"/>
                <property name="fieldName3" type="String" label="Field 3 API Name" description="Enter the field API name"/>
                <property name="fieldName4" type="String" label="Field 4 API Name" description="Enter the field API name"/>
                <property name="fieldName5" type="String" label="Field 5 API Name" description="Enter the field API name"/>
                <property name="fieldName6" type="String" label="Field 6 API Name" description="Enter the field API name"/>
            
            </targetConfig>
        </targetConfigs>
    </LightningComponentBundle>


Apex

    public class RelatedListController {  
      
        @AuraEnabled(cacheable=true)  
        public static List <sObject> fetchRecords(String listValues){      
            
            List <String> strList = listValues.split(',');  
            system.debug('values are ' + strList);  
              
            if (strList.size() == 6) {  
              
                String recordId = strList.get(0);  
                String objectName = strList.get(1);  
                String parentFieldAPIName = strList.get(2);  
                String fieldName1 = strList.get(3);  
                String fieldName2 = strList.get(4);
                String fieldName3 = strList.get(5);
                  
                String strSOQL = 'SELECT Id, '+fieldName1+', '+fieldName2+', '+fieldName3+
                                 ' FROM '+objectName+' WHERE '+parentFieldAPIName+' = \''+recordId+'\' ';
                
                system.debug('-------->strSOQL = '+strSOQL);                        
                
                return Database.query(strSOQL);  
                  
            } else   
                return null;            
        }          
    }

 
Hello,

I'm attempting to deploy some new code and our test class is failing due to the following error:

System.NullPointerException: Attempt to de-reference a null object
Stack Trace: Class.slackv2.invokePostMessage.makePostMessageRequest: line 30, column 1

We have the Salesforce for Slack (https://appexchange.salesforce.com/appxListingDetail?listingId=a0N3A00000FnD9mUAF) app installed in our Org. According to the setup instructions, we have a Process Builder created to send a notification to Slack when a new Opportunity is created. If I disable this Process Builder, I am able to deploy the code. However, I don't want to have to disable this Process Builder every time I deploy in the future. The code in managed packages is not visible so I cannot determine exactly what I need to do 

Does anyone have a suggestion on how I can determine what the managed package class needs?

Here's the test class and the class itself:
@isTest
private class testCreateOpp {
    static testMethod void validateOpp() {
    
        // Create a new email and envelope object
        Messaging.InboundEmail email = new Messaging.InboundEmail() ;
        Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();
        
        // Populate email
        email.plainTextBody = 'Body text';
        email.subject = 'Subject Line of Email';
       
        // Execute method
        createOpp createOppObj = new createOpp();
        createOppObj.handleInboundEmail(email, env);
    }
}

global class createOpp implements Messaging.InboundEmailHandler {
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, Messaging.InboundEnvelope env){
    
        // Create an InboundEmailResult object for returning the result of the Apex Email Service 
        Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
        String myPlainText= email.plainTextBody;
        String OppAccountId = '0014600000A0aaaAAA';
   
        // New Opportunity to be created
        Opportunity newOpp = new Opportunity(Name = email.subject, 
            AccountId = OppAccountId, 
            CloseDate = system.today() + 15,
            Description = myPlainText, // Email Body
            StageName = 'Identified',
            Amount = 5000);
    
        // Insert new Opportunity
        insert newOpp;    
        
        // Set the result to true. No need to send an email back to the user with an error message   
        result.success = true;
    
        // Return the result for the Apex Email Service 
        return result;
    }
}

Hello friends. I have a method that creates records in custom metadata. It works as expected but now I am having a hard time figuring out how to get test coverage for it. 

Initially got an error on the line that enques the deployment via Metadata.Operations.enqueueDeployment which said that metadata cannot be deployed in a test context.

Then I found the suggestion of just skipping that line with a ternary operator, which is the version I have posted here. And that gives me 'Fake Job Id' is not a proper id. Strange that this seems to have worked for other people on that stackexchange post. 

 

At this point I need to seek some advice from those of you that are more experienced. Thanks!!

 

@future
    public static void createCustomMetaData(string acctName, string acctId) {

    string fullname = 'Product_Selection_Search_Parameter.'+acctName.replace(' ','_');    
    // Set up custom metadata to be created in the subscriber org. thanks to https://www.sfdcpanther.com/create-update-custom-metadata-using-apex/
    Metadata.CustomMetadata customMetadata =  new Metadata.CustomMetadata();
    customMetadata.fullName = fullname;
    customMetadata.label = acctName;

    Metadata.CustomMetadataValue typeField = new Metadata.CustomMetadataValue();
    typeField.field = 'Type__c';
    typeField.value = 'Top-Up';
	Metadata.CustomMetadataValue acctField = new Metadata.CustomMetadataValue();
    acctField.field = 'Value__c';
    acctField.value = acctId;

    customMetadata.values.add(typeField);
	customMetadata.values.add(acctField);

    Metadata.DeployContainer mdContainer = new Metadata.DeployContainer();
    mdContainer.addMetadata(customMetadata);

    // Setup deploy callback, MyDeployCallback implements
    // the Metadata.DeployCallback interface 
    CustomMetadataCallback callback = new CustomMetadataCallback();

    // Enqueue custom metadata deployment
    // jobId is the deployment ID
    Id jobId = Test.isRunningTest() ? 'Fake Job Id' : Metadata.Operations.enqueueDeployment(mdContainer, callback);
    }

Here is the test class
@isTest
public with sharing class di_PartnerCreation_Test {
    
    @TestSetup
    static void makeData(){
        TestData_Research_Director director = new TestData_Research_Director();
        director.Construct_Account(new TestData_Research(), true);
        director.Construct_NonStandardPBE(new TestData_Research(), true);
    }

    public static testMethod void testDIPartnerCreationMethods_Act() {
        Account act = [select Id, Name from Account limit 1];
        PriceBook2 pb = [select Id from PriceBook2 where IsStandard = false];

        map<string, string> pbTest = di_PartnerCreation_lcController.getPriceBookOptions(act, 'AUD');
        boolean exProds = di_PartnerCreation_lcController.hasExistingProducts(act.Id);
        di_PartnerCreation_lcController.createProducts(act, 'AUD');
        di_PartnerCreation_lcController.createPriceBookEntries(act, 'AUD', pb.Id);
    }

    public static testMethod void testDIPartnerCreationMethods_NoAct() {

        map<string, string> currencyMap = di_PartnerCreation_lcController.getCurrencies();

    }
}

 
I am trying to Schedule an class at the interval of 5 minutes but am not getting any idea how to perform it, i have seen some examples but they are not working properly please help if any body can.