Search In This Blog

Showing posts with label Aura. Show all posts
Showing posts with label Aura. Show all posts

2022-11-30

Custom auto open utility bar without popout button by aura

cmp
<aura:compomemt implements="lightning:utilityItem">
    <!-- define popout to false -->
    <aura:attribute name="supportsPopOut" type="Boolean" default="false" />

    <!-- auto open utility bar when init -->
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

    <!-- use lightning:utilityBarAPI -->
    <lightning:utilityBarAPI aura:id="utilitybar" />

    someting else
</aura:compomemt>

controller.js
doInit: function(component) {
    var utilityApi = component.find("utilitybar");
    utilityApi.getAllUtilityInfo().then(fuction (response) {
        if (typeof response != "undefined") {
            utilityApi.openUtility();
        }
    });
}

2022-11-01

ReGet data without reload page

Reget data and raletive list data, but not reload page or redirect url.


In AURA

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


In LWC

import { getRecordNotifyChange } from 'lightning/uiRecordApi';

getRecordNotifyChange([{recordId: this.recordId1},{recordId: this.recordId2}]);

or

setTimeout(() => {
    eval("$A.get('e.force:refreshView').fire();");
},1000)

2022-07-02

Get browser type in Lightning Aura/LWC

In Aura

if ($A.get("$Browser.formFactor") != 'DESKTOP') {

    // do something for mobile only here

}


In LWC

import formFactorPropertyName from '@salesforce/client/formFactor'

if (formFactorPropertyName == "Large") {

    // Large—A desktop client.

    // Medium—A tablet client.

    // Small—A phone client.

}


Increase Width of Quick Action Modal Window

Aura

Add style tag to aura component.

<aura:component implements="force:lightningQuickAction,force:hasRecordId">

    <aura:html tag="style"> .slds-modal__container { min-width: 80vw; } </aura:html>

    <aura:attribute name="recordId" type="String" required="false" description="" access="global"/>

    <c:childCmp recordId="{!v.recordId}" onclose="{!c.closeModal}"></c: childCmp>

</aura:component>


LWC

Some issue of quick action in LWC.

Can not change type of Lightning Web Component after deploy.

Can not get recordId & objectApiName at init.

Not working in mobile & Experience(Community)

2021-02-26

Call Apex Method with parameter and show result message | Aura

 CMP:

<aura:component implements="force:lightningQuickActionWithoutHeader,force:hasRecordId" controller="InvoiceIssueController" access="global">

<aura:html tag="style">

       .slds-modal__container{ 

         height : auto; width: 80%; max-width: 70vh; 

       } 

       .modal-body{ 

        height : 15vh !important;

        max-height: 15vh !important; 

       } 

       .slds-modal__footer{ 

         display: inline !important; 

       }

    </aura:html>

    

    <aura:handler name="init" value="{!this}" action="{!c.callServer}"/>

    <aura:handler event="force:refreshView" action="{!c.isRefreshed}" />

    <aura:attribute name="showErrors" type="String"/>

    <aura:attribute name="errorMessage" type="String"/>

    <aura:attribute name="message" type="String"/>

{!v.message}

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

        <div class="slds-notify slds-notify_toast slds-theme_error">

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

            <div class="slds-notify__content">

                <p class="slds-align_absolute-center">{!v.errorMessage}</p>                

            </div>

        </div>

    </aura:if>

</aura:component>


JS:

({

    callServer : function(component,event, helper) {

        var myAttribute = component.get("v.recordId");

        var action = component.get("c.ApexMethod1");

        action.setParams({ "id" : myAttribute });

        var action2 = component.get("c.ApexMethod2");

        action2.setParams({ "id" : myAttribute });


        action2.setCallback(this, function(response) {

            console.log(response.getState());

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

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

            }else {

                console.log("Error Saving Contact ");

            }

        });

      

        action.setCallback(this, function(response) {

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

                if (response.getReturnValue() == 1) {

                    component.set("v.showErrors",true);

                component.set("v.errorMessage","error!");

                } else {

                    component.set("v.message","process...");

                    $A.enqueueAction(action2);

                }

            }else {                  

                component.set("v.showErrors",true);

                component.set("v.errorMessage","error");

            }

        });

        $A.enqueueAction(action);

    },

    isRefreshed: function(component, event, helper) {

        location.reload();

    }

})


Apex:

Add @AuraEnabled to target ApexMethod