Answers - Salesforce Trailblazer Community
Ask Search:
Manibalan SampathkumarManibalan Sampathkumar 
Hi,

I am new to LWC and I have created a LWC to display AppliedQuoteLineItem(Custom object) as a related list against the Quote record(Record Page).

We have a new button on the LWC to create a new line item. I have fetched the fields from the line item layout using Metadata.Operations class and used lightning-input fields under lightning-record-edit form to display them when the New button is clicked. But, I would need to populate the Quote field when the modal loads after the New button is clicked. I understand that I can use value parameter of lightning-input-field to do the job, but in my case I have used for each loop to display the fields hence not sure how I can achieve this.

Following is the html:
 
<template>
    <lightning-card>
        <div class="slds-p-left_large slds-p-right_medium">
            <lightning-record-edit-form
            object-api-name="AppliedQuoteLineItem__c"
            onsuccess={handleSuccess}>
            <lightning-messages>
            </lightning-messages>
            
            <lightning-accordion allow-multiple-sections-open active-section-name={formActiveSections}>
            <template for:each={sec} for:item="lines">
            
                <lightning-accordion-section name={lines.label} label={lines.label} key={lines.label}>
                    <div class="slds-grid slds-wrap slds-gutters">
                <template for:each={lines.lstFields} for:item="flds">
                    <template if:false={flds.isReadOnly}>
                        <div class="slds-col slds-size_1-of-2" key={flds.CreatedById}>
                            
                            <lightning-input-field field-name={flds.fieldName}>
                            </lightning-input-field>
    
                        </div>
                    </template>        
            </template>
            </div>
                </lightning-accordion-section>
                
            
        </template>
        </lightning-accordion>
    
     </lightning-record-edit-form>
        </div>
    </lightning-card>
</template>

JS:
 
import { LightningElement, api, wire, track } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import getPageLayoutFields from '@salesforce/apex/AppliedQLineData.getPageLayoutFields';

export default class AppliedEditQLine extends LightningElement {

    @api getIdFromParent;
    sec;
    //@track formActiveSections=['Information','Product Selection','AHU & FCU','System Information'];
    //@track formActiveSections=['Information'];
    @track formActiveSections=[];
    /*@wire(getPageLayoutFields)
    sec;*/
    
    @wire(getPageLayoutFields)
    wiredLayouts({error, data}) {
         if (data) {
            this.sec = data;
            let newArray = [];
            this.sec.forEach(function(item, index, object){
                if (item.label !== 'Totals') {
                    newArray.push(item);
                }
            }, this);
            //window.console.log('newarray is'+JSON.stringify(newArray));
            this.sec=[];
            this.sec=newArray;
            let arr=[];
            for(var k in this.sec)
            {
                //window.console.log('label is'+this.sec[k].label);
                if(this.sec[k].label!='Totals')
                {
                window.console.log('inside if');
                this.formActiveSections.push(this.sec[k].label);
                //arr= '\''+ arr.push(this.sec[k].label)+'\'';
                //arr.push('\''+ this.sec[k].label+'\'');
                //window.console.log('arr is'+arr);
                }
                
            }
            this.formActiveSections.join(', ');
            
            window.console.log(this.formActiveSections);
                        
        }
            
}
        
    @api
     handleSave(){
        // querying the record edit form and submiting the fields
        this.template.querySelector('lightning-record-edit-form').submit();
        }

     handleSuccess(event)
     {
        // showing success message
        this.dispatchEvent(new ShowToastEvent({
            title: 'Success',
            message: 'Line Item has been created Successfully',
            variant: 'success'
        }),);
        const selectEvent = new CustomEvent('closemainmodal');
        this.dispatchEvent(selectEvent);
     }
    
}

I tried to populate the Quote Id on onload event, but nothing worked. I have got the Id to be populated in getIdFromParent variable.

Please help me on this.

Thanks
Mani
Best Answer chosen by Manibalan Sampathkumar
Mohith ShrivastavaMohith Shrivastava
I think these type of questions are much better answered if you post on salesforce stackexchange.

I think the core problem is lwc template if does not support expression binding. So you will have to either manipulate on front end or backend code to make sure you pass a boolean for your case.

For example check below a sample service that works perfectly fine for me. Note i have not used Metadata retrieve for simplicity. In real world you will convert results comming from the Metadata to your wrapper class.
 
