• Eric Latreille 8
  • NEWBIE
  • 5 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 5
    Replies
I am using an example of the dynamic table where you can add and remove rows from a LWC. I was able to create a dynamic header (with Start through End Date), create dynamic input fields under each element of the header and also add and remove rows. Now I need to map the dynamic input fields to the right fields to create multiple records. See below image:
sched
In that example, it will create 4 records where the first will be Invoice April, the total amount will be 6200$ and it will also create 2 child records where the first one will be SEM | Adwords | 1200 and the second one will be FACEBOOK | Content | 5000$
The Second record will be Invoice May  for a total amount of 1200$ and with only one child record called SEM | Adwords | 1200 and so is the third and forth records.
My HTML Code:
<template for:each={contentArray} for:item="field" for:index="index">
                        <tr key={keyIndex}>
                            <td scope="col">
                                {index}
                            </td>
                            <template for:each={headerArray} for:item="field" for:index="index">
                                <td key={field.Index} scope="col">    
                                    <lightning-input data-index={index} access-key={index} id={index} type='text' value={field.Index} onchange={changeHandler}>
                                    </lightning-input>
                                </td>
                            </template>
                            <td scope="col">
                                <lightning-icon icon-name="action:delete"  access-key={index} id={index} alternative-text="Click to Call" size="small" title="large size" onclick={removeRow}>
                                </lightning-icon>
                            </td>
                        </tr>
                    </template>
my js code
changeHandler(event){
        
        this.template.querySelectorAll('lightning-input-field').forEach(element => {
            this.contentArray = this.contentArray && element.reportValidity();
        });
        
    }

    saveMultipleRecords() {
        console.log("contentArray"+JSON.stringify(this.contentArray));
        saveRecords({ recList : this.contentArray })
            .then(result => {
                this.message = result;
                this.error = undefined;                
                this.contentArray.forEach(function(item){                   
                                
                });

                if(this.message !== undefined) {
                    this.dispatchEvent(
                        new ShowToastEvent({
                            title: 'Success',
                            message: 'Records Created!',
                            variant: 'success',
                        }),
                    );
                }
            })
            .catch(error => {
                this.message = undefined;
                this.error = error;
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: 'Error creating records',
                        message: error.body.message,
                        variant: 'error',
                    }),
                );
                console.log("error", JSON.stringify(this.error));
            });
    }

and my cls:
 

public with sharing class invoiceSchedule {
    
    @AuraEnabled
    public static List<scheduleTable__c> saveRecords(List<scheduleTable__c> recList){
        
        Insert recList;
        
    }
}

I am new to coding and not too sure how can I get the data from my input fields but I know that I will need to clone that array and create an array of object? How can that work?

Your help is appreciated.

Thanks

I am not able to save my record. no error message is showing.
Here is my class.

public with sharing class ScheduleClass {
    @AuraEnabled
    public static Product_Schedule__c submitSchedule(String psRecordId, string psName, string psDescription){
        Product_Schedule__c psObj = new Product_Schedule__c();
        psObj.Invoice_Schedule__c=psRecordId;
        psObj.Product_Name__c=psName;
        psObj.Product_Description__c=psDescription;
 
        insert psObj;
        return psObj;
    }
}
If I add the id of my record page it works but if I am trying to pass the id through my js file it is not working.
Here is my JS File:
import {LightningElement, track, api } from 'lwc';
import submitSchedule from '@salesforce/apex/ScheduleClass.submitSchedule';
import {ShowToastEvent} from 'lightning/platformShowToastEvent';

export default class ScheduleClass extends LightningElement {
    @track psObjName;
    @track psObjDescription;
    @api psRecordId;
    @track errorMsg;
   psHandleChange(event){
        if(event.target.name == 'psName'){
        this.psObjName = event.target.value;
        }
        if(event.target.name == 'psDescription'){
        this.psObjDescription = event.target.value;  
        }
 }
 submitAction(){
    submitSchedule({psRecordId:this.psRecordId,psName:this.psObjName,psDescription:this.psObjDescription})
    .then(result=>{
        this.psRecordId = result.Id;
        window.console.log('psRecordId ' + this.psRecordId);       
        const toastEvent = new ShowToastEvent({
            title:'Success!',
            message:'Record created successfully',
            variant:'success'
          });
          this.dispatchEvent(toastEvent);
          /*Start Navigation*/
          this[NavigationMixin.Navigate]({
            type: 'standard__recordPage',
            attributes: {
                psRecordId: this.psRecordId,
                objectApiName: 'Invoice_Schedule__c',
                actionName: 'view'
            },
         });
         /*End Navigation*/
    })
    .catch(error =>{
       this.errorMsg=error.message;
       window.console.log(this.error);
    });
 }
}

