• Phuc Nguyen 18
  • NEWBIE
  • 340 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 58
    Questions
  • 90
    Replies
Hello ALl,
trying to determine if I cna create an alpha numeric field via a formula or if it need sot be done in apex.
So what I am looking at is if the record type is 'Site' then the field needs to be 'S_(postalcode value on record)_incremented number
ex. S_14547_1
Next record with type site and postal code 45447 woueld be
S_45447_2

Thanks,
P
Trying to update lookup on record after child created.
So in the andFinally method, I am inserting the Project record.  I now want to take the id from the new project and use it to update the lookup on the Permit record.  But I am geting errors.  For starters it doe snot see the id field in teh andfinally method. ANy suggestions is appreciated
P
 
List<Project__c> permitProjectsToCreate = new List<Project__c>();
Project_Template__c permitTemplate;

public void initialize( String sObjectName ){
    
 List<Id> permitIds = new List<Id>();
     for Permit__c permit: trigger.New)
     {
        permitIds.add (permit.id);   
      }

    if( Trigger.isAfter && this.permitTemplate == null ){
        List<Project_Template__c> templates = [
            SELECT Id FROM Project_Template__c WHERE Name =: 'Permit Project' LIMIT 1
        ];

        if( !templates.isEmpty() ){
            this.permitTemplate = templates[ 0 ];
        }
    }

}

public void afterInsert( SObject so ){
    Permit__c newPermit = ( Permit__c ) so;
    

    if( permitTemplate != null ){
        permitProjectsToCreate.add( new Project__c(
            Permit__c = so.Id,
            ProjectTemplate__c = permitTemplate.Id
        ));
    }

}

public void andFinally(){

    if( Trigger.isInsert && !this.permitProjectsToCreate.isEmpty() ){
        insert this.permitProjectsToCreate;
    permitIds.project__c =         
    permitProjectsToCreate.id
    }        
}

 
Hello All,
Looking to get the Recordtype off an objetc but was wondering what woul di do if the name was changed?
 
accountRTId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('First load').getRecordTypeId();
Is there a better way to do this to make sure this doe snot throw an exception if a user changes the name?

Thanks,
P
 

Hello All,
How can I retrieve specific custom metadata records from an org.
I use this syntax for specifc fields

sfdx force:source:retrieve -m CustomField:Object.CustomField__c

But what is the syntax for a custom metadata record?

Thanks,
P

Trying to populate lookup Planning_Application__c and Project_ID but getting erro Variable does not exist at newpl.Planning_Application__c and newproj.Project_ID__c
public set<id> planId = new Set<id>();
public set<id> projId = new Set<id>();
public list<Action_Item__c> pl;
public list<Action_Item__c> pj;
public list<Project__c> lu;
public list<Planning_Application__c> lu2;


public void initialize(String sObjectName) {
        if (!Trigger.isDelete) {
            for (SObject ids : Trigger.new) {
                Action_Item__c action = (Action_Item__c) ids;
                if (action.Planning_Application__c != null) {
                    planId.add(action.Planning_Application__c);
                }
                if (action.Project_ID__c != null) {
                    projId.add(action.Project_ID__c);
                }
            }
        }
    }

 public void bulkAfter() {
        if (!Trigger.isDelete) {
            if (Trigger.isInsert) {
                lu = [
                    SELECT
                        Id,
                        Name
                    FROM Project__c
                    WHERE id IN :projId
                ];
            }
        }
        if (!Trigger.isDelete) {
            if (Trigger.isInsert) {
                lu2 = [
                    SELECT
                        Id,
                        Name
                        FROM Planning_Application__c
                    WHERE id IN :planId
                ];
            }
        }

    }


 public void afterInsert(SObject so) {
    List<Project__c> newproject = lu;
    List<Planning_Application__c> newaplan = lu2;

    For(Project__c newproj : newproject){
    for (Action_Item__c act1 : newproj.Action_Items__r)
    {
        if (newproj.Project_ID__c != null) {
            act1.Project_ID__c = newproj.Project_ID__c;
        }
    }
    }
    
    For(Planning_Application__c newpl : newplan){
            for (Action_Item__c act2 : newpl.Actions__r)
        {
            act2.Planning_Application__c = newpl.Planning_Application__c;
        }
    }
    }

 
