• Ap30
  • NEWBIE
  • 145 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 1
    Likes Given
  • 34
    Questions
  • 27
    Replies
Hi All,
I'm getting below error in accountList.html. Please guide me.

User-added image
 
  • June 05, 2021
  • Like
  • 0
Hi All,
There are objects Vendor__c and Placement__c which are not related to each other. In component 1, I have two picklists "state" and "company".
On giving values to "state and company" and clicking "select" button, it should lists all the records matching state and company from object "Placement__c" in component 2.
Any help is appreciated.



VendorComponent
==============
<template>
    <lightning-record-edit-form object-api-name="Vendor__c">
        <lightning-input-field field-name="Vendor_First_Name__c"></lightning-input-field>
        <lightning-input-field field-name="Vendor_Last_Name__c"></lightning-input-field>
        <lightning-input-field field-name="Vendor_Phone__c" type="tel"></lightning-input-field>
        <lightning-input-field field-name="Vendor_Email__c"></lightning-input-field>
              <lightning-combobox
              name="st"
              label="State"
              value={value1}
              placeholder="Select State"
              options={options1}
              onchange={handleChange1} ></lightning-combobox>
              <lightning-combobox
              name="Com"
              label="Company"
              value={value2}
              placeholder="Select Company"
              options={options2}
              onchange={handleChange2} ></lightning-combobox>
        <lightning-button class="slds-m-top_small" variant="brand" type="submit" label="SAVE" onclick = {navigateToLightningComponent}></lightning-button>

    </lightning-record-edit-form>
</template>

==============================================
import { LightningElement,wire,api} from 'lwc';
import { NavigationMixin } from 'lightning/navigation';
export default class VendorComponent extends LightningElement {
   
        get options1() {
        return [
            { label: 'Delhi', value: 'del' },
            { label: 'Maharashtra', value: 'mah' },
            { label: 'Kerala', value: 'ker' },
        ];
    }
    get options2() {
        return [
            { label: 'Company1', value: '1c' },
            { label: 'Company2', value: '2c' },
            { label: 'Company3', value: '3c' },
        ];
    }
    navigateToLightningComponent() {
        this[NavigationMixin.Navigate]({
            "type": "custom__component",
            "attributes": {
                
                "componentName": "c__payComponent"
            }
        });
    }
}
==============================================
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>51.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__AppPage</target>
        <target>lightning__RecordPage</target>
        <target>lightning__HomePage</target>
    </targets>
    
</LightningComponentBundle>
  • May 29, 2021
  • Like
  • 0
Hi All,
I'm new to lightning web components. In my below code, two objects Vendor__c and Payment__c ia having master detail relationship.Vendor__c is the parent object. On clicking submit button in VendorComponent, master detail field in payCompopnent should be populated with the value of the record just created in component 1. Please help to achieve this. Also email to be sent sent to vendor email id once payement is done in component 2.

VendorComponent
==============
<template>
    <lightning-record-edit-form object-api-name="Vendor__c">
        <lightning-input-field field-name="Vendor_First_Name__c"></lightning-input-field>
        <lightning-input-field field-name="Vendor_Last_Name__c"></lightning-input-field>
        <lightning-input-field field-name="Vendor_Phone__c" type="tel"></lightning-input-field>
        <lightning-input-field field-name="Vendor_Email__c"></lightning-input-field>
              <lightning-combobox
              name="st"
              label="State"
              value={value1}
              placeholder="Select State"
              options={options1}
              onchange={handleChange1} ></lightning-combobox>
              <lightning-combobox
              name="Com"
              label="Company"
              value={value2}
              placeholder="Select Company"
              options={options2}
              onchange={handleChange2} ></lightning-combobox>
        <lightning-button class="slds-m-top_small" variant="brand" type="submit" label="SAVE" onclick = {navigateToLightningComponent}></lightning-button>

    </lightning-record-edit-form>
</template>

==============================================
import { LightningElement,wire,api} from 'lwc';
import { NavigationMixin } from 'lightning/navigation';
export default class VendorComponent extends LightningElement {
   
        get options1() {
        return [
            { label: 'Delhi', value: 'del' },
            { label: 'Maharashtra', value: 'mah' },
            { label: 'Kerala', value: 'ker' },
        ];
    }
    get options2() {
        return [
            { label: 'Company1', value: '1c' },
            { label: 'Company2', value: '2c' },
            { label: 'Company3', value: '3c' },
        ];
    }
    navigateToLightningComponent() {
        this[NavigationMixin.Navigate]({
            "type": "custom__component",
            "attributes": {
                
                "componentName": "c__payComponent"
            }
        });
    }
}
==============================================
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>51.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__AppPage</target>
        <target>lightning__RecordPage</target>
        <target>lightning__HomePage</target>
    </targets>
    
</LightningComponentBundle>
========================
PayComponent
=========
<template>

    <lightning-record-edit-form object-api-name="Payment__c">
        <lightning-output-field field-name="Vendor_Details__c" value={vendorDet}></lightning-output-field>
        <lightning-input-field field-name="Card_No__c" type="number"></lightning-input-field>
        <lightning-input-field field-name="Exp_Month__c" type="number"></lightning-input-field>
        <lightning-input-field field-name="Exp_Year__c" type="number"></lightning-input-field>
        <lightning-input-field field-name="CVV__c" type="password"></lightning-input-field>
        <lightning-button class="slds-m-top_small" variant="brand" type="submit" label="SUBMIT"></lightning-button>
    </lightning-record-edit-form>
</template>
=============================================
import { LightningElement, wire,api,track } from 'lwc';
import { CurrentPageReference } from 'lightning/navigation';
import { NavigationMixin } from 'lightning/navigation';
import { getRecord } from 'lightning/uiRecordApi';
import { getFieldValue } from 'lightning/uiRecordApi';
import VENDOR_OBJECT from '@salesforce/schema/Vendor__c';
import NAME_FIELD from '@salesforce/schema/Vendor__c.Name';
import PAYMENT_OBJECT from '@salesforce/schema/Payment__c';


const fields = [NAME_FIELD];
export default class PayComponent extends NavigationMixin(LightningElement) {
    @api getIdFromParent;

    @api vendorDet;
    
    @wire(CurrentPageReference) pageRef;
    @wire(getRecord, { recordId: '$getIdFromParent', fields: [NAME_FIELD] })
    PAYMENT_OBJECT;

    get vendorDet() {
        return getFieldValue(this.PAYMENT_OBJECT.data, NAME_FIELD);
    }

    }
======================================================
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="paymentInfoComponent">
    <apiVersion>51.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__AppPage</target>
        <target>lightning__RecordPage</target>
        <target>lightning__HomePage</target>
    </targets>
       </LightningComponentBundle>
  • May 28, 2021
  • Like
  • 0
Hi All,
I have to create 3 components.On clicking a button in component 1, it should create a reecord and go to component 2 and on clicking button in component 2, it should move to component 3. Component 1 and 3 have master detail relationship. So how to get the relationship field value in component 3 to create the record. I'm new to Lightning web components.(learning)
Any help is appreciated.
  • May 25, 2021
  • Like
  • 0