What Am I doing wrong?
Thanks
Eric
Hi all,
I am curious to know how to do something like that. I have a custom object called Product_Schedule. In that object, I have the name, description, the month and the amount. I need to create record from a VF where I will be repeating the month coming from the opportunity and this will save it in multiple record in my object.
Example start_date = March 2021 and end_date = June 2021. I have 4 months to repeat in my columns. to the table header will look like that:
product | Description | March 2021 | April 2021 | May 2021 | June 2021
I can easily bind Product, description, month but not the amount as the ID stays the same so only the last month will work. How should I manage this?
Thanks
Eric
I am not able to save my record. no error message is showing.
Here is my class.

public with sharing class ScheduleClass {
    @AuraEnabled
    public static Product_Schedule__c submitSchedule(String psRecordId, string psName, string psDescription){
        Product_Schedule__c psObj = new Product_Schedule__c();
        psObj.Invoice_Schedule__c=psRecordId;
        psObj.Product_Name__c=psName;
        psObj.Product_Description__c=psDescription;
 
        insert psObj;
        return psObj;
    }
}
If I add the id of my record page it works but if I am trying to pass the id through my js file it is not working.
Here is my JS File:
import {LightningElement, track, api } from 'lwc';
import submitSchedule from '@salesforce/apex/ScheduleClass.submitSchedule';
import {ShowToastEvent} from 'lightning/platformShowToastEvent';

export default class ScheduleClass extends LightningElement {
    @track psObjName;
    @track psObjDescription;
    @api psRecordId;
    @track errorMsg;
   psHandleChange(event){
        if(event.target.name == 'psName'){
        this.psObjName = event.target.value;
        }
        if(event.target.name == 'psDescription'){
        this.psObjDescription = event.target.value;  
        }
 }
 submitAction(){
    submitSchedule({psRecordId:this.psRecordId,psName:this.psObjName,psDescription:this.psObjDescription})
    .then(result=>{
        this.psRecordId = result.Id;
        window.console.log('psRecordId ' + this.psRecordId);       
        const toastEvent = new ShowToastEvent({
            title:'Success!',
            message:'Record created successfully',
            variant:'success'
          });
          this.dispatchEvent(toastEvent);
          /*Start Navigation*/
          this[NavigationMixin.Navigate]({
            type: 'standard__recordPage',
            attributes: {
                psRecordId: this.psRecordId,
                objectApiName: 'Invoice_Schedule__c',
                actionName: 'view'
            },
         });
         /*End Navigation*/
    })
    .catch(error =>{
       this.errorMsg=error.message;
       window.console.log(this.error);
    });
 }
}

What Am I doing wrong?
Thanks
Eric
Here is my vf 

<apex:page standardController="Opportunity" standardStylesheets="false" applyHtmlTag="false" showHeader="false" renderAs="PDF">

    <head>
     ...style..    
   </head>
<body>
   .... information generated based on the opportunity fields..
</body>
</apex:page>

The vf is linked to a detailed buton.
When i click  the button  it opens vf page but in the same time i want to be saved as an attachment/file in the opportunity  

Any suggested implementations ? 
 
  • April 01, 2019
  • Like
  • 0
We have been designing a FLOW within a demo org and have hit a brick wall.

We have created a flow using a custom button on an opportunity record that creates a new invoice and drags the amount, account id and some other data into the INV record.

How can I extend its usage by pulling the products into the line items within the invoice using flow? Any idea's?

I started by using an opportunity line item lookup to gather the data and assgined to variables. The problem I face is getting that data to show on the INV record of the specific opportunity.

I am trying to understand standard controllers vs. custom--and how they can be used with Custom Objects?

 

Most of the code samples I have found all use the standard Account or Contact as the example like...

 

<apex:page standardController="Account" showHeader="true"  tabStyle="Account" > 

 

I have several Custom Objects that I have created---and have trying to create a simple Tabbed view of the object detail and related lists instead of the typical list view--using VF.

 

I am just starting on VF...

 

>Do standard controllers get 'auto-created' for each custom object?--assume so and thats how the display using standard SF look?

 

> When I try starting my VF page to be used on my Custom Object with...

 

 

<apex:page standardController="ThenameIusedtocreatetheobject_c" showHeader="true"  tabStyle="ThenameIusedtocreatetheobject_c"" > 

 

 

I get errors - ThenameIusedtocreatetheobject_c Does not Exist, etc.

 

 

What am I missing about standard controllers on custom objects?  Do all custom objects require a custom controller to be coded?

 

Thanks for the assistance...

 

KS