• Darshit Pathak 10
  • NEWBIE
  • 55 Points
  • Member since 2020

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 13
    Replies
Hello Experts,

I dont find any standard documentation on importing custom object and its field to import in lwc js.

Like how do we even import custom obect's picklist and show them on frontend? 

Can anyone help me with this?

Can someone look into this code and share what's wrong in this code?

LWC is hosted on an App Page. it shows the old Account name only unless page is refreshed, even after Account name is updated from Account Detail Page.

LWC.html

<template>
   <template lwc:if={accRec}>
      Acc Name: {name}
   </template>
</template>

LWC.js
import { getRecord, getFieldValue,notifyRecordUpdateAvailable } from 'lightning/uiRecordApi';
import ACC_NAME from '@salesforce/schema/Account.Name';
const fields = [ACC_NAME];
export default class Test_LWC extends LightningElement {
    recordId='0012w00001nF5DIAA0';
    @track accRec;
    @wire(getRecord,{recordId:'$recordId',fields})
    accRecFunc(result) {
        if(result.data != undefined) {
            this.accRec = result.data;
        }
    }
    get name() {
        return getFieldValue(this.accRec.data, ACC_NAME);
    }
channelName = '/event/Event1__e';
   
    connectedCallback() {
        this.subscribeEvent();
    }
    subscribeEvent() {
        const messageCallback = function (response) {
            console.log('in callback: '+JSON.stringify(response));
            console.log('before Notify');
            notifyRecordUpdateAvailable([{recordId:this.recordId}])
            .then((result) => {
                console.log('in notify then: '+JSON.stringify(result));
            })
            .catch((error)=> {
                console.log('in notify error: '+JSON.stringify(result));
            });
            console.log('after Notify');
        };
        subscribe(this.channelName, -1,messageCallback).then((response) => {
            console.log('in subscribe : '+JSON.stringify(response));
        });
    }
}

Account Trigger
trigger AccountTrigg on Account (after update) {
if (Trigger.isAfter) {
    Event1__e ev1 = new Event1__e();
    EventBus.publish(ev1);
}
}

As java provides multiple inheritance, so that class can inherit properties and methods of 2 different parent classes. But apex doesn't support that. Can anyone tell the conecpt/reason behind this?
I am creating a case through Digital site, on which Aura components are added for UI. When case is created through this portal, actual contact on case is different than expected. In debug log, at the end of Before Insert logic, contact is correct, but at the first line of after insert it has changed value. I am not able to understand where this value got changed between before and after insert?
There is an incoming email and case created through email-to-case.
Now we have one custom button (LWC), when user clicks on it, it should send email , but not as a new email , but as a reply to the incoming email. like a mail thread. Is it possible via Apex or WorkFlow or Process builder?
One batch is updating Case with some values.
Case trigger doesn't have any Database.DMLOptions code.
Checked in full trigger & related classes code and also not found any instance of DMLOPtions in debug log.
Still Assignment rules are getting executed and owner is changed.
2 weeks before it was not happening like this.Assignment rule was not getting fired.
Could anyone help with the possible root cause?
Assume A Lead record is inserted, in AfterInsert trigger code is written to populate some fields on the same lead, so update DML is performed on lead from AfterInsert trigger.
But on Update one custom validation rule is failed and error is thrown.
In such scenario the whole transaction should fail or only the Update part? 

I have created 1 default platform cache partition(genSys) with 5MB Session Cache.
Created 2 VF pages and one controller.

I am setting cache data on load of 1 VF Page and using that data in 2nd VF Page. But I lose data after 5 minutes. My understanding is that it should remain available 8 hours if browser is not closed during that period.
Can anyone help how can I maintain session cache for few hours?
 
Below is my code.
SessionHold.vfp
<apex:page controller="SessionHoldController" action="{!holdSeesionVars}">

</apex:page>

SesionGet.vfp
<apex:page controller="SessionHoldController" action="{!getSeesionVars}">
<h1>{!fnm} &nbsp; {!lnm}</h1>
</apex:page>