Hi All,
In my below code, return false is not working. I have highlighted those lines. Though i'm getting alert message "Enter state...." , command button is executed. Any help is appreciated.
=============
<apex:page controller="Bookings" id="page">
<script>
    
    function nameValidation(id){
        
        var n = document.getElementById('{!$Component.page.form.pb.pbs.name}');
        
        if(n.value == "")
        {
            alert("Name is mandatory");
            return false;
        }
       
       
        if(id == 'page:form:pb:pdf'){
        this.clickMe();
        }
        }
function clickMe()
     {
        var a = document.getElementById('{!$Component.page.form.pb.pbs.state}');
        var b = document.getElementById('{!$Component.page.form.pb.pbs.coun}');
        var pdfbtn = document.querySelector("[id$='pdf']");
        
        if(a.value == "" )
        {
            alert("Enter state to show Generate Pdf Button");
            pdfbtn.style.visibility = 'hidden';
            return false;
        }
        else if(b.value == "")
        {
            alert("Enter Country to show Generate Pdf Button");
            pdfbtn.style.visibility = 'hidden';
            return false;
        }
        else
        {
            alert("inside else");
            clickme();
        }
    }
</script>
 <apex:form id="form">
    <apex:actionFunction action="{!clickme}" name="clickme" reRender="pb"/>
  <apex:actionFunction name="toggleButton" reRender="op"/>
  <apex:pageBlock title="Booking Form" id="pb">
  <apex:pageBlockSection columns="2" id="pbs">
  Name :<apex:inputText value="{!person}" id="name" />
  State :<apex:inputText value="{!state}" id="state" onchange="toggleButton()"/>
  Country :<apex:inputText value="{!country}" id="coun" onchange="toggleButton()"/>
  </apex:pageBlockSection>
  <apex:outputPanel id="op">
  <apex:commandButton value="Click Me" id="pdf" action="{!clickme}" onclick="return nameValidation(this.id);"/>
  
  </apex:outputPanel>
  </apex:pageBlock>
  
  </apex:form>
</apex:page>
  • May 19, 2021
  • Like
  • 0
Hi All,
In my below code, I have to call tow javascript functions "amtValidation() and clickMe()" inside javascript "nameValidation". These functions should be called based on the button click. when "send" button is clicked it has to call amtValidation(), and when "click Me" is clicked it has to call clickMe(). Please help.
============
<apex:page controller="Bookings" id="page">
<script>
    
    function nameValidation(){
    
      var n = document.getElementById('{!$Component.page.form.pb.pbs.name}');
        alert(n.value);
        if(n.value == "")
        {
            alert("Name is mandatory");
            return false;
        }
        else{
        alert("enter name else");
         amtValidation();
         clickMe();
        }
        }
    function amtValidation(){
        //process here
    }
     function clickMe(){
        //process here
    }
    
    <apex:form id="form">
  <apex:actionFunction action="{!send}" name="send" reRender="pb" />
  <apex:actionFunction action="{!clickme}" name="clickme" reRender="pb"/>
  <apex:pageBlock title="Vendor Registration Form" id="pb">
  <apex:pageBlockSection columns="2" id="pbs">
  Name :<apex:inputText value="{!vcperson}" id="name"/>
  
   
  </apex:pageBlockSection>
  <apex:outputPanel id="op">
  <apex:commandButton value="Send" id="email" action="{!send}" onclick="return nameValidation();return amtValidation()"/>
  <apex:commandButton value="Click Me" id="pdf" action="{!clickme}" onclick="return nameValidation();return clickMe()"/>
  </apex:outputPanel>
  
  
  </apex:pageBlock>
</apex:form>
</apex:page>
  • May 18, 2021
  • Like
  • 0
Hi All,
In my below code, only name validation is working fine. When amount is blank,send button is not disabled.I could able to send email.
Also when city and country is not entered, Click Me button is not hidden. I'm new to javascript. Please guide me.

======================================

<apex:page controller="Bookings" id="page">
<script>
    function nameValidation(){
    
      var n = document.getElementById('{!$Component.page.form.pb.pbs.name}');
        
        if(n.value == "")
        {
            alert("Name is mandatory");
            return false;
        }
        else{
        return true;
        }
        }
    function amtValidation(){
      
        var at = document.getElementById('{!$Component.page.form.pb.pbs.amt}');
        if(at.value == "")
        {
           document.getElementById('{!$Component.page.form.pb.op.email}').disabled = true;
        }
        else
        {
            send();
        }
     }
     function clickMe()
     {
        var a = document.getElementById('{!$Component.page.form.pb.pbs.city}');
        var b = document.getElementById('{!$Component.page.form.pb.pbs.coun}');
        if(a.value == "" )
        {
            document.getElementById('{!$Component.page.form.pb.op.pdf}').style.visibility="hidden";
            return false;
        }
        else if(b.value == "")
        {
            document.getElementById('{!$Component.page.form.pb.op.pdf}').style.visibility="hidden";
            return false;
        }
        else
        {
            return true;
        }
    }
     
</script>
 <apex:form id="form">
  <apex:actionFunction action="{!send}" name="send" reRender="pb" />
  <apex:actionFunction action="{!clickme}" name="clickme" reRender="pb"/>
  <apex:pageBlock title="Vendor Registration Form" id="pb">
  <apex:pageBlockSection columns="2" id="pbs">
  Name :<apex:inputText value="{!vcperson}" id="name"/>
  Amount :<apex:inputText value="{!apevent}" id="amt"/>
  City :<apex:inputText value="{!city}" id="city"/>
  Country :<apex:inputText value="{!country}" id="coun"/>
   
  </apex:pageBlockSection>
  <apex:outputPanel id="op">
  <apex:commandButton value="Send" id="email" action="{!send}" onclick="return nameValidation();return amtValidation()"/>
  <apex:commandButton value="Click Me" id="pdf" action="{!clickme}" onclick="return nameValidation();return clickMe()"/>
  </apex:outputPanel>
  
  
  </apex:pageBlock>
  
  </apex:form>
</apex:page>
  • May 17, 2021
  • Like
  • 0
In my below code, only name validation is working fine. When amount is blank,send button is not disabled.I could able to send email.
Also when city and country is not entered, Click Me button is not hidden. I'm new to javascript. Please guide me.

======================================

<apex:page controller="Bookings" id="page">
<script>
    function nameValidation(){
    
      var n = document.getElementById('{!$Component.page.form.pb.pbs.name}');
        
        if(n.value == "")
        {
            alert("Name is mandatory");
            return false;
        }
        else{
        return true;
        }
        }
    function amtValidation(){
      
        var at = document.getElementById('{!$Component.page.form.pb.pbs.amt}');
        if(at.value == "")
        {
           document.getElementById('{!$Component.page.form.pb.op.email}').disabled = true;
        }
        else
        {
            send();
        }
     }
     function clickMe()
     {
        var a = document.getElementById('{!$Component.page.form.pb.pbs.city}');
        var b = document.getElementById('{!$Component.page.form.pb.pbs.coun}');
        if(a.value == "" )
        {
            document.getElementById('{!$Component.page.form.pb.op.pdf}').style.visibility="hidden";
            return false;
        }
        else if(b.value == "")
        {
            document.getElementById('{!$Component.page.form.pb.op.pdf}').style.visibility="hidden";
            return false;
        }
        else
        {
            return true;
        }
    }
     
