Passing objects to future methods

Future methods are used to run a code in a separate thread at a later time when system resources are available. We can use them to run something asynchronously, for example make a web service callout from an Apex Trigger. This way we can make sure user does not wait for response to get back. Future methods must be static and if you want to make callouts annotation needs to include (callout=true):

<pre class="wp-block-syntaxhighlighter-code">
@future (callout=true)
public static void doCallout() {
    //make callout here

Future methods does not allow passing objects as an arguments, only primitive data types are accepted, however we can oversome this limitation by using serialization and deserialization. Here is how we can do this:


<pre class="wp-block-syntaxhighlighter-code">
Trigger OpportunityTrigger on Opportunity( after insert) {
     String jsonString = json.serialize(Trigger.NEW);



<pre class="wp-block-syntaxhighlighter-code">
public class OpportunityTriggerHandler {
    public static void process( String jsonString) {
          List&amp;lt;Opportunity&gt; oppNewtList = (List&amp;lt;Opportunity&gt;)Json.deserialize(jsonString, List&amp;lt;Opportunity&gt;.class);

Add Dropdown (Picklist) in Lightning Web Component.

In Aura Components we can use lightning-select to create dropdown. In Lightning Web Component there is a lightning-combobox component that allows to do this.

Here is example on how to do this in LWC:



import { LightningElement, track } from 'lwc';

export default class LightningDropDown extends LightningElement {
@track selectedColor = 'white';

get colorOptions() {
    return [
             { label: 'White', value: 'white' },     
             { label: 'Red', value: 'red' },
             { label: 'Green', value: 'green' },
             { label: 'Blue', value: 'blue' },

handleChange(event) {
        this.selectedColor = event.detail.value;