Apr 19, 2021

ReUsable Schema Snippets


          Get Object from Record Id:

Id  recordId = '100xxxxxxxxxxxxabc';

Schema.DescribeSObjectResult objectDescribe = recordId.getSobjectType().getDescribe();

String objectName = objectDescribe.getName();


Get Record Type Id Dynamically


          Get Record Type Id by  Record Type Label:

String recordTypeLabel='Parent Account';

String ObjectAPI='Account';

String accRecordTypeID =
Schema.getGlobalDescribe().get(ObjectAPI).getDescribe().getRecordTypeInfosByName().
get(recordTypeLabel).getRecordTypeId();


       Get Record Type Id by  Record Type Developer Name:

String recordTypeDeveloperName='Parent_Account';

String ObjectAPI='Account';

String accRecordTypeID =
Schema.getGlobalDescribe().get(ObjectAPI).getDescribe().getRecordTypeInfosByDeveloperName().get(recordTypeDeveloperName).getRecordTypeId();

 


Get Field Type Dynamically

 

GET Field Type Dynamically 

String objectAPIName = 'Account';
String fieldAPIName = 'Name';

SObjectType r = ( (SObject) Type.forName('Schema.'+objectAPIName).newInstance())).
getSObjectType();

 DescribeSObjectResult d = r.getDescribe();

System.debug(d.fields.getMap().get(fieldAPIName).getDescribe().getType());

 


Apr 6, 2021

ReUsable Apex Snippets

Query All Fields from Specific Object

public static String AllFields(String ObjectName) {

List<String> fields = new List<String>(

 Schema.getGlobalDescribe().get(ObjectName).getDescribe().fields.getMap().keySet()

);

String query  = 'SELECT '+String.join(fields, ',')+' FROM '+ObjectName;


return query;

    }



Apr 4, 2021

Reusable Lightning Snippets

Spinner

<!-- spinner Start  -->

    <aura:attribute name="isLoading" type="Boolean" default="false" />

  

<aura:if isTrue="{!v.isLoading}">

        <div class="demo-only" style="height:6rem">

            <div class="slds-spinner_container">

                <div role="status" class="slds-spinner slds-spinner_medium slds-spinner_brand">

                    <span class="slds-assistive-text">Loading</span>

                    <div class="slds-spinner__dot-a"></div>

                    <div class="slds-spinner__dot-b"></div>

                </div>

            </div>

        </div>

    </aura:if>

    <!-- spinner end  -->


Model pop up

  <!-- Model pop Start  -->

    <section aria-describedby="modal-content-id-1" aria-labelledby="modal-heading-01" aria-modal="true" class="slds-modal slds-fade-in-open slds-modal_medium" role="dialog" tabindex="-1">

        <div class="slds-modal__container">

            <header class="slds-modal__header">

                <lightning:buttonicon alternativetext="close" class="slds-modal__close" iconname="utility:close" onclick="{! c.hideModel }" variant="bare-inverse">

                <h2 class="slds-modal__title slds-hyphenate" id="modal-heading-01">Modal header</h2>

            </lightning:buttonicon></header>

            <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">

                <lightning:card footer="Card Footer" title="Hello">

                    <aura:set attribute="actions">

                        <lightning:button label="New">

                    </lightning:button></aura:set>

                    <p class="slds-p-horizontal_small">

                        Card Body (custom component)

                    </p>

                </lightning:card>

            </div>

            <footer class="slds-modal__footer">

                <button class="slds-button slds-button_neutral">Cancel</button>

                <button class="slds-button slds-button_brand">Save</button>

            </footer>

        </div>

    </section>

    <div class="slds-backdrop slds-backdrop_open"></div>  

     <!-- Model pop End  -->



Common Helper methods

({

    actionMethod : function(cmp,action){

        return new Promise(function (resolve, reject) {

            action.setCallback(this, function (response) {

                //alert(response.getState());

                if (response.getState() === 'SUCCESS') {

                    resolve(response.getReturnValue());

                } else if(response.getState() === 'ERROR') {

                    reject(response.getError());

                }

            });

            // if an action isn't getting called you probably missed this line

            $A.enqueueAction(action);

        });

    },

    showToast : function(type, title, message, duration, mode, key) {

        var toastEvent = $A.get("e.force:showToast");

        toastEvent.setParams({

            "title": title,

            "message": message,

            "type": type,

            "duration": duration,

            "mode": mode,

            "key": key

        });

        toastEvent.fire();

    },

})



Close Quick Action

                 $A.get('e.force:refreshView').fire();

                var dismissActionPanel = $A.get('e.force:closeQuickAction');

                dismissActionPanel.fire();