</script>
 <apex:form id="form">
  <apex:actionFunction action="{!send}" name="send" reRender="pb" />
  <apex:actionFunction action="{!clickme}" name="clickme" reRender="pb"/>
  <apex:pageBlock title="Vendor Registration Form" id="pb">
  <apex:pageBlockSection columns="2" id="pbs">
  Name :<apex:inputText value="{!vcperson}" id="name"/>
  Amount :<apex:inputText value="{!apevent}" id="amt"/>
  City :<apex:inputText value="{!city}" id="city"/>
  Country :<apex:inputText value="{!country}" id="coun"/>
   
  </apex:pageBlockSection>
  <apex:outputPanel id="op">
  <apex:commandButton value="Send" id="email" action="{!send}" onclick="return nameValidation();return amtValidation()"/>
  <apex:commandButton value="Click Me" id="pdf" action="{!clickme}" onclick="return nameValidation();return clickMe()"/>
  </apex:outputPanel>
  
  
  </apex:pageBlock>
  
  </apex:form>
</apex:page>
                                        
  • May 15, 2021
  • Like
  • 0
Hi All,
In my below code else part is not working though status field is blank. Please guide where i'm going wrong.
===============
<apex:page standardController="Detail__c" extensions="WarningPage" action="{!displayWarning}">

<apex:form >
    <apex:pageBlock >
    
        <apex:pageMessages ></apex:pageMessages>
</apex:pageBlock>
</apex:form>
</apex:page>

==============================================


public with sharing class WarningPage {
 
    public WarningPage(ApexPages.StandardController controller) {
    }
    public void displayWarning(){
   
    list<Detail__c> stud = [select id,name,Status__c  from Detail__c ];
    
        for(Detail__c s : stud)
        {
        
            
                if(s.Status__c == 'More details needed')
                {
                   
                 ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'More details needed'));
                }
                else if(s.Status__c == '')
                {
                    
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Verified'));
                }
                }
                }
                }
  • May 15, 2021
  • Like
  • 0
Hi All,
Command btton is not getting disabled. Condition is written in javascript.

============
<apex:page controller="vRegistration" id="page">

<script>
    function getValidation(){
      
        var at = document.getElementById('{!$Component.page.form.pb.pbs.amt}');
        if(at.value == "")
        {
           document.getElementById('{!$Component.page.form.pb.pbs.email}').disabled = true;
        }
        else
        {
            return true;
        }
     }
</script>

  <apex:form id="form">
  <apex:actionFunction action="{!sendEmail}" name="sendEmail" reRender="pb" />
  <apex:actionFunction action="{!generatePDF}" name="generatePdf" reRender="pb"/>
  <apex:pageBlock title="Registration Form" id="pb">
  <apex:pageBlockSection columns="2" id="pbs">
  Company Name :<apex:inputText value="{!vcname}" id="name"/>
  Amount :<apex:inputText value="{!apevent}" id="amt"/>
    </apex:pageBlockSection>
  <apex:outputPanel >
  <apex:commandButton value="Send Email" id="email" action="{!sendEmail}" onclick="getValidation();"/>
  <apex:commandButton value="Generate PDF" action="/apex/generatePDFpage"  onclick="return generatePDF()" />
  </apex:outputPanel>
  
  
  </apex:pageBlock>
  
  </apex:form>
</apex:page>
  • May 14, 2021
  • Like
  • 0
Hi All,
I have to display warning message in my standard page layout of a custom object. I'm using window onload function. Warning message is displayed but with flickers. Please guide me how to avoid this.

==============================================
<apex:page standardController="Detail__c" extensions="WarningPage">
<script>
window.onload = function()
{
    if({!Detail__c.Status__c  = 'Details needed'})
    {
        dispWarn();
    }
 }

</script>
<apex:form >
    <apex:pageBlock >
    <apex:actionFunction action="{!displayWarning}" name="dispWarn"/>
        <apex:pageMessages ></apex:pageMessages>
</apex:pageBlock>
</apex:form>
</apex:page>
  • May 13, 2021
  • Like
  • 0
Hi All,
In my below code i have to get the count of 'unchecked' records whenever apex is executed in batch class. Please guide me how to get the count for only 'unchecked' records found.

if(t.Profile__c == null)
            {
        t.Status__c = 'Fill data';
            }
            else if(t.Profile__c != null && t.Check__c == 'No')
            {
                t.Verification_Status__c = 'Unchecked';
              
            }
  • May 12, 2021
  • Like
  • 0
Hi All,
How to display warning message in standard page layout only for certain records based on a field value?
  • May 12, 2021
  • Like
  • 0
Hello All,
Below code is not workinng. I'm not getting alert message when name is not entered.I tried all possible ways. 
====================
<apex:page controller="vendorRegistration" id="page">

<script>
    function getValidation()
    {
     alert('hi');
    
     var n = document.getElementById('{!$Component.page.form.pb.pbs.name}');
       if(n.value =="")
       {
            alert("Name is mandatory");
       }
       

    }
</script>

  <apex:form id="form">
  
  <apex:pageBlock title="Registration Form" id="pb">
  <apex:pageBlockSection columns="2" id="pbs">
  Company Name :<apex:inputText value="{!vcname}" id="name"/>
    </apex:pageBlockSection>
  <apex:outputPanel >
  <apex:commandButton value="Send Email" id="email" action="{!sendEmail}" onclick="getValidation();"/>
  
  </apex:outputPanel>
  
  
  </apex:pageBlock>
  
  </apex:form>
</apex:page>
  • May 10, 2021
  • Like
  • 0
Hello All,
In standard view we should see only one record at a time. On clicking next button, it should show another single record. Record shown first should not be there. I couldn't implement as i'm new to pagination concept.Please help.

<apex:page standardController="obj__c" extensions="contollername">
 <apex:form >
    <apex:pageBlock title="Student's Data">
  
           <apex:pageBlockTable value="{!listitem}"  var="sd">
            
          <apex:column value="{!sd.First_Name__c}"/>
          <apex:column value="{!sd.Last_Name__c}"/>
          <apex:column value="{!sd.Company__c}"/>
             
                        
            </apex:pageBlockTable>
            <apex:pageBlockButtons >
    <apex:commandButton action="{!previous}" value="Prev"/>
      <apex:commandButton action="{!next}" value="Next"/>
    </apex:pageBlockButtons>
           
       </apex:pageBlock>
   </apex:form>
</apex:page> 

======================
public class contollername
{
    public transient List<obj__c> listitem{get; set;}
    public Integer size {get; set;}

