Wednesday, 7 June 2023

Get selected row id in aura component

 

Get selected row id in aura component




Below is aura:iteration example in aura componnet 

step 1: Define the data-record attribute and on click event

<aura:iteration items="{!v.ShowRecords}" var="acc">

<div class="slds-grid slds-wrap mainsearchBox">

<div class="imgDiv slds-col slds-size_2-of-12 slds-small-size_2-of-12 slds-medium-size_2-of-12" style="text-align:center;">

<div class="holder">                      

<div data-record="{!acc.Id}" onclick="{!c.goToProfile}"><a><img src="{!acc.Logo_URL}" class="logoImg" /> </a></div>        

</div>

</div>                             

</div>

</aura: iteration>



step 2:  Add the click event in controller.js

goToProfile : function(component, event, helper) {

console.log('goToProfile ------');

var selectedItem = event.currentTarget;

  

var Id = selectedItem.dataset.record;

console.log('Id='+Id);



Tuesday, 6 June 2023

Increase quick action window width

 

Increase size (width) of Lightning Web Component Quick Action Modal Popup Salesforce



<aura:component controller="PaymentCalculatorController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >

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

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

<aura:attribute name="actionWidth" type="string" default="75"/>


 <aura:html tag="style">             

        .slds-modal__container{        

        width: 100% !important;

        max-width: {!v.actionWidth}rem !important; 

        }      

        

        .slds-modal__footer {

        display: none;

        }

    </aura:html>





</aura: component >

Tuesday, 30 May 2023

Send email using guest user by apex code

Sending Email from Guest User Profile- Email No Receiving Email 



Send email using guest user




public pageReference generatePDF() {    

        if(caseId != '') {

            Case cs = [select Id,CaseNumber,Quote_Number__c from Case where Id=:caseId LIMIT 1];      

            pageReference pdfPage = Page.EnceliumForm;

            blob pdfBody;

            if(Test.isRunningTest()) { 

              pdfBody = blob.valueOf('Unit.Test');

            } else {

                pdfBody = pdfPage.getContentAsPdf(); 

            }       

            system.debug('in method--------->>'+caseId+cs);

            system.debug('pdfFile===>'+pdfBody);

            attachment pdfFile = new attachment();

            pdfFile.isPrivate  = false;

            pdfFile.body       = pdfBody;

            pdfFile.parentId   = cs.Id; // '5003B000005oRIx';

            pdfFile.Name       = 'Encelium Request form.pdf';        

            insert pdfFile; 

            system.debug('## pdfFile===>'+pdfFile);

            if(string.isNotBlank(ecContactEmail)) {

                system.debug('## ecContactEmail===>'+ecContactEmail);                

                OrgWideEmailAddress owea = new OrgWideEmailAddress();

                owea = [SELECT Id, Address, DisplayName FROM 

                        OrgWideEmailAddress WHERE displayname='Legrand CRM Support Team' limit 1];                                                

                string conEmail = ecContactEmail;

                Messaging.EmailFileAttachment att = new Messaging.EmailFileAttachment();

                att.setBody(pdfBody);

                att.setContentType('application/pdf');

                att.setFileName('attachment.pdf');

                Messaging.SingleEmailMessage mess = new Messaging.SingleEmailMessage();

                mess.setSubject('Encelium Request Form:'+' Your Case Number: '+ cs.CaseNumber);

                mess.setToAddresses(new String[]{conEmail}); 

                

                mess.setHtmlBody('Please find attached self-signed Encelium Request Form. <br/><br/> Please do not reply to this mail');

                mess.setFileAttachments(new Messaging.EmailFileAttachment[]{att});

                mess.setSaveAsActivity(false);

                mess.setOrgWideEmailAddressId(owea.id);

              //Messaging.sendEmail(new Messaging.Email[]{mess});

                system.debug('## End===>');

                

                try{

                    List<Messaging.SendEmailResult> results =   Messaging.sendEmail(new Messaging.Email[]{mess});

                    if(results[0].success){

                         system.debug('## success===>');

                    }else{

                        system.debug('## Fail===>');

                    }

                } catch(Exception ex){

                    system.debug('## Exception===>'+ex.getMessage() +' LN ='+ex.getLineNumber());

                }

                

                

            }

        }

        return new pagereference('http://www.Legrand.us').setRedirect(true);

    }

Wednesday, 22 February 2023

How to detect browser in lightning component

 

How to detect browser in lightning component


This example shows usage of the $Browser global value provider.

In Lightning component 

<aura:component> {!$Browser.isTablet} {!$Browser.isPhone} {!$Browser.isAndroid} {!$Browser.formFactor} </aura: component>

In a client-side controller

({ checkBrowser: function(component) { var device = $A.get("$Browser.formFactor"); alert("You are using a " + device); } })





Thursday, 19 January 2023

Get URL parameters in Lightning Components

 You can get lightning parameter in two way : 

1)  