<template>
  <lightning-card>
    <div class="slds-p-left_large slds-p-right_medium">
      <lightning-record-edit-form
        object-api-name="AppliedQuoteLineItem__c"
        onsuccess={handleSuccess}
      >
              <template for:each={results.data} for:item="flds">
                <template if:true={flds.isParentLookup}>
                  <div class="slds-col slds-size_1-of-2" key={flds.fieldname}>
                    <lightning-input-field field-name={flds.fieldname} value={recordId}>
                    </lightning-input-field>
                  </div>
                </template>
                <template if:false={flds.isParentLookup}>
                    <div class="slds-col slds-size_1-of-2" key={flds.fieldname}>
                      <lightning-input-field field-name={flds.fieldname}>
                      </lightning-input-field>
                    </div>
                  </template>
              </template>
      </lightning-record-edit-form>
    </div>
  </lightning-card>
</template>

The controller code
 
import { LightningElement, api, wire, track} from 'lwc';
import getPageLayoutFields from '@salesforce/apex/LayoutController.getLayoutDetails';

export default class AppliedEditLine extends LightningElement {

    results;
    @api
    recordId;

    @wire(getPageLayoutFields)
    results;
}

The apex class i have used is as below
 
public with sharing class LayoutController {

    @AuraEnabled(cacheable=true)
    public static List<LayoutMetadata> getLayoutDetails(){
        List<LayoutMetadata> metadatalst = new List<LayoutMetadata>();
        // Add your logic here to read the CustomLayout class and turn them into wrapper layer of field names and identify parentfield and flag it
        LayoutMetadata layoutmd1 = new LayoutMetadata('Quote__c', true, true);
        LayoutMetadata layoutmd2 = new LayoutMetadata('Name', true, false);
        metadatalst.add(layoutmd1);
        metadatalst.add(layoutmd2);
        return metadatalst;
    }

    public inherited sharing class LayoutMetadata {
        @AuraEnabled
        public String fieldname;
        @AuraEnabled
        public Boolean isRequired;
        @AuraEnabled
        public Boolean isParentLookup;

        public LayoutMetadata(String fieldname, Boolean isRequired, Boolean isParentLookup) {
            this.fieldname = fieldname;
            this.isRequired = isRequired;
            this.isParentLookup = isParentLookup;
        }
    }
    
}

​​​​​​​
Akis AthanasiadisAkis Athanasiadis 
Contract renewals are related with the Maintenance Fees.
When a maintenance fee is updated and the contract renweal is not renewed(checkbox), then the contract renewal is updated via an autolaunched flow.
However, if the contract renewal is renewed(checkbox), then the change should be blocked.
That means, not only the contract renewal is not updated, nor the maintenance fee.
So i would like something a validation rule to run before the flow runs.
Best Answer chosen by Akis Athanasiadis
Ronald DefeoRonald Defeo
Hi Akis,

Is Maintenance Fees child of Contract? If yes, then you can use the following formula on the maintenance fees object for you validation rule.
 
Contract__r.Renewal__c = True

Just change the field according to the field name in your org.
Ruslan VekuaRuslan Vekua 
Anyone can help me with what I am doing wrong with #7 challenge of Advanced Billing Specialist Superbadge?

Workflow Rule with Email Alert setup:
Workflow Rule with Email Alert setup

Error message:

Error message
Best Answer chosen by Ruslan Vekua
Ruslan VekuaRuslan Vekua
I was able to solve the problem. Looks like my time-dependent workflow actions were not set up correctly.
Cian Creed-HealyCian Creed-Healy 
Hey gang,

Could somebody provide some insight as to what's wrong with the following folrmula:

INCLUDES(Service_Days__c," & CASE(WEEKDAY(TODAY()), 1, "Sunday", 2, "Monday", 3, "Tuesday", 4, "Wednesday", 5, "Thursday", 6, "Friday", 7, "Saturday", "Error") & ")

With the above I keep getting the following error:

Error: Invalid Data.
Review all error messages below to correct your data.
Syntax error. Missing ')' (Related field: Formula)

When I try it without the quotes:

INCLUDES(Service_Days__c,CASE(WEEKDAY(TODAY()), 1, "Sunday", 2, "Monday", 3, "Tuesday", 4, "Wednesday", 5, "Thursday", 6, "Friday", 7, "Saturday", "Error"))

I get:

Error: Invalid Data.
Review all error messages below to correct your data.
Incorrect parameter type for function 'INCLUDES()'. Expected Text Literal, received Text (Related field: Formula)

Any help would be much appriciated.

Thank you,

-Cian
Best Answer chosen by Cian Creed-Healy
Ronald DefeoRonald Defeo
Hi Cian,