    public contollername(ApexPages.StandardController stdController) {

         size=1;
         setLists();
    }

    public void setLists()
    {
       listitem= [Select First_Name__c,Last_Name__c,Company__c From obj__c limit:size];
    }

   public void next()
   {
      
      setLists();
   }
   
   public void previous()
   {
      
      setLists();
   }
}
  • May 08, 2021
  • Like
  • 1
Hello All,
In standard view we should see only one record at a time. On clicking next button, it should show another single record. Record shown first should not be there. I couldn't implement as i'm new to pagination concept.Please help.

<apex:page standardController="obj__c" extensions="contollername">
 <apex:form >
    <apex:pageBlock title="Student's Data">
  
           <apex:pageBlockTable value="{!listitem}"  var="sd">
            
          <apex:column value="{!sd.First_Name__c}"/>
          <apex:column value="{!sd.Last_Name__c}"/>
          <apex:column value="{!sd.Company__c}"/>
             
                        
            </apex:pageBlockTable>
            <apex:pageBlockButtons >
    <apex:commandButton action="{!previous}" value="Prev"/>
      <apex:commandButton action="{!next}" value="Next"/>
    </apex:pageBlockButtons>
           
       </apex:pageBlock>
   </apex:form>
</apex:page> 

======================
public class contollername
{
    public transient List<obj__c> listitem{get; set;}
    public Integer size {get; set;}

    public contollername(ApexPages.StandardController stdController) {

         size=1;
         setLists();
    }

    public void setLists()
    {
       listitem= [Select First_Name__c,Last_Name__c,Company__c From obj__c limit:size];
    }

   public void next()
   {
      
      setLists();
   }
   
   public void previous()
   {
      
      setLists();
   }
}
  • May 08, 2021
  • Like
  • 1
Hi All,
There are objects Vendor__c and Placement__c which are not related to each other. In component 1, I have two picklists "state" and "company".
On giving values to "state and company" and clicking "select" button, it should lists all the records matching state and company from object "Placement__c" in component 2.
Any help is appreciated.



VendorComponent
==============
<template>
    <lightning-record-edit-form object-api-name="Vendor__c">
        <lightning-input-field field-name="Vendor_First_Name__c"></lightning-input-field>
        <lightning-input-field field-name="Vendor_Last_Name__c"></lightning-input-field>
        <lightning-input-field field-name="Vendor_Phone__c" type="tel"></lightning-input-field>
        <lightning-input-field field-name="Vendor_Email__c"></lightning-input-field>
              <lightning-combobox
              name="st"
              label="State"
              value={value1}
              placeholder="Select State"
              options={options1}
              onchange={handleChange1} ></lightning-combobox>
              <lightning-combobox
              name="Com"
              label="Company"
              value={value2}
              placeholder="Select Company"
              options={options2}
              onchange={handleChange2} ></lightning-combobox>
        <lightning-button class="slds-m-top_small" variant="brand" type="submit" label="SAVE" onclick = {navigateToLightningComponent}></lightning-button>

    </lightning-record-edit-form>
</template>

==============================================
import { LightningElement,wire,api} from 'lwc';
import { NavigationMixin } from 'lightning/navigation';
export default class VendorComponent extends LightningElement {
   
        get options1() {
        return [
            { label: 'Delhi', value: 'del' },
            { label: 'Maharashtra', value: 'mah' },
            { label: 'Kerala', value: 'ker' },
        ];
    }
    get options2() {
        return [
            { label: 'Company1', value: '1c' },
            { label: 'Company2', value: '2c' },
            { label: 'Company3', value: '3c' },
        ];
    }
    navigateToLightningComponent() {
        this[NavigationMixin.Navigate]({
            "type": "custom__component",
            "attributes": {
                
                "componentName": "c__payComponent"
            }
        });
    }
}
==============================================
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>51.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__AppPage</target>
        <target>lightning__RecordPage</target>
        <target>lightning__HomePage</target>
    </targets>
    
</LightningComponentBundle>
  • May 29, 2021
  • Like
  • 0
Hi All,
I have to create 3 components.On clicking a button in component 1, it should create a reecord and go to component 2 and on clicking button in component 2, it should move to component 3. Component 1 and 3 have master detail relationship. So how to get the relationship field value in component 3 to create the record. I'm new to Lightning web components.(learning)
Any help is appreciated.
  • May 25, 2021
  • Like
  • 0
Hi All,
In my below code, return false is not working. I have highlighted those lines. Though i'm getting alert message "Enter state...." , command button is executed. Any help is appreciated.
=============
<apex:page controller="Bookings" id="page">
<script>
    
    function nameValidation(id){
        
        var n = document.getElementById('{!$Component.page.form.pb.pbs.name}');
        
        if(n.value == "")
        {
            alert("Name is mandatory");
            return false;
        }
       
       
        if(id == 'page:form:pb:pdf'){
        this.clickMe();
        }
        }
function clickMe()
     {
        var a = document.getElementById('{!$Component.page.form.pb.pbs.state}');
        var b = document.getElementById('{!$Component.page.form.pb.pbs.coun}');
        var pdfbtn = document.querySelector("[id$='pdf']");
        
        if(a.value == "" )
        {
            alert("Enter state to show Generate Pdf Button");
            pdfbtn.style.visibility = 'hidden';
            return false;
        }
        else if(b.value == "")
        {
            alert("Enter Country to show Generate Pdf Button");
            pdfbtn.style.visibility = 'hidden';
            return false;
        }
        else
        {
            alert("inside else");
            clickme();
        }
    }
</script>
 <apex:form id="form">
    <apex:actionFunction action="{!clickme}" name="clickme" reRender="pb"/>
  <apex:actionFunction name="toggleButton" reRender="op"/>
  <apex:pageBlock title="Booking Form" id="pb">
  <apex:pageBlockSection columns="2" id="pbs">
  Name :<apex:inputText value="{!person}" id="name" />
  State :<apex:inputText value="{!state}" id="state" onchange="toggleButton()"/>
  Country :<apex:inputText value="{!country}" id="coun" onchange="toggleButton()"/>
  </apex:pageBlockSection>
  <apex:outputPanel id="op">
  <apex:commandButton value="Click Me" id="pdf" action="{!clickme}" onclick="return nameValidation(this.id);"/>
  
  </apex:outputPanel>
  </apex:pageBlock>
  
  </apex:form>
</apex:page>
  • May 19, 2021
  • Like
  • 0