I am unable to pull in the parent field(Lease__c) for my LWC

HTML
<template>
    <lightning-record-edit-form record-id={recordId} object-api-name="Lease_Payment_Term__c"
    onsuccess={handleSuccess} onsubmit ={handleSubmit}>
<lightning-messages>
</lightning-messages>
<lightning-output-field field-name="Lease__c">
</lightning-output-field>

 JS
import { LightningElement,wire, track } from 'lwc';
import { getPicklistValues } from 'lightning/uiObjectInfoApi';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import Lease_Payment from '@salesforce/schema/Lease_Payment__c';
import Lease_Payment_Term from '@salesforce/schema/Lease_Payment_Term__c';

 
LWC renders first and last radio button groups fine but but none in between. If I reference 1 or 2 picklist group I am ok but 3 or more none of the picklist in in the middle render any values.
 
import { LightningElement,wire, track } from 'lwc';
import { getPicklistValues } from 'lightning/uiObjectInfoApi';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import LEASE_OBJECT from 
'@salesforce/schema/Lease_Payment_Term__c';
import Accounting_Type from 
'@salesforce/schema/Lease_Payment_Term__c.Accounting_Type__c';
import Type__c from '@salesforce/schema/Lease_Payment_Term__c.Type__c';

export default class GetPickListValueInLWC extends LightningElement {

@track selectedValue;
@track options = [];
@track options1 = [];
@track options2 = [];

@wire(getObjectInfo, { objectApiName: LEASE_OBJECT })
objectInfo;

@wire(getPicklistValues, {
    recordTypeId: '$objectInfo.data.defaultRecordTypeId', fieldApiName : 
Accounting_Type
}) ATPicklistValues ({error, data}) {
    if(data) {
        let optionsValues = [];
        for(let i = 0; i < data.values.length; i++) {
            optionsValues.push({
                label: data.values[i].label,
                value: data.values[i].value
            })
        }
        this.options = optionsValues;
        window.console.log('optionsValues ===> '+JSON.stringify(optionsValues));
    }
    else if(error) {
        window.console.log('error ===> '+JSON.stringify(error));
    }
   }


@wire(getPicklistValues, {
    recordTypeId: '$objectInfo.data.defaultRecordTypeId',  
    fieldApiName : Type__c
}) TPicklistValues ({error, data}) {
    if(data) {
        let optionsValues = [];
        for(let i = 0; i < data.values.length; i++) {
            optionsValues.push({
                label: data.values[i].label,
                value: data.values[i].value
            })
        }
        this.options1 = optionsValues;
        window.console.log('optionsValues ===> 
'+JSON.stringify(optionsValues));
    }
    else if(error) {
        window.console.log('error ===> '+JSON.stringify(error));
    }
}

 @wire(getPicklistValues, {
     recordTypeId: '$objectInfo.data.defaultRecordTypeId', fieldApiName : Payment_Frequency
 }) TPicklistValues ({error, data}) {
     if(data) {
         let optionsValues = [];
         for(let i = 0; i < data.values.length; i++) {
             optionsValues.push({
                 label: data.values[i].label,
                 value: data.values[i].value
             })
         }
         this.options2 = optionsValues;
         window.console.log('optionsValues ===> '+JSON.stringify(optionsValues));
     }
     else if(error) {
         window.console.log('error ===> '+JSON.stringify(error));
     }
 }


HTML

<template>
<lightning-record-edit-form record-id={recordId} object-api-name="Lease_Payment_Term__c"
onsuccess={handleSuccess} onsubmit ={handleSubmit}>
<lightning-messages>
</lightning-messages>
<lightning-output-field field-name="Lease__c">
</lightning-output-field>
<lightning-input-field field-name="Name">
</lightning-input-field>
<lightning-radio-group name="ATradioGroup" if:true={wiredPicklistValues.data}
                      label="Accounting Type"
                      options={options}
                      value={value}
                      type="radio">
</lightning-radio-group>
<lightning-radio-group name="TradioGroup"
                      label="Type"
                      options={options1}
                      value={value}
                      type="radio">
</lightning-radio-group>
<lightning-radio-group name="PaymentradioGroup"
                      label="Payment Frequency"
                      options={options2}
                      value={selectedValue}
                      onchange={handleChange2}
                      type="radio">
</lightning-radio-group>

​​​​​​​
Trying to show fields base don radio button selection:  I know this works but its for any value selected.  How can I make it work for a specific radion button value?
<lightning-radio-group name="TradioGroup"
                          label="Type"
                          options={options1}
                          value={selectedValue}
                          onchange={handleChange1}
                          type="radio">
</lightning-radio-group>
<div if:true={selectedValue}></div>
    <lightning-input-field field-name="Amount__c">
    </lightning-input-field>
</div>

 
Hello all,
I am overriding the new button on a cusotm object .  I am referencing an aura component that has an embedded LWC.  The page now is the same size as the record page.  Can I make the page smaller?  Is this comtrolled by the LWC or Aura component?
Hello All,
I need help rendering picklist values as radion buttons.  This will be on a LWC with input fields.  So the selected radion button will need to match the picklist value when the record is saved.
Thank you,
 P
In an apex class I am trying to update a couple field on a child record from the parent when the child record is created.
Any suggestion is appreciated.
Thanks
I was wondering.  Can an apex class(sharing class) be used to set the fields on a standard lightning record page read or edit based on a formula field on the record?  I create a checkbox that is set to true if the logged in user is not equal to a field on the record. Just wondering if an apex class can be used since I was unable to used a sharing rule.
Thank you,
P
Hello All,
I was wondering, from a previous post I was using a VF page and aura compont and trying to control field access based on the logged in user.  Is this easier to accomplish in a lightning web component?  I see examples of gettign the logged in user infor but was wonder if I could grab the logged in users Name and  compare it to a picklist field.  If the user and picklist value matches they can edit certain fields.  Else its read only.  I know there is a readonly property on the input field but how can I make that a condiiton based on the logged in user(compare to picklist value).  Or if you have another way to accomplish this let me know.

Thank you,
P
Hello Alll,

I am trying to create a trigger handler class to update records based on the field values from another object record.  But there is no direct relationship between the 2  objects.  Do I have have to create a relationship between them?
  • Object 1 lookup to obejct 3
  • Object 2 lookup to object 1
  • Object 3

I am trying to take the fields from object 3(only 1 record) and match them to the name of the records of object 2.
So field on obect 3 records are called
  • 'big dog - old' 
  • 'big cat - young'
  • small pig - old'
Name of records for obejct 2 are
  • record name is 'big dog' 
  • record name is 'big cat'
  • record name is 'small pig'
How do I do this when there is no direct relationship between the 2 objects.  Object 3 is a lookup on Object 1 and object 2 are children records of object 1? 

Thank you,
P
Hello,
I have a apex component where I need to make some of the fields read only based on the logged in user.
<apex:outputfield value="{!Account.Agent__c}" />
Can I use an if statement like
If(($User.FirstName + " " +$User.LastName) != Text(Buyer__c)
make the agent field read only?
Thanks,
P
 
Hello All,
I am hoping you can help me with this issue.
I have 2 custom objects.
Custom object A has fields quatity and estimate
Custom object B has field price.
Custom object A has a Lookup to Custom Objetc B.
So when a user enters a quantity on a custom object A fields, I need to go to custom object B and grab the price for those fields.  Bring it back and multiply the value retrieved by the quantity to get the estimate.
So in the Class(already have a trigger and other classes for theis object) what is the best approach to make sure the update works not only on single record edits but during large data loads .  My issue is that a user can edit up to 20 fields on record A and I am not sure how to update all of them all at once.
Thank you,
P
Hello,
I was wondering.  What is the best way to get the record from a list based on the currecnt record.
For example I have this list where I am grabbing all the records where the ProjectT Name is 'Closed Templates'
cprojects = [SELECT Id, ProjectT__r.Name, Cand_Project__c,Cand__c 
                FROM Project__c WHERE  ProjectT__r.Name =: 'Closed Templates'];
In a nother method how can I grab the the record/field from the list based on the current record.  What I am trying to go is query all of the records that meet the criteria so that I only have to query it once in the class but need to be able to get a record from list based on the current record being updated.
Thanks,
P
Hello all,
I am trying to send out emais when the record meets a specific criteria and I need to use an exsiting email template.  How do I use the template and make sure I am grabbing the fields for the tempalte?
global class UpdateAccountBillingState implements Database.Batchable<sObject>, Database.Stateful {
    global Database.QueryLocator start(Database.BatchableContext bc) {
        return Database.getQueryLocator(
            'SELECT notifydate__c FROM Account Where notifydate__c != null'
        );
    }
    global void execute(Database.BatchableContext bc, List<Account> scope){
        // process each batch of record
        List<Account> lstacc = new List<Account>();       
        for (Account acc : scope) {
            acc.notifydate__c = today();
            lstacc.add(acc);  
        }   
        update lstacc;
    }   
    global void finish(Database.BatchableContext bc){
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
      
    }   
     
}

 
Hello All,
I am trying to create an Ppex Class that creates a child record(asset__c) when the parent record(Warehouse__c) field(approved__c) is set to true. 
How do I make sure its bulkified so when the customer does a dataload there will not be an issue.
Thank you,
P
I would like to send an email with the attchment that associated with the record when a field is updated on the record.
Thanks,
P
Hello ALl,
trying to determine if I cna create an alpha numeric field via a formula or if it need sot be done in apex.
So what I am looking at is if the record type is 'Site' then the field needs to be 'S_(postalcode value on record)_incremented number
ex. S_14547_1
Next record with type site and postal code 45447 woueld be
S_45447_2

Thanks,
P
Trying to update lookup on record after child created.
So in the andFinally method, I am inserting the Project record.  I now want to take the id from the new project and use it to update the lookup on the Permit record.  But I am geting errors.  For starters it doe snot see the id field in teh andfinally method. ANy suggestions is appreciated
P
 
List<Project__c> permitProjectsToCreate = new List<Project__c>();
Project_Template__c permitTemplate;

public void initialize( String sObjectName ){
    
 List<Id> permitIds = new List<Id>();
     for Permit__c permit: trigger.New)
     {
        permitIds.add (permit.id);   
      }

    if( Trigger.isAfter && this.permitTemplate == null ){
        List<Project_Template__c> templates = [
            SELECT Id FROM Project_Template__c WHERE Name =: 'Permit Project' LIMIT 1
        ];

        if( !templates.isEmpty() ){
            this.permitTemplate = templates[ 0 ];
        }
    }

}

public void afterInsert( SObject so ){
    Permit__c newPermit = ( Permit__c ) so;
    

    if( permitTemplate != null ){
        permitProjectsToCreate.add( new Project__c(
            Permit__c = so.Id,
            ProjectTemplate__c = permitTemplate.Id
        ));
    }

}

public void andFinally(){

    if( Trigger.isInsert && !this.permitProjectsToCreate.isEmpty() ){
        insert this.permitProjectsToCreate;
    permitIds.project__c =         
    permitProjectsToCreate.id
    }        
}

 
LWC renders first and last radio button groups fine but but none in between. If I reference 1 or 2 picklist group I am ok but 3 or more none of the picklist in in the middle render any values.
 
import { LightningElement,wire, track } from 'lwc';
import { getPicklistValues } from 'lightning/uiObjectInfoApi';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import LEASE_OBJECT from 
'@salesforce/schema/Lease_Payment_Term__c';
import Accounting_Type from 
'@salesforce/schema/Lease_Payment_Term__c.Accounting_Type__c';
import Type__c from '@salesforce/schema/Lease_Payment_Term__c.Type__c';

export default class GetPickListValueInLWC extends LightningElement {

@track selectedValue;
@track options = [];
@track options1 = [];
@track options2 = [];

@wire(getObjectInfo, { objectApiName: LEASE_OBJECT })
objectInfo;

@wire(getPicklistValues, {
    recordTypeId: '$objectInfo.data.defaultRecordTypeId', fieldApiName : 
Accounting_Type
}) ATPicklistValues ({error, data}) {
    if(data) {
        let optionsValues = [];
        for(let i = 0; i < data.values.length; i++) {
            optionsValues.push({
                label: data.values[i].label,
                value: data.values[i].value
            })
        }
        this.options = optionsValues;
        window.console.log('optionsValues ===> '+JSON.stringify(optionsValues));
    }
    else if(error) {
        window.console.log('error ===> '+JSON.stringify(error));
    }
   }


@wire(getPicklistValues, {
    recordTypeId: '$objectInfo.data.defaultRecordTypeId',  
    fieldApiName : Type__c
}) TPicklistValues ({error, data}) {
    if(data) {
        let optionsValues = [];
        for(let i = 0; i < data.values.length; i++) {
            optionsValues.push({
                label: data.values[i].label,
                value: data.values[i].value
            })
        }
        this.options1 = optionsValues;
        window.console.log('optionsValues ===> 
'+JSON.stringify(optionsValues));
    }
    else if(error) {
        window.console.log('error ===> '+JSON.stringify(error));
    }
}

 @wire(getPicklistValues, {
     recordTypeId: '$objectInfo.data.defaultRecordTypeId', fieldApiName : Payment_Frequency
 }) TPicklistValues ({error, data}) {
     if(data) {
         let optionsValues = [];
         for(let i = 0; i < data.values.length; i++) {
             optionsValues.push({
                 label: data.values[i].label,
                 value: data.values[i].value
             })
         }
         this.options2 = optionsValues;
         window.console.log('optionsValues ===> '+JSON.stringify(optionsValues));
     }
     else if(error) {
         window.console.log('error ===> '+JSON.stringify(error));
     }
 }


HTML

<template>
<lightning-record-edit-form record-id={recordId} object-api-name="Lease_Payment_Term__c"
onsuccess={handleSuccess} onsubmit ={handleSubmit}>
<lightning-messages>
</lightning-messages>
<lightning-output-field field-name="Lease__c">
</lightning-output-field>
<lightning-input-field field-name="Name">
</lightning-input-field>
<lightning-radio-group name="ATradioGroup" if:true={wiredPicklistValues.data}
                      label="Accounting Type"
                      options={options}
                      value={value}
                      type="radio">
</lightning-radio-group>
<lightning-radio-group name="TradioGroup"
                      label="Type"
                      options={options1}
                      value={value}
                      type="radio">
</lightning-radio-group>
<lightning-radio-group name="PaymentradioGroup"
                      label="Payment Frequency"
                      options={options2}
                      value={selectedValue}
                      onchange={handleChange2}
                      type="radio">
</lightning-radio-group>

​​​​​​​
Trying to show fields base don radio button selection:  I know this works but its for any value selected.  How can I make it work for a specific radion button value?
<lightning-radio-group name="TradioGroup"
                          label="Type"
                          options={options1}
                          value={selectedValue}
                          onchange={handleChange1}
                          type="radio">
</lightning-radio-group>
<div if:true={selectedValue}></div>
    <lightning-input-field field-name="Amount__c">
    </lightning-input-field>
</div>

 
Hello All,
I need help rendering picklist values as radion buttons.  This will be on a LWC with input fields.  So the selected radion button will need to match the picklist value when the record is saved.
Thank you,
 P
In an apex class I am trying to update a couple field on a child record from the parent when the child record is created.
Any suggestion is appreciated.
Thanks
Hello Alll,

I am trying to create a trigger handler class to update records based on the field values from another object record.  But there is no direct relationship between the 2  objects.  Do I have have to create a relationship between them?
  • Object 1 lookup to obejct 3
  • Object 2 lookup to object 1
  • Object 3

I am trying to take the fields from object 3(only 1 record) and match them to the name of the records of object 2.
So field on obect 3 records are called
  • 'big dog - old' 
  • 'big cat - young'
  • small pig - old'
Name of records for obejct 2 are
  • record name is 'big dog' 
  • record name is 'big cat'
  • record name is 'small pig'
How do I do this when there is no direct relationship between the 2 objects.  Object 3 is a lookup on Object 1 and object 2 are children records of object 1? 

Thank you,
P
Hello All,
I am hoping you can help me with this issue.
I have 2 custom objects.
Custom object A has fields quatity and estimate
Custom object B has field price.
Custom object A has a Lookup to Custom Objetc B.
So when a user enters a quantity on a custom object A fields, I need to go to custom object B and grab the price for those fields.  Bring it back and multiply the value retrieved by the quantity to get the estimate.
So in the Class(already have a trigger and other classes for theis object) what is the best approach to make sure the update works not only on single record edits but during large data loads .  My issue is that a user can edit up to 20 fields on record A and I am not sure how to update all of them all at once.
Thank you,
P