Sunday, July 28, 2019

Display Google Map Lightning Web Component at Salesforce Communities

Motivation behind this


After posting my previous blog post Display Google Map using Salesforce Lightning Web Components leveraging modern JavaScript at Linkedin (My Post), there are few community members asked me if that component could be available in Salesforce Communities, which drives me to do one more proof-of-concept on how that component can be available at Communities.


Use Case


How to expose Lightning Web Component at Salesforce Community.


Expected Outcome


After adding LWC component at Community Page, it will look like this:



Solution Approach


Let's break down few steps to be performed:

1. Changes in Configuration File displayLWCMap.js-meta.xml

a) Need to add targets where this component will be  exposed. lightningCommunity__Page and lightningCommunity__Default 

b) Need to add targetConfigs which will contain property to be passed.

So, entire file will look like this:



<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="displayLWCMap">
    <apiVersion>45.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
    <target>lightning__AppPage</target>
    <target>lightning__RecordPage</target>
    <target>lightning__HomePage</target>
    <target>lightningCommunity__Page</target>
    <target>lightningCommunity__Default</target>
  </targets>
  <targetConfigs>
        <targetConfig targets="lightningCommunity__Default">
            <property name="accountNameParam" type="String" default="myValue"></property>            
        </targetConfig>
    </targetConfigs>
  
</LightningComponentBundle>

If the defined property is not exposed in js Controller we will receive error.

So, here I have used accountNameParam which is public reactive property (@api).

There will not be any other changes in HTML and JS controller files.

2. Enabling Community and use your own template.

For more information, refer Build a Custom Theme Layout Component for Lightning Communities

3. Adding Component to the Community Builder

When we try to add this component inside the page, we will see following alert message.





Solving Security Issues


Navigate to Builder à Settings à Security and find following settings:



Add the blocked URL as Whitelist URL.

We can also add trusted sites in the following screen.




Add the displayLWCMap component to the layout, publish the changes and our job is done.


Related Reference




Further Reading


Display Google Map using Salesforce Lightning Web Components leveraging modern JavaScript

Motivation behind this


Currently I am exploring Lightning Web Components (LWC) and trying to display Google map using LWC leveraging modern JavaScript (ES6 Standard). Since modern JavaScript has new functions like Spread function, Arrow function which are well blended into LWC JavaScript controller and hence, drives me to come out with this proof-of-concept.

Use Case


Business has a requirement to display their various office locations in the Google Map which will get retrieved from Salesforce Account Object.

Developer wants to build this requirement using Lightning Web Components.


Expected Outcome





In the above picture I am displaying our company office locations (Bangaluru and Noida) in Google Map. I have taken only 2 locations for simplicity.

Solution Approach


Salesforce provides lightning-map component which displays one or more locations. It inherits the styling from map of Lighting Design System. 

So, it is better to use it.

Syntax for using lightning-map component


<template>
    <lightning-map
 map-markers={mapMarkers}
 markers-title="Our Company Location">
  </lightning-map>
</template>

A marker contains
  • Location Information: A coordinate pair of latitude and longitude, or an address composed of address elements.
  • Descriptive Information: Optional title, description, and an icon. These are relevant to the marker but not specifically related to location.
For more information, refer lightning-map documentation

Little bit homework for preparing data

Since data to be displayed dynamically from database, so created 2 Account records with a name starts with Tavant providing complete BillingAddress information. I have not given Latitude and Longitude as Location which can also be used alternatively.

Let's first construct the Apex class.

DisplayMapController.cls

getOfficeLocations method accepts accountNameInitial  as input parameter and returns List of Accounts based on SOQL query. We are not doing any data transformation which can be recognized in map display, rather let it be handled by LWC js controller will be mentioned below.

Note: 
@AuraEnabled (cacheable=true) used as it will be called from js controller and @wire is calling the method
Secondly, use of bind (:str) variables to get rid of SOQL injection.



public with sharing class DisplayMapController {
    
    @AuraEnabled (cacheable=true)
    public static List<Account> getOfficeLocations(String accountNameInitial){
        String str = accountNameInitial + '%';
        return [SELECT Id, Name, BillingStreet, BillingCity, BillingState, BillingPostalCode, BillingCountry 
                FROM Account 
                WHERE Name LIKE :str];       
    }
}