Hi All,
In my below code, I have to call tow javascript functions "amtValidation() and clickMe()" inside javascript "nameValidation". These functions should be called based on the button click. when "send" button is clicked it has to call amtValidation(), and when "click Me" is clicked it has to call clickMe(). Please help.
============
<apex:page controller="Bookings" id="page">
<script>
    
    function nameValidation(){
    
      var n = document.getElementById('{!$Component.page.form.pb.pbs.name}');
        alert(n.value);
        if(n.value == "")
        {
            alert("Name is mandatory");
            return false;
        }
        else{
        alert("enter name else");
         amtValidation();
         clickMe();
        }
        }
    function amtValidation(){
        //process here
    }
     function clickMe(){
        //process here
    }
    
    <apex:form id="form">
  <apex:actionFunction action="{!send}" name="send" reRender="pb" />
  <apex:actionFunction action="{!clickme}" name="clickme" reRender="pb"/>
  <apex:pageBlock title="Vendor Registration Form" id="pb">
  <apex:pageBlockSection columns="2" id="pbs">
  Name :<apex:inputText value="{!vcperson}" id="name"/>
  
   
  </apex:pageBlockSection>
  <apex:outputPanel id="op">
  <apex:commandButton value="Send" id="email" action="{!send}" onclick="return nameValidation();return amtValidation()"/>
  <apex:commandButton value="Click Me" id="pdf" action="{!clickme}" onclick="return nameValidation();return clickMe()"/>
  </apex:outputPanel>
  
  
  </apex:pageBlock>
</apex:form>
</apex:page>
  • May 18, 2021
  • Like
  • 0
In my below code, only name validation is working fine. When amount is blank,send button is not disabled.I could able to send email.
Also when city and country is not entered, Click Me button is not hidden. I'm new to javascript. Please guide me.

======================================

<apex:page controller="Bookings" id="page">
<script>
    function nameValidation(){
    
      var n = document.getElementById('{!$Component.page.form.pb.pbs.name}');
        
        if(n.value == "")
        {
            alert("Name is mandatory");
            return false;
        }
        else{
        return true;
        }
        }
    function amtValidation(){
      
        var at = document.getElementById('{!$Component.page.form.pb.pbs.amt}');
        if(at.value == "")
        {
           document.getElementById('{!$Component.page.form.pb.op.email}').disabled = true;
        }
        else
        {
            send();
        }
     }
     function clickMe()
     {
        var a = document.getElementById('{!$Component.page.form.pb.pbs.city}');
        var b = document.getElementById('{!$Component.page.form.pb.pbs.coun}');
        if(a.value == "" )
        {
            document.getElementById('{!$Component.page.form.pb.op.pdf}').style.visibility="hidden";
            return false;
        }
        else if(b.value == "")
        {
            document.getElementById('{!$Component.page.form.pb.op.pdf}').style.visibility="hidden";
            return false;
        }
        else
        {
            return true;
        }
    }
     
</script>
 <apex:form id="form">
  <apex:actionFunction action="{!send}" name="send" reRender="pb" />
  <apex:actionFunction action="{!clickme}" name="clickme" reRender="pb"/>
  <apex:pageBlock title="Vendor Registration Form" id="pb">
  <apex:pageBlockSection columns="2" id="pbs">
  Name :<apex:inputText value="{!vcperson}" id="name"/>
  Amount :<apex:inputText value="{!apevent}" id="amt"/>
  City :<apex:inputText value="{!city}" id="city"/>
  Country :<apex:inputText value="{!country}" id="coun"/>
   
  </apex:pageBlockSection>
  <apex:outputPanel id="op">
  <apex:commandButton value="Send" id="email" action="{!send}" onclick="return nameValidation();return amtValidation()"/>
  <apex:commandButton value="Click Me" id="pdf" action="{!clickme}" onclick="return nameValidation();return clickMe()"/>
  </apex:outputPanel>
  
  
  </apex:pageBlock>
  
  </apex:form>
</apex:page>
                                        
  • May 15, 2021
  • Like
  • 0
Hi All,
In my below code else part is not working though status field is blank. Please guide where i'm going wrong.
===============
<apex:page standardController="Detail__c" extensions="WarningPage" action="{!displayWarning}">

<apex:form >
    <apex:pageBlock >
    
        <apex:pageMessages ></apex:pageMessages>
</apex:pageBlock>
</apex:form>
</apex:page>

==============================================


public with sharing class WarningPage {
 
    public WarningPage(ApexPages.StandardController controller) {
    }
    public void displayWarning(){
   
    list<Detail__c> stud = [select id,name,Status__c  from Detail__c ];
    
        for(Detail__c s : stud)
        {
        
            
                if(s.Status__c == 'More details needed')
                {
                   
                 ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'More details needed'));
                }
                else if(s.Status__c == '')
                {
                    
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Verified'));
                }
                }
                }
                }
  • May 15, 2021
  • Like
  • 0
Hi All,
Command btton is not getting disabled. Condition is written in javascript.

============
<apex:page controller="vRegistration" id="page">

<script>
    function getValidation(){
      
        var at = document.getElementById('{!$Component.page.form.pb.pbs.amt}');
        if(at.value == "")
        {
           document.getElementById('{!$Component.page.form.pb.pbs.email}').disabled = true;
        }
        else
        {
            return true;
        }
     }
</script>

  <apex:form id="form">
  <apex:actionFunction action="{!sendEmail}" name="sendEmail" reRender="pb" />
  <apex:actionFunction action="{!generatePDF}" name="generatePdf" reRender="pb"/>
  <apex:pageBlock title="Registration Form" id="pb">
  <apex:pageBlockSection columns="2" id="pbs">
  Company Name :<apex:inputText value="{!vcname}" id="name"/>
  Amount :<apex:inputText value="{!apevent}" id="amt"/>
    </apex:pageBlockSection>
  <apex:outputPanel >
  <apex:commandButton value="Send Email" id="email" action="{!sendEmail}" onclick="getValidation();"/>
  <apex:commandButton value="Generate PDF" action="/apex/generatePDFpage"  onclick="return generatePDF()" />
  </apex:outputPanel>
  
  
  </apex:pageBlock>
  
  </apex:form>
</apex:page>
  • May 14, 2021
  • Like
  • 0
Hi All,
I have to display warning message in my standard page layout of a custom object. I'm using window onload function. Warning message is displayed but with flickers. Please guide me how to avoid this.

==============================================
<apex:page standardController="Detail__c" extensions="WarningPage">
<script>
window.onload = function()
{
    if({!Detail__c.Status__c  = 'Details needed'})
    {
        dispWarn();
    }
 }

</script>
<apex:form >
    <apex:pageBlock >
    <apex:actionFunction action="{!displayWarning}" name="dispWarn"/>
        <apex:pageMessages ></apex:pageMessages>
</apex:pageBlock>
</apex:form>
</apex:page>
  • May 13, 2021
  • Like
  • 0
Hello All,
In standard view we should see only one record at a time. On clicking next button, it should show another single record. Record shown first should not be there. I couldn't implement as i'm new to pagination concept.Please help.

<apex:page standardController="obj__c" extensions="contollername">
 <apex:form >
    <apex:pageBlock title="Student's Data">
  
           <apex:pageBlockTable value="{!listitem}"  var="sd">
            
          <apex:column value="{!sd.First_Name__c}"/>
          <apex:column value="{!sd.Last_Name__c}"/>
          <apex:column value="{!sd.Company__c}"/>
             
                        
            </apex:pageBlockTable>
            <apex:pageBlockButtons >
    <apex:commandButton action="{!previous}" value="Prev"/>
      <apex:commandButton action="{!next}" value="Next"/>
    </apex:pageBlockButtons>
           
       </apex:pageBlock>
   </apex:form>