SessionHoldController.apxc
public with sharing class SessionHoldController {
    public static String fnm {get; set;}
    public static String lnm {get; set;}
    public SessionHoldController() {
    }
    public static void holdSeesionVars() {
        Cache.Session.put('local.gensysSession.firstName', 'ABC');
        String lnm = ApexPages.currentPage().getParameters().get('lnm');
        Cache.Session.put('local.gensysSession.lastName', lnm);
        System.debug(''+Cache.Session.MAX_TTL_SECS); //printing 28800
    }

    public static void getSeesionVars() {
        if (Cache.Session.contains('firstName')) {
            fnm = (String)Cache.Session.get('local.gensysSession.firstName');
        }
        if (Cache.Session.contains('lastName')) {
            lnm = (String)Cache.Session.get('local.gensysSession.lastName');
        }
        System.debug('Fnm: '+fnm+' lnm: '+lnm);
    }
}
 

I have written a webService for external system, while external system hit the sfdc to utilize the webSrive and suppose SOQL 101 or CPU time limit exception occured, so transaction fails right away there.
So is there any way I can send proper response in soap:fault format, to external system?
I had one trailhead account but it had email address of my previous organization. I had linked that trailhead account with webassessor.
I have created new trailhead account with my personal email address now. And merged the old trailhead account in new one.
So all badges and points are visible in new tarilhead account.
But webassessor is still linked to the old trailhead account only. So whichever maintenance exam I am completing is not reflecting in the results.
I tried to link the new(merged) trailhead account with webassessor but I am not getting any unique verification code on my email. So I am not able to link it.
Can anyone help me to link this new account and remove the old link?

Can someone look into this code and share what's wrong in this code?

LWC is hosted on an App Page. it shows the old Account name only unless page is refreshed, even after Account name is updated from Account Detail Page.

LWC.html

<template>
   <template lwc:if={accRec}>
      Acc Name: {name}
   </template>
</template>

LWC.js
import { getRecord, getFieldValue,notifyRecordUpdateAvailable } from 'lightning/uiRecordApi';
import ACC_NAME from '@salesforce/schema/Account.Name';
const fields = [ACC_NAME];
export default class Test_LWC extends LightningElement {
    recordId='0012w00001nF5DIAA0';
    @track accRec;
    @wire(getRecord,{recordId:'$recordId',fields})
    accRecFunc(result) {
        if(result.data != undefined) {
            this.accRec = result.data;
        }
    }
    get name() {
        return getFieldValue(this.accRec.data, ACC_NAME);
    }
channelName = '/event/Event1__e';
   
    connectedCallback() {
        this.subscribeEvent();
    }
    subscribeEvent() {
        const messageCallback = function (response) {
            console.log('in callback: '+JSON.stringify(response));
            console.log('before Notify');
            notifyRecordUpdateAvailable([{recordId:this.recordId}])
            .then((result) => {
                console.log('in notify then: '+JSON.stringify(result));
            })
            .catch((error)=> {
                console.log('in notify error: '+JSON.stringify(result));
            });
            console.log('after Notify');
        };
        subscribe(this.channelName, -1,messageCallback).then((response) => {
            console.log('in subscribe : '+JSON.stringify(response));
        });
    }
}

Account Trigger
trigger AccountTrigg on Account (after update) {
if (Trigger.isAfter) {
    Event1__e ev1 = new Event1__e();
    EventBus.publish(ev1);
}
}

I want to create the new custom field in the case object,In the custom field i need to add multiple email id.whenever the case is closed it should the email notification to the email id

kindly some one help me how to execute this scenario by using flow

i tried :
i used large text area to create the field.i'm using the flow to execute this task

i created new record trigger flow in after update.

User-added image

User-added image

User-added image

User-added image
User-added image