Let's develop Lightning Web Components

Create a VSCode project with a menu selection SFDX: Create Lightning Web Component and provide a name displayLWCMap, which creates 3 files html (UI) , js (Controller) and xml (Configuration) at your chosen directory.

displayLWCMap.html

Inside the template lightning-map component has been used and also zoom-level has been used as additional attribute apart from map-markers and markers-title.

<template>
    <div class="slds-m-around_medium">
        <h1 class="slds-text-heading_small">Tavant Technologies</h1>
        <p class="slds-text-body_regular">Office locations</p>
    </div>
    <lightning-map 
        map-markers={mapMarkers}
        markers-title={markersTitle}
        zoom-level={zoomLevel}>
    </lightning-map>   
</template>

displayLWCMap.js

Good thing of LWC is handling all attributes as js controller level which is opposed to Aura and this class is most important for implementing this functionality.

Follow these steps:
  • import LightningElement, api, wire, track which will be used in this class.
  • import getOfficeLocations as we will be using getOfficeLocations method of DisplayMapController apex class.
  • At the class level, 
    • accountNameParam which is public reactive property decorated with @api
    • error, mapMarkers, markersTitle and zoomLevel are private reactive properties
  • @wire to function i.e getOfficeLocations and passing parameter '$accountNameParam' for accountName (here, parameter has been hard coded, though it can passed from html)
    • This is function, retrieve the data and prepare mapMarkers array with location, icon and title which should be recognized and used in the lightning-map.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { LightningElement , wire, track, api} from 'lwc';

import getOfficeLocations from '@salesforce/apex/DisplayMapController.getOfficeLocations';

export default class DisplayLWCMap extends LightningElement {

    @api accountNameParam; 
    accountNameParam = 'Tavant';
    @track error;   //this holds errors

    @track mapMarkers = [];
    @track markersTitle = 'Tavant Technologies';
    @track zoomLevel = 4;
    /* Load address information based on accountNameParam from Controller */
    @wire(getOfficeLocations, { accountNameInitial: '$accountNameParam'})
    wiredOfficeLocations({ error, data }) {
        if (data) {            
            data.forEach(dataItem => {
                this.mapMarkers = [...this.mapMarkers ,
                    {
                        location: {
                            City: dataItem.BillingCity,
                            Country: dataItem.BillingCountry,
                        },
        
                        icon: 'custom:custom26',
                        title: dataItem.Name,
                    }                                    
                ];
              });            
            this.error = undefined;
        } else if (error) {
            this.error = error;
            this.contacts = undefined;
        }
    }

}

displayLWCMap.js-meta.xml


This is configuration file which states where this component will be available.
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="displayLWCMap">
    <apiVersion>45.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
    <target>lightning__AppPage</target>
    <target>lightning__RecordPage</target>
    <target>lightning__HomePage</target>
  </targets>
</LightningComponentBundle>


Leveraging Modern JavaScript


Arrow Function

You can observe that following statement has been used which doesn't have function() and return statement.