</apex:page> 

======================
public class contollername
{
    public transient List<obj__c> listitem{get; set;}
    public Integer size {get; set;}

    public contollername(ApexPages.StandardController stdController) {

         size=1;
         setLists();
    }

    public void setLists()
    {
       listitem= [Select First_Name__c,Last_Name__c,Company__c From obj__c limit:size];
    }

   public void next()
   {
      
      setLists();
   }
   
   public void previous()
   {
      
      setLists();
   }
}
  • May 08, 2021
  • Like
  • 1
Hello All,
I'm getting below error in my Apex. Please guide me.
Error: Compile Error: Constructor not defined: [TrainingDataWrapperController.wrapRecord].<Constructor>(Trainers_Detail__c) at line 13 column 36

line 13 ---> wrapRecordList.add(new wrapRecord(t));

================code===============

public class TrainingDataWrapperController {
 
    //Our collection of the class/wrapper objects wrapRecord 
    public List<wrapRecord> wrapRecordList{get; set;}
    public list<custobj1> obj1{get;set;}    
    public list<custobj2> obj2{get;set;} 
     
    public TrainingDataWrapperController (){
        if(wrapRecordList == null) {
            wrapRecordList = new List<wrapRecord>();
            for (custobj1 t: [Select Id, First_Name__c, Last_Name__c, Education__c, Technology__c ,(Select Name From custobj2) From custobj1 Limit 1]){
                // As each detail is processed we create a new wrapRecord object and add it to the wrapRecordList
                wrapRecordList.add(new wrapRecord(t));
            }
        }
    }
 
   
 
    // This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. 
    public class wrapRecord {
        public custobj1 td {get; set;}
        public custobj2 tdeal {get; set;}
 
        //This is the contructor method. When we create a new wrapRecord object.
        public wrapRecord (custobj1 tds,custobj2 tdeals) {
            td = tds;
            tdeal = tdeals;
        }
    }
}
  • May 08, 2021
  • Like
  • 0
Hello All,

I have created a visualforce page and apex which is used to calculate values and display in visualforce page. In a scenario, output text value has to be changed. I'm new to this. Kindly help.

<apex:page Controller="xxCalculator">
  <apex:form >
    <apex:pageBlock title="xx Calculator">
  <apex:pageBlockSection >
  <apex:inputText label="Number of 1:" value="{!num1}"/><br/>
  <apex:inputText label="Number of 2:" value="{!num2}"/><br/>
  <apex:commandButton value="Calculate" action="{!yyCalculate}" reRender="{!changeOutput}"/>
  </apex:pageBlockSection>
  </apex:pageBlock>
  
  <br/>
  <font color="red">
   HERE YOUR OUTPUT is:<apex:outputText value="{!output1}" />
   </font>
  </apex:form>
</apex:page>


================

public class xxCalculator{

public String changeOutput{ get; set; }
public integer num1{set;get;}
public integer num2{set;get;}
public integer output1{set;get;}
public void yyCalculate(){
    if(num1 == 1 && num2 == 1)
    {
        output1 = 0;
    }
   
    else if(num1 > 1 && num2 > 1 )
    {
        output1= (10 * num1) + (15 * num2);
    }
       
    }  
    public PageReference changeOutput(){
    if(output1 > 60)
    {
        output1 = 60;
    }
    
    return null;
    }  
    
}
                    
 
  • May 07, 2021
  • Like
  • 0
I have to set blue color to pageblock title font. kindly help. 

<apex:page Controller="xxxxx">
<apex:form >
<apex:pageBlock title="Calculator">
<apex:pageBlockSection >
==========
  • May 07, 2021
  • Like
  • 0
Here is my class:

public with sharing class BusinessUnitTriggerHandler 
{
    public static void checkDuplicate(List<BusinessUnits__c> units, Map<Id, BusinessUnits__c> oldMap, Boolean isInsert ) 
    {
      Map<String, Integer> businessUnitMap = new Map<String, Integer>();
      Set<String> lineOfBusiness = new Set<String>();
      Set<Id> contactIds = new Set<Id>();
      List<BusinessUnits__c> unitsToProcess = new List<BusinessUnits__c>();

      // Get System Admin profile Id
      Id profileId = [SELECT Id FROM Profile WHERE Name = 'System Administrator' LIMIT 1].Id;
      System.debug('UAC: profileId' + profileId);

      //Get current User Profile ID
      Id userProfileId = UserInfo.getProfileId() ;
    System.debug('UAC: userProfileId' + userProfileId);

    // Iterate over all business records 
        for( BusinessUnits__c bu : units )
        {  
          // When current user Non-Admin OR these fields are updated 
          if(  profileId != userProfileId &&
            ( isInsert || ( !isInsert && ( bu.LineOfBusiness__c != oldMap.get(bu.Id).LineOfBusiness__c || bu.Contact__c != oldMap.get(bu.Id).Contact__c))) ) 
          {
            lineOfBusiness.add(bu.LineOfBusiness__c);
            contactIds.add(bu.Contact__c);
            unitsToProcess.add(bu);
            businessUnitMap.put(bu.LineOfBusiness__c+bu.Contact__c, 0);
          }
        }
        System.debug('UAC: businessUnitMap' + businessUnitMap );
        if( businessUnitMap.size() == 0 ) return ;

        // Get existing Business records 
        for( BusinessUnits__c bu : [SELECT Id, LineOfBusiness__c, Contact__c FROM BusinessUnits__c 
                      WHERE Contact__c IN :contactIds AND LineOfBusiness__c IN :lineOfBusiness AND ID NOT IN :units ])
        {
          String key = bu.LineOfBusiness__c+bu.Contact__c;
          businessUnitMap.put( key, (businessUnitMap.get(key)+1) ) ;
        }
        System.debug('UAC: businessUnitMap' + businessUnitMap );
        if( businessUnitMap.size() == 0 ) return ;

        // Iterate again over inserted/updated records 
        for( BusinessUnits__c bu : unitsToProcess )
        {
          String key = bu.LineOfBusiness__c+bu.Contact__c;
          // When Already exists then show error
          if( businessUnitMap.containsKey(key) && businessUnitMap.get(key) > 0 ) bu.addError('Sorry. A Business Relationship for this Business Unit already exists for this Contact.');
        }
    }

    public static void changeOwner(List<BusinessUnits__c> units )
    {
        for(BusinessUnits__c bu : units )
        {
            if( bu.Sales_Rep__c != null && bu.OwnerId != bu.Sales_Rep__c  ) bu.OwnerId = bu.Sales_Rep__c ; 
        }
    }

    public static Map<String, BusinessUnitRulesManagement__c> lobAndUserRoleToBusinessUnitCS
    {
        get
        {
            if(lobAndUserRoleToBusinessUnitCS == null )
            {
                lobAndUserRoleToBusinessUnitCS = new Map<String, BusinessUnitRulesManagement__c>();
                for(BusinessUnitRulesManagement__c cs : BusinessUnitRulesManagement__c.getAll().values()) 
                {
                    lobAndUserRoleToBusinessUnitCS.put( cs.LineofBusiness__c + '' + cs.RoleDeveloperName__c, cs);
                }
            }
            //for(String key : lobAndUserRoleToBusinessUnitCS.keySet() ) System.debug('UAC: key ' + key  + ' value ' + lobAndUserRoleToBusinessUnitCS.get(key) );
            return lobAndUserRoleToBusinessUnitCS ;
        }
        private set ;
    }

    /**
    *   @Method:    updateContactFromCS()
    *   @Purpose:   When BusinessUnit is Updated then update SalesRep and EscrowOfficer fields from Contact based on Custom Setting fields 
    *   @Param:     List<BusinessUnits__c> units : List of new records - Trigger.new
    *               Map<Id,BusinessUnit__c> oldMap : map of old values - Trigger.oldMap
    *   @Return:    void : No return value
    *   @Date:      05/15/2017
    *
    *   @Updates: 
    */
    public static Boolean RUN_ONCE_UCFCS = true ; 
    public static void updateContactFromCS(List<BusinessUnits__c> units, Map<Id,BusinessUnits__c> oldMap, Boolean isInsert )
    {
        System.debug('UAC: BU updateContactFromCS START ' );
        Map<BusinessUnits__c, Id> businessUnitToContactId = new Map<BusinessUnits__c, Id>();
        Map<Id,Contact> existingContacts = new Map<Id,Contact>();
        Set<Id> contactIdsAddedForUpdate = new Set<Id>();
        List<Contact> contactsToUpdate = new List<Contact>();
        Set<Id> contactIds = new Set<Id>();
        Set<Id> userIds = new Set<Id>();
        Map<Id, String> userIdToUserRole = new Map<Id, String>();

        for(BusinessUnits__c bu : units)
        {
            BusinessUnits__c old =  !isInsert ? oldMap.get(bu.Id) : NULL ; 
            if( isInsert || ( !isInsert && (bu.Sales_Rep__c != old.Sales_Rep__c || bu.Escrow_Officer__c != old.Escrow_Officer__c)) ) 
            {
                if(bu.Sales_Rep__c != null ) userIds.add(bu.Sales_Rep__c);
                if(bu.Escrow_Officer__c != null && bu.Sales_Rep__c != bu.Escrow_Officer__c ) userIds.add(bu.Escrow_Officer__c);
                businessUnitToContactId.put(bu, bu.Contact__c);
                contactIds.add(bu.Contact__c);
            }
        }
        System.debug('UAC: businessUnitToContactId ' + businessUnitToContactId );

        for(User u : [SELECT Id, UserRole.DeveloperName FROM User WHERE ID IN :userIds ])
        {
            userIdToUserRole.put(u.Id, u.UserRole.DeveloperName );
        }
        System.debug('UAC: userIdToUserRole ' + userIdToUserRole );
        
        for(Contact con : Database.query( 'SELECT ' + getFields('Contact') + ' FROM Contact WHERE ID IN :contactIds ') )
        {
            existingContacts.put(con.Id, con);
        }

        for(BusinessUnits__c bu : businessUnitToContactId.keyset() )
        {
            String validUserRole = 
                //ContactTriggerHandler.currentUserRole == 'Administration' && 
                userIdToUserRole.containsKey(bu.Sales_Rep__c) ? userIdToUserRole.get(bu.Sales_Rep__c) : ContactTriggerHandler.currentUserRole ;

            // When no custom setting found for current User Role then Go Back
            if(!lobAndUserRoleToBusinessUnitCS.containsKey(bu.LineOfBusiness__c + '' + validUserRole)) continue ; 

            // Get Custom setting record
            BusinessUnitRulesManagement__c cs = lobAndUserRoleToBusinessUnitCS.get(bu.LineOfBusiness__c + '' + validUserRole);
            System.debug('UAC: cs ' + cs );

            if(cs == null ) continue ; 
            
            // Get related Contact 
            Contact con = existingContacts.get(businessUnitToContactId.get(bu));

            // When SalesRep or EscrowOfficer changed 
            if((bu.Sales_Rep__c != con.get(cs.SalesRepFieldonContactAPIName__c) || bu.Escrow_Officer__c != con.get(cs.EscrowOfficerFieldonContactAPIName__c) ) 
                    && !contactIdsAddedForUpdate.contains(con.Id) )
            {
                contactIdsAddedForUpdate.add(con.Id);
                Contact newContact = new Contact();
                newContact.Id = con.Id;
                System.debug('UAC: bu.Sales_Rep__c ' + bu.Sales_Rep__c );
                System.debug('UAC: bu.Escrow_Officer__c ' + bu.Escrow_Officer__c );
                if( !String.isBlank(cs.SalesRepFieldonContactAPIName__c)) newContact.put(cs.SalesRepFieldonContactAPIName__c, bu.Sales_Rep__c);
                if( !String.isBlank(cs.EscrowOfficerFieldonContactAPIName__c)) newContact.put(cs.EscrowOfficerFieldonContactAPIName__c, bu.Escrow_Officer__c);
                contactsToUpdate.add(newContact);
            } 
        }

        System.debug('UAC: contactsToUpdate ' + contactsToUpdate );

        // Update Contacts 
        if(contactsToUpdate.size() > 0 ) 
        {
            ContactTriggerHandler.RUN_ONCE_UBUFCS = false ;  
            BusinessUnitTriggerHandler.RUN_ONCE_UCFCS = false ;
            update contactsToUpdate ;
            ContactTriggerHandler.RUN_ONCE_UBUFCS = true ;  
            BusinessUnitTriggerHandler.RUN_ONCE_UCFCS = true ;
        }

        System.debug('UAC: BU updateContactFromCS END ' );
    
    }

    /**
    *   @Method:    getFields()
    *   @Purpose:   Use to get all fields of passing object  
    *   @Param:     String objName for which you want to get fields
    *   @Return:    Comma seprated fields
    *   @Date:      05/18/2017
    *
    *   @Updates: 
    */
    private static String getFields(String objectName)
    {
        //Broke this out of formatQuery because it could be used separately
        String fields = '';
        
        // Get All Objects List
        Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
        
        // Get object detail which passed as argument
        SObjectType objectType = gd.get(objectName);

        // Get passed object detail
        Schema.DescribeSObjectResult r = objectType.getDescribe();

        //Get all fields for passed object 
        Map<String, Schema.SObjectField> fieldMap = r.fields.getMap();

        // Itterate over all fields and check one by one 
        for (String f: fieldMap.keySet())
        { 
            // Get current field 
            Schema.SObjectField sof = fieldMap.get(f);
            // Get current field detail
            Schema.DescribeFieldResult dfr = sof.getDescribe();

            // when current field is accessible, creatable and defaultonCreare then concatinate in field string
            if( dfr.isAccessible() )
            {
                String fname = dfr.getName(); 
                fields += fname + ', '; 
            }
        }
        
        // remove last comma
        fields = fields.substring(0, fields.length() - 2);
        return fields;
    }


    public static Map<String, BusinessUnitRulesManagement__c> lobToBusinessUnitCS
    {
        get
        {
            if(lobToBusinessUnitCS == null )
            {
                lobToBusinessUnitCS = new Map<String, BusinessUnitRulesManagement__c>();
                for(BusinessUnitRulesManagement__c cs : BusinessUnitRulesManagement__c.getAll().values()) 
                {
                    if(!lobToBusinessUnitCS.containsKey(cs.LineofBusiness__c)) lobToBusinessUnitCS.put( cs.LineofBusiness__c, cs);
                }
            }
            //for(String key : lobToBusinessUnitCS.keySet() ) System.debug('UAC: key ' + key  + ' value ' + lobToBusinessUnitCS.get(key) );
            return lobToBusinessUnitCS ;
        }
        private set ;
    }

    /**
    *   @Method:    clearValueOnContact()
    *   @Purpose:   When BusinessUnit is Updated then update and clearOut SalesRep and EscrowOfficer fields from Contact based on Custom Setting fields 
    *   @Param:     List<BusinessUnits__c> units : List of new records - Trigger.new
    *               Map<Id,BusinessUnit__c> oldMap : map of old values - Trigger.oldMap
    *   @Return:    void : No return value
    *   @Date:      05/15/2017
    *
    *   @Updates: 
    */
    public static void clearValueOnContact(List<BusinessUnits__c> units)
    {
        System.debug('UAC: BU clearValueOnContact START ' );
     
        
     
        Map<Id, String> contactIdToLOB = new Map<Id, String>();
        Map<Id,Contact> contacts = new Map<Id,Contact>();

        // Iterate over BusinessUnit 
        for(BusinessUnits__c bu : units )
        {
            if(bu.Contact__c != null) contactIdToLOB.put(bu.Contact__c, bu.LineOfBusiness__c);
        }
        System.debug('UAC: BU contactIdToLOB ' + contactIdToLOB );
        if(contactIdToLOB.size() == 0) 
           return ; 

        // Get related Contacts 
        contacts = new Map<Id, Contact>( [SELECT Id FROM Contact WHERE ID IN :contactIdToLOB.keyset() ]);

        // Iterate over ContactIds 
        for(Id contactId : contactIdToLOB.keyset() )
        {   
            // Get Custom Setting Business Unit
            BusinessUnitRulesManagement__c cs = lobToBusinessUnitCS.get(contactIdToLOB.get(contactId));
            System.debug('UAC: cs ' + cs );

            if(cs == null ) continue ; 

            // Get Contact 
            Contact con = contacts.get(contactId);

            // Clear Out Values on Contact 
            if( !String.isBlank(cs.SalesRepFieldonContactAPIName__c)) con.put(cs.SalesRepFieldonContactAPIName__c, null);
            if( !String.isBlank(cs.EscrowOfficerFieldonContactAPIName__c)) con.put(cs.EscrowOfficerFieldonContactAPIName__c, null);
            System.debug('UAC: con ' + con );
        }

        // Update Contact
        ContactTriggerHandler.RUN_ONCE_UBUFCS = false ;
        update contacts.values() ;
        ContactTriggerHandler.RUN_ONCE_UBUFCS = true ; 

        System.debug('UAC: BU clearValueOnContact End ' );
    }

}