Hi 
I have created one batch class that contains the following code. I want to write one logic for sandbox and one for production.   
ObjectPermissions[] objectPermissionsArray = [SELECT Id,sObjectType,parentid FROM ObjectPermissions WHERE ParentId In '...'];    
  Organization org = [select Id, IsSandbox from Organization limit 1];  
 if(org.IsSandbox || test.isRunningTest()) {    //   sandbox code
 } 
else {
 // production code }

 In test class code coverage the else block is showing in red color. and code coverage is 78%. Same happen with following condition.    
if(!objectPermissionsArray.IsEmpty()){
     code
 }else{ code } 


  Test class 
  {  test.starttest();   
       database.executeBatch(new BatchJobname());       
  test.stoptest();
  }

 
In TriggerHandler i am getting 'FATAL_ERROR System.TypeException: Invalid conversion from runtime type Contact to REO_Application__c'
line number 15
REO_Application__c reo = (REO_Application__c)application;


Trigger:

trigger REOApplicationTrigger on REO_Application__c (before insert, before update, after update) {
    new REOApplicationTriggerHandler().run();
}

TriggerHandler :

public without sharing class REOApplicationTriggerHandler extends TriggerHandler {
    public REOApplicationTriggerHandler() {}
   
    override public void beforeInsert() {
        List<REO_Application__c> REOsToCreateContact = new List<REO_Application__c>();
        for(REO_Application__c reo : (List<REO_Application__c>)Trigger.new) {
            if(reo.Applicant_Contact__c == null) {
                REOsToCreateContact.add(reo);
            }                                                        
        }  
        if(!REOsToCreateContact.isEmpty()) {
            Map<SObject, Id> applicationContactIds = Utility.createContact(REOsToCreateContact, Utility.getContactFieldMapping('REO'));
            if(applicationContactIds != null) {
                for(SObject application : applicationContactIds.keySet()) {
                    REO_Application__c reo = (REO_Application__c)application;
                    reo.Applicant_Contact__c = applicationContactIds.get(reo);
                }                
            }          
        }
    }

Utility: getContactFieldMapping

  public static Map<String, String> getContactFieldMapping(String objType) {
        Map<String, String> fieldMap = new Map<String, String>();
        switch on objType {
            when 'REO' {
                fieldMap.put('Applicant_Last_Name__c', 'LastName');
                fieldMap.put('Applicant_Country__c', 'MailingCountry');
                fieldMap.put('Applicant_Postal_Code__c', 'MailingPostalCode');
                fieldMap.put('Applicant_Street__c', 'MailingStreet');
                fieldMap.put('Applicant_Mobile__c', 'MobilePhone');
                fieldMap.put('Applicant_NRIC_FIN__c', 'NRIC_FIN__c');
                fieldMap.put('Applicant_Phone__c', 'Phone');
                fieldMap.put('Date_of_Birth__c', 'Birthdate');                
                fieldMap.put('Gender__c', 'Gender__c');
                fieldmap.put('Applicant_Nationality__c', 'Nationality__c');
                fieldMap.put('Work_Permit_Expiry_Date__c', 'Work_Permit_Expiry_Date__c');
                fieldMap.put('Work_Permit_Number__c', 'Work_Permit_Number__c');
            }
            when 'RES' {
                fieldMap.put('Applicant_Last_Name__c', 'LastName');
                fieldMap.put('Applicant_Country__c', 'MailingCountry');
                fieldMap.put('Applicant_Postal_Code__c', 'MailingPostalCode');
                fieldMap.put('Applicant_Street__c', 'MailingStreet');
                fieldMap.put('Applicant_Mobile__c', 'MobilePhone');
                fieldMap.put('Applicant_NRIC_FIN__c', 'NRIC_FIN__c');
                fieldMap.put('Applicant_Phone__c', 'Phone');
                fieldMap.put('Date_of_Birth__c', 'Birthdate');                
                fieldMap.put('Gender__c', 'Gender__c');        
                fieldmap.put('Applicant_Nationality__c', 'Nationality__c');
                fieldMap.put('Work_Permit_Expiry_Date__c', 'Work_Permit_Expiry_Date__c');
                fieldMap.put('Work_Permit_Number__c', 'Work_Permit_Number__c');                
            }
            when else {
                return null;
            }
        }
        return fieldMap;
    }
Hello Experts,

I dont find any standard documentation on importing custom object and its field to import in lwc js.

Like how do we even import custom obect's picklist and show them on frontend? 

Can anyone help me with this?
Hi I have a apex class 'XLSXGenerator' which contains a method generate. When I insert XLSXGenerator.generate(new List<String>); in the execute Apex in Workbench, i get an xlsx as result. But I would like to trigger it with a visualforce button instead of workbench. Could you tell me how i can achive this?

My apex class:
 
public class XLSXGenerator {

    public PageReference generate() {
        return null;
    }

    //public static String generate(List<String> textList) {
    public static String generate(List<String> AccList) {
        // Build XLSX File Content
        PageReference xlsxTemplate = page.XLSXTemplate;
    //    xlsxTemplate.getParameters().put('textList', System.JSON.serialize(textList));
        xlsxTemplate.getParameters().put('AccList', System.JSON.serialize(AccList));
        Blob xlsxContent;
        if (Test.isRunningtest()) {
            xlsxContent = Blob.valueOf('Sample');
        } else {
            xlsxContent = xlsxTemplate.getContent();
        }
        // Build XLSX File Frame
        StaticResource xlsxTemplateFrame = [SELECT Body FROM StaticResource WHERE Name = 'XLSXTemplateFrame' LIMIT 1];
        Zippex xlsx = new Zippex(xlsxTemplateFrame.Body);
        // Add the Content to the Frame to complete the File
        xlsx.addFile('xl/worksheets/sheet1.xml', xlsxContent, null);
        // Save XLSX File 
        ContentVersion cv = new ContentVersion();
        String title = 'XLSXExample';
        cv.Title = title;
        cv.PathOnClient = title + ' - ' + DateTime.now() + '.xlsx';
        cv.VersionData = xlsx.getZipArchive();
        insert cv;
        Id contentDocumentid = [SELECT Id FROM ContentDocument WHERE LatestPublishedVersionId = :cv.Id].Id;
        return URL.getOrgDomainUrl().toExternalForm() + '/sfc/servlet.shepherd/document/download/' + contentDocumentid;
    }

}

 
Hi
I have created an aura component which returns the records in a grid of tiles. However, I would like to set the title of the tile as a url to the returned record. I cant quite get this to work. My current code is below:

Apex Class:
public with sharing class getknowledgearticles {
    @AuraEnabled
    public static List<Knowledge__kav> getknowledge() {
        return [SELECT Id, ArticleTotalViewCount, ArticleCreatedDate,     Group__c,     Full_Description__c, IsLatestVersion,    PublishStatus,     Summary, Title FROM Knowledge__kav WHERE  PublishStatus='Online'AND Group__c includes ('General Information')];
    }
}

CMP:
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" controller ="getknowledgearticles" access="global" >
    
    <aura:attribute name="mydataLst" type="Object"/>
     <aura:handler name="init" value="{! this }" action="{! c.init }"/>
  <lightning:layout multipleRows="true">  
    <aura:iteration items="{!v.mydataLst}" var="records" >
       
      <lightning:layoutItem padding="around-small" size="6">  
        <div id="Tilu" class="slds-box">
            <lightning:tile label="{!records.Title}">
                <div class="slds-media__figure">
      <span class="slds-avatar slds-avatar_circle slds-avatar_large">
        <img alt="" src="/resource/1652857196000/info?" title="General Information" />
                    </span></div>
                <dl class="slds-dl_horizontal">
                    <dt class="slds-dl_horizontal__label">
                        <p class="slds-wrap">{!records.Group__c}</p>
                    </dt>
                    <dd class="slds-dl_horizontal__detail slds-tile__meta">
                        <p class="slds-wrap">{!records.Summary}</p>
                    </dd>
               
                  
                </dl>
            </lightning:tile>
        </div> 
       </lightning:layoutItem>
    </aura:iteration>
 </lightning:layout>
</aura:component>

JS CONTROLLER:
({
    init: function (cmp, event, helper) {
         cmp.set('v.records', [
            {label: 'Title', fieldName: 'linkTitle', type: 'url', 
            typeAttributes: {label: { fieldName: 'Title' }, target: '_blank'}}   ]);
        var action=cmp.get('c.getknowledge');
        action.setCallback(this,$A.getCallback(function(response){
            var state=response.getState();
            if(state==="SUCCESS"){
                var oResponse=response.getReturnValue();
                oResponse.forEach(function(record){
                    record.linkTitle = '/'+record.Id;
                });
                cmp.set("v.mydataLst",oResponse);
            }else if(state==="ERROR"){
                var errors=response.getError();console.error(errors);
          }
        }
         ));
        $A.enqueueAction(action);
    },
})

Hi,

I want to know whether we can add a custom formula field to the User detail/edit page?

I am talking about user page. Setup-Quick find-User-Select one user and click on edit.

once we click edit we go to one page which i have attached below.can we add custom formulae field in that?

User detail page

 

Please tell me different approaches of dealing with this issue. 

If the callout is from UI (button) or a flow (external service), the response data is invalid and there is a valdation rule on that field (response data), same transaction and user is expecting to see the result on UI.
I can have custom object which stores the failed data, but how about saving the record in this instance since validation rule doesn't let us?

I am looking for approaches to save the record when we have a validation rule instead of using code.

I can think of two ways to save the record: 
1. In the validation rule: which lets the record to be saved if the field is blank. For example having CONTAINS OR BEGINS functions in the formula. 
2. Instead of a validation rule, no code, we can do the callout from apex and have the validation there, if there is invalid or failed validation, to manipulate the data to allow the record to be saved. 



 
One batch is updating Case with some values.
Case trigger doesn't have any Database.DMLOptions code.
Checked in full trigger & related classes code and also not found any instance of DMLOPtions in debug log.
Still Assignment rules are getting executed and owner is changed.
2 weeks before it was not happening like this.Assignment rule was not getting fired.
Could anyone help with the possible root cause?

I have created 1 default platform cache partition(genSys) with 5MB Session Cache.
Created 2 VF pages and one controller.

I am setting cache data on load of 1 VF Page and using that data in 2nd VF Page. But I lose data after 5 minutes. My understanding is that it should remain available 8 hours if browser is not closed during that period.
Can anyone help how can I maintain session cache for few hours?
 
Below is my code.
SessionHold.vfp
<apex:page controller="SessionHoldController" action="{!holdSeesionVars}">

</apex:page>

SesionGet.vfp
<apex:page controller="SessionHoldController" action="{!getSeesionVars}">
<h1>{!fnm} &nbsp; {!lnm}</h1>
</apex:page>

SessionHoldController.apxc
public with sharing class SessionHoldController {
    public static String fnm {get; set;}
    public static String lnm {get; set;}
    public SessionHoldController() {
    }
    public static void holdSeesionVars() {
        Cache.Session.put('local.gensysSession.firstName', 'ABC');
        String lnm = ApexPages.currentPage().getParameters().get('lnm');
        Cache.Session.put('local.gensysSession.lastName', lnm);
        System.debug(''+Cache.Session.MAX_TTL_SECS); //printing 28800
    }

    public static void getSeesionVars() {
        if (Cache.Session.contains('firstName')) {
            fnm = (String)Cache.Session.get('local.gensysSession.firstName');
        }
        if (Cache.Session.contains('lastName')) {
            lnm = (String)Cache.Session.get('local.gensysSession.lastName');
        }
        System.debug('Fnm: '+fnm+' lnm: '+lnm);
    }
}