I updated the formula.
IF(INCLUDES(Service_Days__c,"Sunday") && WEEKDAY(TODAY()) = 1 ||
INCLUDES(Service_Days__c,"Monday") && WEEKDAY(TODAY()) = 2 ||
INCLUDES(Service_Days__c,"Tuesday") && WEEKDAY(TODAY()) = 3 ||
INCLUDES(Service_Days__c,"Wednesday") && WEEKDAY(TODAY()) = 4 ||
INCLUDES(Service_Days__c,"Thursday") && WEEKDAY(TODAY()) = 5 ||
INCLUDES(Service_Days__c,"Friday") && WEEKDAY(TODAY()) = 6 ||
INCLUDES(Service_Days__c,"Saturday") && WEEKDAY(TODAY()) = 7, True,
False)

The reason for the error regarding Expected Text Literal, received Text. This is because formulas that return text are just text. While literal requires a text enclosed in " double-quotes.
Bertram NehlsBertram Nehls 
Hi all,

I feel like I'm being an idiot about this one but I just can't seem to find the answer.

A couple of my users are dealing with humongous lists of records and are being frustrated by the way that Lightning presents them in a continous list rather than having the skip through options that Classic has. Does anyone know if there is a way to enable this/a similar feature on Lightning?

Thanks all, stay safe!
Best Answer chosen by Bertram Nehls
Ronald DefeoRonald Defeo
Hi Bertram,

It looks like your, not the only one who's having difficulties with the list view in lightning.

Here's an Ideas Exchange link that you can upvote.

https://success.salesforce.com/ideaView?id=0873A00000159V2QAI

If you're familiar with Aura then here's a link to a custom solution that you can look at.

https://bitbucket.org/vdeepak/lightningpagination/src/master/
https://saramorgan.net/2017/08/13/lightning-best-practice-adding-pagination-to-lists/
SANTANU KUMAR PATRASANTANU KUMAR PATRA 

Hi,

Try to create processbuilder in Invocable Processes [  ISCHANGED(), ISNEW(), and PRIORVALUE().] is not working and showing this  error (The formula expression is invalid: Function ISNEW may not be used in this type of formula)

Need Alternet solution for avove Issue .

Thank you
Santanu

Best Answer chosen by SANTANU KUMAR PATRA
Ronald DefeoRonald Defeo
You can look at using Flow to replace the Invocable Process. As when you call a Flow, the formulas you need are accessible and can be passed as values to Flow Variables.
Mimma AltieriMimma Altieri 
Hello,
I need to create a rule for an user in order to allow him/her modify only records based on specific criteria.
I created  a specific role and prfile assigned to thsi user only.
As example: User John Smith, can only modify Leads and Account where country=UK.
What's the best option in your opinion? 
Best Answer chosen by Mimma Altieri
Ines GarciaInes Garcia
Hi Mimma,

Just recently I wrote about sharing rules: https://www.salesforceben.com/tips-for-planning-and-creating-salesforce-sharing-rules/
Also, best place to go is trailhead https://trailhead.salesforce.com/en/content/learn/projects/protect-your-data-in-salesforce/create-opportunity-sharing-rules
you have handson exercises there as well as the theory and logic of functionality
Max WinbladMax Winblad 
Hi everyone 

I need some help with a formula field. 

On the object with the new formula field we want to pull in values from two fields on different objects if one of them is empty.

Example:

Object Order - new field Owner Group

Owner Group 
should be a formula text field first looking at field Contract Owner Group on object Contract. If that is empty it should look at field Location Owner Group on object Location.

Contract Owner Group and Location Owner Group are both picklist fields.

Any help really appreciated! 
Best Answer chosen by Max Winblad
Angus BrownAngus Brown
++Eric

Max I think the formula will be some thing like this:
BLANKVALUE(TEXT(Contract__r.Contract_Owner_Group__c),TEXT(Location__r.Location_Owner_Group__c))

 
Racheal DalesRacheal Dales 
Is it possible within Lightning to create a searchable picklist?  The issue is that we have a LARGE picklist "Job Markets" and I would like to avoid having the users scroll endlessly to find what they are looking for.  It would be so much easier if they can begin typing what they are looking for and for the picklist to move to that particular item for them to choose.  Thanks in advance for any advice you can provide.
Best Answer chosen by Racheal Dales
Guillermo AkermanGuillermo Akerman
Hi Racheal!

When I click on my picklists and start typing, the selection automatically moves to the words that I'm typing. There's any other way of searching I believe. 

Cheers!
Ben ZBen Z 
Hello everyone!
One of my users suddenly doesn't have to ability to create a Post while being on the Chatter object.
I checked the profile but nothing has been changed so I don't really understand where the issue could come from.
Any ideas please?
Thanks
Ben
Best Answer chosen by Ben Z
Ben ZBen Z
I found the answer!
https://success.salesforce.com/answers?id=90630000000CnVQAA0
https://success.salesforce.com/answers?id=90630000000CofbAAC