Test class:

@isTest
private class BusinessUnitTriggerHandlerTest 
{
      Map<String, Integer> businessUnitMap = new Map<String, Integer>();
      Set<String> lineOfBusiness = new Set<String>();
      Set<Id> contactIds = new Set<Id>();
      List<BusinessUnits__c> unitsToProcess = new List<BusinessUnits__c>();
      Set<Id> userIds = new Set<Id>();
      Map<Id, String> userIdToUserRole = new Map<Id, String>();
     Map<BusinessUnits__c, Id> businessUnitToContactId = new Map<BusinessUnits__c, Id>();
     Map<Id,Contact> existingContacts = new Map<Id,Contact>();
     Map<String, BusinessUnitRulesManagement__c> lobToBusinessUnitCS;
       Map<Id, String> contactIdToLOB = new Map<Id, String>();
        Map<Id,Contact> contacts = new Map<Id,Contact>();
    static testMethod void testCheckDuplicate() 
    {
         
   
        Profile profile = [Select Id from Profile where name = 'ORT Direct Sales User'];
        //UserRole ur = [Select Id from UserRole where UserRole.DeveloperName = 'Central_Direct_Agency'];

        User nonAdminUser = new User( ProfileId = profile.Id, Username = System.now().millisecond() + 'test2@test.com.dev',UserRoleId = '00E1G000000IWzyUAG',
                                    Alias = 'batman', Email='bruce.wayne@wayneenterprises.com', EmailEncodingKey='UTF-8',Firstname='Bruce',
                                    Lastname='Wayne',LanguageLocaleKey='en_US',LocaleSidKey='en_US',TimeZoneSidKey='America/Chicago' );
        System.runAs(new User( Id = UserInfo.getUserId() ))
        {
            Database.insert(nonAdminUser);
        }

        Account acc = TestUtility.createAccount( TestUtility.default_account_rt, false );
        acc.Name = 'sfdcpoint';
        acc.Account_Status__c = 'Active';
        acc.AccountNumber = '001';
        insert acc; 
    
        System.runAs(nonAdminUser)
        {
            Contact cont = TestUtility.createContact( TestUtility.default_contact_rt , acc, false ); 
            cont.MailingStreet = 'Test Street' ;
            cont.MailingCity = 'Minneapolis';
            cont.MailingState = 'MN';
            cont.MailingPostalCode = '55347';
            cont.MailingCountry = 'United States' ; 
            insert cont;
            
            
            BusinessUnitRulesManagement__c cs = new BusinessUnitRulesManagement__c();
            cs.Name = 'AgencyManager';
            cs.EscrowOfficerFieldonContactAPIName__c = 'Text';
            cs.LineofBusiness__c = 'testlob';
            cs.RoleDeveloperName__c = 'uniquetest';
            cs.SalesRepFieldonContactAPIName__c = 'conttext';
            cs.Status__c = 'alltext';
            insert cs;
            Id userId = UserInfo.getUserId() ;
          

            BusinessUnits__c bu = new BusinessUnits__c( Contact__c = cont.Id, LineOfBusiness__c = ' Agency',Sales_Rep__c = UserId );
          
            insert bu ; 
  
            try
            {
                BusinessUnits__c bu1 = new BusinessUnits__c( Contact__c = cont.Id,LineOfBusiness__c = 'Western Title Division',Sales_Rep__c = UserId  );
                insert bu1 ;  
            }
            catch(DmlException de )
            {

            } 
  

        }
    

    }