data.forEach(dataItem => {
  //method body without return statement
}

For example, earlier we use write this way to using function and return statement.

let result = function (a,b) {
  return a+b; 
}
console.log(result(1,2));

Now, with Arrow function, it can be written as:

let result = (a,b) => return a+b; 

console.log(result(1,2))

Also, Arrow function resolves some confusion when dealing with this keyword, when nested functions are involved. Functions have a special variable called this, often referred to as the “dynamic this,” which refers to the object used to invoke the function.

For more information, Refer Understand JavaScript Functions

Spread Operator

Spread operator helps to expand the array which we have used for creating mapMarkers array. Here is an example:


let arr = ['a','b']; 
let arr2 = [...arr,'c','d']; 
  
console.log(arr2); // [ 'a', 'b', 'c', 'd' ] 

We can see, arr values has been appended first and then c and d have been added to the same array.

Similarly, we can append array values at end the array too.


let arr = ['a','b']; 
let arr2 = ['c','d',...arr]; 
  
console.log(arr2); // [ 'c', 'd', 'a', 'b'] 

Monday, July 22, 2019

Salesforce Lightning Web Components Cheat Sheet

Motivation behind this


Lately, I am exploring on Lightning Web Components and trying to find out one handy document which I didn't find on net. That's why I thought of preparing a cheat sheet on this. 

I have prepared 8 pager cheat sheet which covers almost all most important features and functionalities. (To download entire document scroll through the bottom).

Hope it will be helpful for Salesforce community members who are learning, exploring and working on Lightning Web Components.

Page 1



Page 2

Page 3

Page 4

Page 5

Page 6

Page 7 



Final Page




Download entire cheat sheet

Salesforce Lightning Web Components Cheat Sheet (Unofficial)

If you find this useful then post your feedback as comments.

Happy to share!

Further Reading


Monday, July 15, 2019

Display Combobox values by Lightning Web Components and propagating events to Parent Aura Components

Motivation behind this


I have started exploring on Lightning Web Components (aka. LWC) lately and tried to answer this question at StackExchange Lightning Web Component Combobox in a different way. During my proof of concepts I have faced few issues in array handling on LWC js controller and thought of sharing this solution.

I have come up with a use case which could help many of us who are learning LWC. Now a days, there are lot of Lightning upgrade projects are going on. Most of companies are also transforming Aura Components to Lightning Web Components. Also, in some cases, Aura Components will still exist as Parent Component of LWC child components. So, communication from Child LWC to Parent Aura Component is also necessary which has been depicted as part of this use case.

Use Case


In a Salesforce instance there is a Aura Component which displays Account specific information and all types of DML operation are getting performed from this component. There is a requirement to display list of Contacts pertaining to that Account which should be done on Lightning Web Components (as there could many other Contact specific information or calculations can be performed) and selection of the Contact from the dropdown should fire an event and send the ContactId to the Parent Aura Component.

End output will look like this:


Solution Approach


We can break down the solutions into the smaller steps as follows:

1. Create a Lightning Web Component which will display list of Contacts from database. It will also take AccountId as parameter to this component.

2. Create a Aura Component which will have Account information and it will embed Child LWC and pass AccountId to the child.

3. Final step will be event propagation which will be from Child LWC to Parent Aura component. Here, for sake of simplicity, selecting Contact from comboxbox will fire Component event and send ContactId of the selected item and pass it as part of event. This will be displayed into Parent Aura Component as a text.

Child Web Components

displayContact.html

As part of step 1, create this LWC component and place lightning-combo component which attributes. Note that, value, options attributes and onchange event handler.

<template>
    <lightning-card title="List of Contacts - Lightning Web Component" icon-name="custom:custom63">
        <lightning-combobox
            name="contacts"
            label="Contacts"
            placeholder="Choose Contact"
            value={value}
            onchange={handleChange}
            options={statusOptions}>
        </lightning-combobox>
    </lightning-card>
</template>

displayContact.js

This is most important for implementing this functionality.

There are the points to meet Step 2, to populate and display combobox values.

  • import LightningElement, api, wire, track which will be used in this class.
  • import getContacts as we will be using getContacts method of AccountController apex class.
  • At the class level, 
    • recordId which is public property decorated with @api
    • error, items array, value are private tracked properties
  • @wire to function i.e getContacts and passing parameter '$recordId' for accountId
    • This is function, retrieve the data and prepare items array with value and label which should be recognized and used in the combobox.
    • Mind the syntax for storing values in array: this.items = [...this.items ,{value: data[i].Id , label: data[i].Name}]
  • getter property for statusOptions which displays options taking items array.

To meet Step 3, we have used handleChange(event) it fires based on changing combobox item selection.

  • Collect combobox value as selectedOption.
  • Create a Custom Event, Lightning web component fires a custom filterchange event in its JavaScript file.
  • And finally, dispatchEvent which helps to communicate from child to parent.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* eslint-disable no-console */
/* eslint-disable no-alert */
/* eslint-disable no-unused-vars */
import { LightningElement, api, wire, track } from 'lwc';

import getContacts from '@salesforce/apex/AccountController.getContacts';
let i=0;

export default class DisplayContact extends LightningElement {
     /** Id of record to display. */
    @api recordId; //this captures AccountId which is passed from Parent Component
    @track error;   //this holds errors

    @track items = []; //this holds the array for records with value & label

    @track value = '';  //this displays selected value of combo box

    /* Load Contacts based on AccountId from Controller */
    @wire(getContacts, { accountId: '$recordId'})
    wiredContacts({ error, data }) {
        if (data) {
            for(i=0; i<data.length; i++) {
                console.log('id=' + data[i].Id);
                this.items = [...this.items ,{value: data[i].Id , label: data[i].Name}];                                   
            }                
            this.error = undefined;
        } else if (error) {
            this.error = error;
            this.contacts = undefined;
        }
    }
   
    //getter property from statusOptions which return the items array
    get statusOptions() {
        console.log(this.items);
        return this.items;
    }

    handleChange(event) {
        // Get the string of the "value" attribute on the selected option
        const selectedOption = event.detail.value;
        console.log('selectedOption=' + selectedOption);

        //This is for event propagation
        
        const filterChangeEvent = new CustomEvent('filterchange', {
            detail: { selectedOption },
        });

        
        // Fire the custom event
        this.dispatchEvent(filterChangeEvent);
    }
    
}

AccountController.cls

getContacts method returns List of Contacts based on SOQL query. We are not doing any data transformation which can be recognized in combobox display, rather let it be handled by LWC js controller as specified above.


public with sharing class AccountController{
    
    @AuraEnabled (cacheable=true)
    public static List<Contact> getContacts(String accountId){
        return [SELECT Id, Name FROM Contact WHERE AccountId =:accountId];        
    }
}

displayContact.js-meta.xml

This is nothing fancy as such.

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="DisplayContact">
    <apiVersion>45.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
    <target>lightning__AppPage</target>
    <target>lightning__RecordPage</target>
    <target>lightning__HomePage</target>
  </targets>
</LightningComponentBundle>

Now its time to prepare Parent Aura Component and related files.

ParentAccount.cmp

Following points to be noted, it meets Step 3:

  • force:hasRecordId has been implemented to get recordId of Account.
  • That has been passed as recordId which is captured in Child LWC controller through @api public property
  • The enclosing Aura component wrapper adds a handler for the custom event. Notice that the event handler, onfilterchange, matches the event name with “on” prefixed to it. That is, use onfilterchange to handle the event named filterchange.


<aura:component implements="flexipage:availableForAllPageTypes,force:hasRecordId">
    <aura:attribute name="message" type="String" default="Select a Contact from dropdown"/>
    <lightning:card title="Account - Aura Component" iconName="custom:custom30">
        <div class="slds-m-around_medium">
            <lightning:layout>
                <lightning:layoutItem size="4">
                    <!-- This is an LWC component -->
                    <c:displayContact recordId="{!v.recordId}"  onfilterchange="{!c.handleFilterChange}"/>
                </lightning:layoutItem>
                <lightning:layoutItem size="8" class="slds-p-left_medium">
                    {!v.message}
                </lightning:layoutItem>
            </lightning:layout>
        </div>
    </lightning:card>
</aura:component>


ParentAccountController.js

The Aura component’s controller receives the event. You can handle the event however you’d like. This component operates on the filters array passed in the details property of the Lightning web component event. You can optionally fire a new Aura event to communicate with other Aura components.


({
    handleFilterChange: function(component, event) {
        var filters = event.getParam('selectedOption');
        console.log('filters=' + filters);
        component.set('v.message', filters.length > 0 ? 
                      'Selected ContactId from Child LWC: ' + filters : 
                      'No selection from Child LWC');
    },
});

So, we are done.

After deployment, place ParentAccount component on the page layout of Account and our desired functionality will be achieved.

Note: The concepts for preparing array with items not only applicable for combobox, but also for, lightning-checkbox-group, lightning-radio-group, lightning-dual-listbox, lightning-datatable etc. So the above approach can be leveraged for all those purposes.

References


Monday, May 27, 2019

Create Salesforce Big Objects through Apex and Metadata API

Motivation behind this


I was exploring Big Objects and trying to create Big Object and Field definitions through Metadata API. I have searched all possible way but didn't find any code regarding this use case.

I am thankful to Andrew Fawcett (Andrew Fawcett) and his team for building MetadataService.cls which a wrapper to Metadata API which actually helped me to build this solution. Though this example doesn't exists anywhere which motivates me to write this code.

It has taken almost 5 hours to build this solution since I didn't have any prior experience to handle Metadata API through Apex.

Little bit information about Big Objects


  • It stores billions of data on Salesforce Platform and we can archive data from other objects or datasets.
  • There are two type of Big Objects: Standard and Custom
  • Only following field types are available: Lookup Relation, Number, Text, Long Text Area and Date/Time
  • Big Object supports custom Lightning and Visualforce components rather than standard UI elements home pages, detail pages, list views etc.
  • We can create up to 100 Big Objects in per org.
  • It doesn't support encryption.
For more information, refer Big Objects Implementation Guide

Implementation Approach and important points


Firstly I have referred the codebase in MetadataService.cls and then started exploring.

To create Big Objects following points must be followed:

1. AllOrNoneHeader element and allOrNone should be true.

2. During firing createMetadata(), Big Object definition along with a custom field and index are must.

3. It will use MetadataService.CustomObject to create Big Object, but fullName should have API Name which ends with __b

4. Big Object doesn't have Standard Name field.

5. Big Object doesn't have SharingModel. Though you can use permission sets to assign permissions.


Script


I have provided step by step approach with in-line comments.

Here I have tried to create Big Object with a name Application (Application__b) with following fields:


  • Account - Lookup (Account)
  • Amount - Number (16,2)
  • Description - Long Text Area (33000)
  • Name - Text (50) and it is indexed
  • Start Date - Date/Time




  1. MetadataService.MetadataPort service = new MetadataService.MetadataPort();  
  2. service.SessionHeader = new MetadataService.SessionHeader_element();  
  3. service.SessionHeader.sessionId = UserInfo.getSessionId();  
  4.   
  5. //AllOrNoneHeader is mandatory for Big Object  
  6. service.AllOrNoneHeader = new MetadataService.AllOrNoneHeader_element();  
  7. service.AllOrNoneHeader.allOrNone = true; //this is required for Big Objects  
  8.   
  9. //define Big Object  
  10. MetadataService.CustomObject bigObject = new MetadataService.CustomObject();  
  11. bigObject.fullName = 'Application__b';  
  12. bigObject.label = 'Application';  
  13. bigObject.pluralLabel = 'Applications';  
  14. bigObject.deploymentStatus = 'InDevelopment'; //Make it Deployed if you need
  15.   
  16. List<MetadataService.CustomField> lstCustomFields = new List<MetadataService.CustomField>();  
  17.   
  18. //define Text Field  
  19. MetadataService.CustomField fieldObj = new MetadataService.CustomField();  
  20. fieldObj.type_x = 'Text';  
  21. fieldObj.label = 'Name';  
  22. fieldObj.fullName = 'Name__c';  
  23. fieldObj.length = 50;  
  24. fieldObj.required = true;  
  25. lstCustomFields.add(fieldObj);  
  26.   
  27. //define DateTime Field  
  28. fieldObj = new MetadataService.CustomField();  
  29. fieldObj.type_x = 'DateTime';  
  30. fieldObj.label = 'StartDate';  
  31. fieldObj.fullName = 'StartDate__c';  
  32. lstCustomFields.add(fieldObj);  
  33.   
  34. //define Number Field  
  35. fieldObj = new MetadataService.CustomField();  
  36. fieldObj.type_x = 'Number';  
  37. fieldObj.label = 'Amount';  
  38. fieldObj.fullName = 'Amount__c';  
  39. fieldObj.externalId = false;  
  40. fieldObj.precision = 18;  
  41. fieldObj.required = false;  
  42. fieldObj.scale = 2;  
  43. fieldObj.unique = false;          
  44. lstCustomFields.add(fieldObj);  
  45.   
  46. //define Long Text Area Field  
  47. fieldObj = new MetadataService.CustomField();  
  48. fieldObj.type_x = 'LongTextArea';  
  49. fieldObj.label = 'Description';  
  50. fieldObj.fullName = 'Description__c';  
  51. fieldObj.length = 33000;  
  52. fieldObj.visibleLines = 3;  
  53. fieldObj.required = false;  
  54. fieldObj.unique = false;          
  55. lstCustomFields.add(fieldObj);  
  56.   
  57.   
  58. //define Lookup Relationship with Account  
  59. fieldObj = new MetadataService.CustomField();  
  60. fieldObj.type_x = 'Lookup';  
  61. fieldObj.label = 'Account';  
  62. fieldObj.fullName = 'Account__c';  
  63. fieldObj.relationshipLabel = 'Applications';  
  64. fieldObj.relationshipName = 'Applications';  
  65. fieldObj.referenceTo = 'Account';  
  66. lstCustomFields.add(fieldObj);  
  67.   
  68. bigObject.fields = lstCustomFields;  
  69.   
  70. //define index  
  71. List<MetadataService.Index> lstIndex = new List<MetadataService.Index>() ;  
  72. MetadataService.Index indexObj = new MetadataService.Index();  
  73. indexObj.label = 'MyIndex';  
  74. indexObj.fullName = 'MyIndex';  
  75.   
  76. bigObject.indexes = lstIndex;  
  77.   
  78. //define index field and add it to index  
  79. List<MetadataService.IndexField> lstIndexFields = new List<MetadataService.IndexField>();  
  80. MetadataService.IndexField indfl = new MetadataService.IndexField();  
  81. indfl.name = 'Name__c';  
  82. indfl.sortDirection = 'ASC';  
  83. lstIndexFields.add(indfl);  
  84.   
  85. indexObj.fields = lstIndexFields;  
  86. lstIndex.add(indexObj);  
  87.   
  88. //finally create Big Object with Index field  
  89. List<MetadataService.SaveResult> saveResults =          
  90.     service.createMetadata(  
  91.         new MetadataService.Metadata[] { bigObject});         
  92.   
  93. MetadataService.SaveResult saveResult = saveResults[0];  
  94.   
  95. if(saveResult==null || saveResult.success)  
  96.     return;  
  97. // Construct error message   
  98. if(saveResult.errors!=null)  
  99. {  
  100.     System.debug('errors=' + JSON.serialize(saveResult.errors));  
  101.     List<String> messages = new List<String>();  
  102.     messages.add(  
  103.         (saveResult.errors.size()==1 ? 'Error ' : 'Errors ') +  
  104.             'occured processing component ' + saveResult.fullName + '.');  
  105.     for(MetadataService.Error error : saveResult.errors)  
  106.         messages.add(  
  107.             error.message + ' (' + error.statusCode + ').' +  
  108.             ( error.fields!=null && error.fields.size()>0 ?  
  109.                 ' Fields ' + String.join(error.fields, ',') + '.' : '' ) );  
  110.     if(messages.size()>0)  
  111.         System.debug(String.join(messages, ' '));  
  112. }  
  113. if(!saveResult.success)  
  114.     System.debug('Request failed with no specified error.');  


Pain Points


In the MetadataService.cls Index class doesn't have fullName and it should be added otherwise after creating Big Object, Index name will show as null and Index API name will should null__b


  1. public class Index {  
  2.         public MetadataService.IndexField[] fields;  
  3.         public String label;  
  4.         public String fullName; //added by Santanu otherwise index name will show null and api name as null__b  
  5.         private String[] fullName_type_info = new String[]{'fullName',SOAP_M_URI,null,'0','1','false'}; //added by Santanu  
  6.         private String[] fields_type_info = new String[]{'fields',SOAP_M_URI,null,'0','-1','false'};  
  7.         private String[] label_type_info = new String[]{'label',SOAP_M_URI,null,'1','1','false'};  
  8.         private String[] apex_schema_type_info = new String[]{SOAP_M_URI,'true','false'};  
  9.         //private String[] field_order_type_info = new String[]{'fields','label'};  
  10.         private String[] field_order_type_info = new String[]{'fields','label','fullName'}; //fullName added  
  11.     }  


I have run the scripts when I was adding fields one by one. After creating Big Object if you have to rerun the script, you need to delete the Big Object permanently if it contains Lookup field.

Secondly, you can create permission set to provide field level permissions.

Final Outcome


The Big Object has been created and found as follows:


Data Entry


To insert data into Big Object as record create an instance of the object and assign field values and use Database.insertImmediate() .

  1. Account acct = new Account(Name='Account1');  
  2. insert acct;  
  3.   
  4. Application__b appObj = new Application__b();  
  5. appObj.Name__c = 'My Application';  
  6. appObj.Amount__c = 100;  
  7. appObj.Description__c = 'Testing with data';  
  8. appObj.Account__c = acct.Id;  
  9. appObj.StartDate__c = System.today();  
  10.   
  11. Database.insertImmediate(appObj);  


References