• KevanM
  • 0 Points
  • Member since 2015
  • Salesforce Architect
  • SharinPix

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
  • 2

I am encountering an issue with LWC where is it working fine on a record page in Lightning but does not work on Community. 

I am using a public api and in the design property, I am using a datasource which is basically looking for all STRING field on the current object. On a record page in lightning, if I am on an account, it is working fine and the entity context is returning 'Account' but when I am on community and try to add the LWC on the record page, it is returning a null entity context.

Below is a simple lwc to reproduce this issue. 

Drag and drop on an Account page in lightning, in the design you should be able to see a list of field. Do same on community, no field will appear and you will have an error in the debug. Attempt to de-reference a null object on this line : dynamicPicklistValues = new DynamicPicklistValues(String.valueOf(context.entityName), 'STRING');
public with sharing class DynamicPicklistValues {

    private Map<String, String> fieldNamesToLabels;
    private String defaultField;

    public DynamicPicklistValues(String objectApiName, String fieldType) {
        Map<String, Schema.SObjectField> objectFieldsDescribe = Schema.getGlobalDescribe().get(objectApiName).getDescribe().fields.getMap(); 
        defaultField = null;
        fieldNamesToLabels = new Map<String, String>();
        for (Schema.sObjectField fieldObject: objectFieldsDescribe.values()) {
            Schema.DescribeFieldResult fieldDescription = fieldObject.getDescribe();
            if (fieldType(fieldDescription) == fieldType) {
                fieldNamesToLabels.put(fieldDescription.getName(), fieldDescription.getLabel());
                if (String.isBlank(defaultField)) {
                    defaultField = fieldDescription.getName();

    public VisualEditor.DataRow getDefaultValue() {
        VisualEditor.DataRow defaultValue = new VisualEditor.DataRow('', '');
        if (!String.isBlank(defaultField)) {
            defaultValue = new VisualEditor.DataRow(defaultField, defaultField);
        return defaultValue;

    public VisualEditor.DynamicPickListRows getValues() {
        VisualEditor.DynamicPickListRows pickListRows = new VisualEditor.DynamicPickListRows();
        for (String fieldApiName : fieldNamesToLabels.keySet()) {
            pickListRows.addRow(new VisualEditor.DataRow(fieldApiName, fieldApiName));
        return pickListRows;

    private string fieldType(Schema.DescribeFieldResult fieldDescription) {
        if (String.valueOf(fieldDescription.getType()) == 'string' && !fieldDescription.isCalculated()) { return 'STRING'; }
        if (String.valueOf(fieldDescription.getType()) == 'url') { return 'URL'; }
        if (String.valueOf(fieldDescription.getType()) == 'textarea' && fieldDescription.getLength() >= 256 && fieldDescription.isHtmlFormatted()) { return 'RICHTEXT'; }
        return null;

public with sharing class FieldPicklistDatasource  extends VisualEditor.DynamicPickList {

    private DynamicPicklistValues dynamicPicklistValues;
    private VisualEditor.DynamicPickListRows pickListRows;
    private List <VisualEditor.DataRow> dataRows;
    private VisualEditor.DataRow defaultValue;

    public FieldPicklistDatasource(VisualEditor.DesignTimePageContext context) {
        defaultValue = new VisualEditor.DataRow('None', 'None');
        dynamicPicklistValues = new DynamicPicklistValues(String.valueOf(context.entityName), 'STRING');
        pickListRows = dynamicPicklistValues.getValues();
        dataRows = pickListRows.getDataRows();
        pickListRows = new VisualEditor.DynamicPickListRows();
        for (VisualEditor.DataRow dataRow : dataRows) {

    public override VisualEditor.DataRow getDefaultValue() {
        return defaultValue;

    public override VisualEditor.DynamicPickListRows getValues() {
        return pickListRows;
// LWC SimpleButton

    <button class="slds-button slds-button_brand slds-button_stretch slds-p-vertical_xx-small">{selectedField}</button>


import { LightningElement, api } from 'lwc';

export default class SimpleButton extends LightningElement {

    @api selectedField


<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
        <targetConfig targets="lightning__RecordPage, lightningCommunity__Default">
            <property name="selectedField" label="Select a field" description="" type="String" datasource="apex://FieldPicklistDatasource"/>

If anyone has any idea on how this can be resolve, let me know in the comment. 


  • January 14, 2020
  • Like
  • 0
If you have a lightning component on a layout of a subtab in Lightning service console and you change from one primary tab and came back to the previous one, the Lightning component on the layout refreshes by itself. Can we prevent this behaviour? 
My score got reset to zero on trailhead. I had already completed about 47%.
If you have a lightning component on a layout of a subtab in Lightning service console and you change from one primary tab and came back to the previous one, the Lightning component on the layout refreshes by itself. Can we prevent this behaviour? 


I'm trying to reproduce in APEX this PHP example :

= pack("H*", $key);
echo strtoupper
(hash_hmac('sha512',"ABC", $binkey));


or this Java example :

privateString generateHMAC(String datas )

//                final Charset asciiCs = Charset.forName( "utf-8" );
Mac mac;
String result ="";
            finalSecretKeySpec secretKey = newSecretKeySpec( DatatypeConverter.parseHexBinary(CONSTANTS.KEY),"HmacSHA512");
.init( secretKey );
finalbyte[] macData = mac.doFinal( datas.getBytes());
byte[] hex =newHex().encode( macData );
=newString( hex,"ISO-8859-1");

return result.toUpperCase();



This is my APEX code :

private String hmacFunction(String str, String k) {
    Blob mac = Crypto.generateMac('hmacSHA512', Blob.valueOf(str), Blob.valueOf(k));
    return EncodingUtil.convertToHex(mac).toUpperCase();


This is no good, for the moment : encrypted strings match between Java and PHP, not with APEX.

The result for ABC should be :



Obviously, the difficulty lies in the pack('H*, key) conversion which seems to be different from the Blob.valueOf(key) call.



Can anyone help ?