lightning:isUrlAddressable Interface : Get URL parameters in Lightning Components


We can fetch URL param by using "{!v.PageReference.state.parameterName}" where parameterName is URL parameter name.


<aura:component  implements="lightning:isUrlAddressable,force:appHostable" access="global">
    <aura:attribute name="urlParam" type="string"/>
    <div class="slds-card">
    If you implements "lightning:isUrlAddressable" interface, then by 
        using v.pageReference,you can get URL params.
    <div class="slds-box">  
        Account Name is :  <b>{!v.pageReference.state.accname}</b>
        </div>
    </div> 
</aura:component>

"/lightning/n/tabName?accname=Naresh Thakur"

Output is : 
Account Name is : Naresh Thakur



2) You can write code in js component 
For Ex 

doInit : function(component, event, helper) {       
         var sPageURL = decodeURIComponent(window.location.search.substring(1));
         var sURLVariables = sPageURL.split('&');
         var sParameterName;
         for (var i = 0; i < sURLVariables.length; i++) {
             sParameterName = sURLVariables[i].split('=');             
             if (sParameterName[0] === 'conId') {
                 component.set('v.tempConId',sParameterName[1]);
             }
         }
         
        // Other code goes here
    },

Call it 
https://YourURL/Pagename?conId = aio000000000ADSuiq

Monday, 9 May 2022

getting picklist field options in list in apex class

getting picklist field options in list in apex class


VF page 

<div class="slds-form-element slds-form-element_horizontal">

                              <label class="slds-form-element__label" for="">Current Institution <span class="reg">*</span></label>

                              <div class="slds-form-element__control">                                  

                                  <apex:selectList value="{!currentInstitution}" size="1" label="" styleClass="slds-input">

                                      <apex:selectOptions value="{!PickListValuesIntoList}"/>

                                  </apex:selectList>

                                  <!--<apex:inputField value="{!UserContact.Country_of_Institution__c}" styleClass="slds-input" id="UserContact__Country_of_Institution__c" ignoreEditPermissionForRendering="true"/>-->

                              </div>

                          </div> 




Apex Controller 


 public List<SelectOption> getPickListValuesIntoList(){

        List<SelectOption> selectOptions = new List<SelectOption>();

        Schema.DescribeFieldResult fieldResult = Contact.Country_of_Institution__c.getDescribe();

        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();

        for( Schema.PicklistEntry pickListVal : ple){

            selectOptions.add(new SelectOption(pickListVal.getLabel(), pickListVal.getLabel()));

        }             

        return selectOptions; 

    }  


Wednesday, 6 October 2021

Get the Api name from soql

 



List<FieldDefinition> lstApiRecords =[SELECT Label, DeveloperName, Description, DataType, ExtraTypeInfo,  Length, Precision, Scale,QualifiedApiName FROM FieldDefinition WHERE EntityDefinition.QualifiedApiName ='Account'  order by label ASC];

        if(lstApiRecords.size()>0){

            for(FieldDefinition record:lstApiRecords){

                if(string.isNotEmpty(record.label)){  

                    system.debug('Field Infoemartin========================>');

                    system.debug('Label  ==='+record.Label);

                    system.debug('DeveloperName  ==='+record.DeveloperName);

                    system.debug('Description  ==='+record.Description);

                    system.debug('DataType  ==='+record.DataType);

                    system.debug('ExtraTypeInfo  ==='+record.ExtraTypeInfo);

                    system.debug('Length  ==='+record.Length);

                    system.debug('Precision  ==='+record.Precision);

                    system.debug('Scale  ==='+record.Scale);

                    system.debug('QualifiedApiName  ==='+record.QualifiedApiName);

                }                               

            }

        }   


Result :