Tuesday, May 25, 2021

Get Parent records Count if Child records are null

 

Single line SOQL: 

SELECT Count(Id) from ParentObject__c where Id Not IN (select Parent(Lookup) field API name from ChildObject__c) and Status_c='Pending' and Recordtype.name ='Normal'


Reference link:

https://salesforce.stackexchange.com/questions/230524/soql-query-to-display-number-of-opportunities-number-of-contacts-from-account


Monday, May 24, 2021

Quick action width Increase

1. Create a .css file in your local system along with below code, No need to add any < Style /> keywords

    .slds-modal__container{      width: 80% !important; max-width: 80% !important;     }   

2. Add the above File to Static resources(Public)(Name : CustomModelPopUpand Refer this file to the lightning component by using ltng Require Attribute.

  <ltng:require styles="{!$Resource.CustomModelPopUp}" />

3. The height is Managed while creating the Quick action.


Reference link:

https://forcepanda.wordpress.com/2019/01/24/how-to-increase-the-width-of-quick-action-modal-popup/

Monday, May 17, 2021

Email button Visibility on Activity Tab under Record detail page

1. Change the Deliverability to "All Emails".

(  Setup --﹥  Quick Search --﹥ Deliverability --﹥ All Emails  ).

2. Supported ObjectsAccounts, Contacts, Contracts, Leads, Opportunities, and activity-enabled Custom object records

3. UnSupported Objects: Cases




Reference link : 

https://help.salesforce.com/articleView?id=000331369&type=1&mode=1

Saturday, May 15, 2021

MailChimp transactional Email R&D

About transactional Email:

Transactional emails are sent to one person at a time, and are limited in the type of content they can include


1.  are one-to-one communications, 

2.  are a type of automated email or Trigger Email

3.  are relevant only to the intended individual recipient but not group of emaails

Usage:

a. Confirmation emails : 

b. Notification emails

c. Reminders

4. legal restrictions on a transactional email.

5. Transactional email typically relies on an API or Simple Mail Transfer Protocol (SMTP) integration for sending.

6. Transactional Email is a paid add-on to a Standard or Premium Mailchimp plan


ref links:

https://mailchimp.com/resources/how-to-use-transactional-emails/

https://mailchimp.com/help/about-transactional-email/ .



For setup the Transactional Email from Mandril :

https://mailchimp.com/developer/transactional/docs/fundamentals/



https://www.g2.com/products/mailchimp-transactional-email-formerly-mandrill/reviews#survey-response-902629


SMTP : https://www.youtube.com/watch?v=lA3xBtQ9juY


Send through POSTMAN:

https://mailchimp.com/developer/transactional/guides/quick-start/


to get the API key:

https://mandrillapp.com/settings


Api for templates for mailchimp:

https://mailchimp.com/developer/transactional/api/templates/list-templates/


Api for templates for mandrill:

https://mandrillapp.com/api/docs/templates.JSON.html#method=list


Quick Start API:

https://mailchimp.com/developer/transactional/guides/quick-start/


Send template:

https://mailchimp.com/developer/transactional/api/messages/send-using-message-template/


https://developer.salesforce.com/forums/?id=9062I000000IYVCQA4


Reusable Related List Component in Lightning using Apex class

 Apex class:

----------

public with sharing class RelatedListController {

    @AuraEnabled   

    public static RelatedListResult fetchRecs( String recId, String sObjName, String parentFldNam, String strCriteria ) {     

        String strTitle = ' (';           

        List < sObject > listsObjects = new List < sObject >();  

        RelatedListResult obj = new RelatedListResult();  

        String strSOQL = 'SELECT Id FROM ' + sObjName + ' WHERE ' + parentFldNam + ' = \'' + recid + '\'';

        if ( String.isNotBlank( strCriteria ) )  

            strSOQL += ' ' + strCriteria;   

        strSOQL += ' LIMIT 4';  

        listsObjects = Database.query( strSOQL );    

        Integer intCount = listsObjects.size();  

        if ( intCount > 3 ) {  

              

            List < sObject > tempListsObjects = new List < sObject >();  

            for ( Integer i = 0; i <3; i++ )  

                tempListsObjects.add( listsObjects.get( i ) );  

              

            obj.listsObject = tempListsObjects;  

            strTitle += '3+';  

              

        } else {  

              

            obj.listsObject = listsObjects;  

            strTitle += String.valueOf( intCount );  

              

        }  

        strTitle += ')';        

        obj.strTitle = strTitle;  

        return obj;  

          

    }  

      

    public class RelatedListResult {        

        @AuraEnabled  

        public String strTitle;  

        @AuraEnabled  

        public List < sObject > listsObject;  

          

    }  

}


RelatedList.cmp:

-------------------

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" controller="RelatedListController" >  

      

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

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

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

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

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

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

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

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

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

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

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

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

    <aura:attribute name="listRecords" type="sObject[]"/>  

      

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

      

    <lightning:card iconName="{!v.iconName}">  

          

        <aura:set attribute="title">  

              

            <aura:if isTrue="{!not(empty(v.listRecords))}">  

                  

                <lightning:button variant="base"   

                                  label="{!v.title}"   

                                  title="View All Action"   

                                  onclick="{! c.viewRelatedList }"/>  

                  

            </aura:if>  

              

        </aura:set>  

          

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

              

            <aura:iteration items="{!v.listRecords}" var="item">  

                  

                <!--lightning:button variant="base"   

                                  label="{! 'View ' + v.ObjectName }"   

                                  title="View"   

                                  onclick="{! c.viewRecord }"  

                                  value="{!item.Id}"/-->  

                <lightning:recordViewForm recordId="{!item.Id}" objectApiName="{!v.sobjectName}">  

                      

                    <div class="slds-grid">  

                        <div class="slds-col slds-size_1-of-2">  

                            <lightning:outputField fieldName="{!v.field1}" />  

                        </div>  

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

                            <div class="slds-col slds-size_1-of-2">  

                                <lightning:outputField fieldName="{!v.field2}" />  

                            </div>  

                        </aura:if>

                    </div>  

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

                        <div class="slds-grid">  

                            <div class="slds-col slds-size_1-of-2">  

                                <lightning:outputField fieldName="{!v.field3}" />  

                            </div>

                            <div class="slds-col slds-size_1-of-2">  

                                <lightning:outputField fieldName="{!v.field4}" />  

                            </div>  

                        </div>  

                    </aura:if>

                              

                </lightning:recordViewForm><br/><br/>  

                  

            </aura:iteration>  

        </p>  

                  

        <aura:set attribute="footer">  

              

            <aura:if isTrue="{!not(empty(v.listRecords))}">  

                  

                <lightning:button variant="base"   

                                  label="View All"   

                                  title="View All Action"   

                                  onclick="{! c.viewRelatedList }"/>  

                  

            </aura:if>  

              

        </aura:set>  

          

    </lightning:card>  

      

</aura:component>



js controller:

-------------

({  

      

    fetchRecords : function(component, event, helper) {  

          

        var temObjName = component.get( "v.sobjectName" );  

        component.set( "v.ObjectName", temObjName.replace( "__c", "" ).replace( "_", " " ) );  

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

        action.setParams({  

            recId: component.get( "v.recordId" ),  

            sObjName: temObjName,  

            parentFldNam: component.get( "v.parentFieldName" ),  

            strCriteria: component.get( "v.criteria" )  

        });  

        action.setCallback(this, function(response) {  

            var state = response.getState();  

            if ( state === "SUCCESS" ) {  

                  

                var tempTitle = component.get( "v.title" );  

                component.set( "v.listRecords", response.getReturnValue().listsObject );  

                component.set( "v.title", tempTitle + response.getReturnValue().strTitle );  

                  

            }  

        });  

        $A.enqueueAction(action);  

          

    },  

      

    viewRelatedList: function (component, event, helper) {  

          

        var navEvt = $A.get("e.force:navigateToRelatedList");  

        navEvt.setParams({  

            "relatedListId": component.get( "v.childRelName" ),  

            "parentRecordId": component.get( "v.recordId" )  

        });  

        navEvt.fire();  

    },  

      

    viewRecord: function (component, event, helper) {  

          

        var navEvt = $A.get("e.force:navigateToSObject");  

        var recId = event.getSource().get( "v.value" )  

        navEvt.setParams({  

            "recordId": recId  

        });  

        navEvt.fire();  

          

    }  

      

})


Docimentation:

------------

<aura:documentation>

<aura:description>Documentation</aura:description>

<aura:example name="ExampleName" ref="exampleComponentName" label="Label">

Example Description

</aura:example>

</aura:documentation>



design:

------

<design:component >

    <design:attribute name="title" label="Title" required="true"/>  

    <design:attribute name="parentFieldName" label="Parent Field API Name" required="true"/>  

    <design:attribute name="sobjectName" label="Object API Name" required="true"/>  

    <design:attribute name="criteria" label="Additonal Criteria"/>  

    <design:attribute name="childRelName" label="Child Relationship Name" required="true"/>  

    <design:attribute name="iconName" label="Icon Name" required="true"/>  

    <design:attribute name="field1" label="Field 1" required="true"/>  

    <design:attribute name="field2" label="Field 2" />  

    <design:attribute name="field3" label="Field 3" /> 

</design:component>


SVG:

----

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>

<svg width="120px" height="120px" viewBox="0 0 120 120" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">

<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">

<path d="M120,108 C120,114.6 114.6,120 108,120 L12,120 C5.4,120 0,114.6 0,108 L0,12 C0,5.4 5.4,0 12,0 L108,0 C114.6,0 120,5.4 120,12 L120,108 L120,108 Z" id="Shape" fill="#2A739E" />

<path d="M77.7383308,20 L61.1640113,20 L44.7300055,63.2000173 L56.0543288,63.2000173 L40,99.623291 L72.7458388,54.5871812 L60.907727,54.5871812 L77.7383308,20 Z" id="Path-1" fill="#FFFFFF" />

</g>

</svg>

Sample LWC data table using Apex class

 import { LightningElement ,api, wire, track} from 'lwc';

import getInvestigations from '@salesforce/apex/IMS_CaseFieldSet.getInvestigations';

export default class IMS_PrintInvestigations extends LightningElement {

    @track columns = [{

            label: 'Name',

            fieldName: 'Name',

            type: 'text',

            sortable: true

        },

        {

            label: 'Type',

            fieldName: 'Type__c',

            type: 'text',

            sortable: true

        },

        {

            label: 'Other Text',

            fieldName: 'Other_Text__c',

            type: 'Currency',

            sortable: true

        },

        {

            label: 'Phone',

            fieldName: 'Phone',

            type: 'phone',

            sortable: true

        },

        {

            label: 'CreatedById',

            fieldName: 'CreatedById',

            type: 'date',

            sortable: true

        },

        {

            label: 'LastModifiedById',

            fieldName: 'LastModifiedById',

            type: 'Date',

            sortable: true

        },

{

            label: 'Investigator Notes',

            fieldName: 'Investigator_Notes__c',

            type: 'text',

            sortable: true

        }

    ];

 

    @track error;

    @track invlist ;

    @wire(getInvestigations, { CaseId: '$CaseId' })

    wiredAccounts({

        error,

        data

    }) {

        if (data) {

            this.invlist = data;

        } else if (error) {

            this.error = error;

        }

    }

}



<template>

    <h2> Related Investigations </h2>

    <template if:true={invlist}>

        <lightning-datatable data={invlist} columns={columns} key-field="Id">

        </lightning-datatable>

    </template>

    <template if:true={error}>

        {error}

    </template>

</template>

Sample Lightning Component HTML Table using tr and td

 <div class="slds-background-clr slds-text-heading_small">

            Incidents

        </div>

        <div class="slds-p-right_x-large">

            <table class="slds-table slds-table--bordered slds-table_fixed-layout">

                <thead>

                    <tr class="slds-text-title--caps">

                        <th scope="col">

                            <div class="slds-truncate" title="Incident Number">Incident Number</div>

                        </th>

                        <th scope="col">

                            <div class="slds-truncate" title="Incident category">Incident Category</div>

                        </th>

                        <th scope="col">

                            <div class="slds-truncate" title="Incident Sub Category">Incident Sub Category</div>

                        </th>

                        <th scope="col">

                            <div class="slds-truncate" title="Incident Created Date">Incident Created Date</div>

                        </th>

                    </tr>

                </thead>

                <tbody>

                    <aura:iteration items="{!v.ObjInc}" var="inc">

                        <tr>

                            <td data-label="Incident Number">

                                <div class="slds-truncate">{!inc.Alleged_Person_s_Responsible__r.Name}</div>

                            </td>

                            <td data-label="Incident category">

                                <div class="slds-truncate">{!inc.Alleged_Person_s_Responsible__r.Incident_Type__c}</div>

                            </td>

                            <td data-label="Incident Sub Category">

                                <div class="slds-truncate">{!inc.Alleged_Person_s_Responsible__r.Incident_Sub_Type__c}</div>

                            </td>

                            <td data-label="Incident Created Date">

                                <div class="slds-truncate">{!inc.Alleged_Person_s_Responsible__r.CreatedDate}</div>

                            </td>

                        </tr>

                        

                    </aura:iteration>

                </tbody>

            </table>

        </div>

        <br/>

        <div class="slds-background-clr slds-text-heading_small">

            Violators (Associates)

        </div>

        <div class="slds-p-right_x-large">

            <table class="slds-table slds-table--bordered slds-table_fixed-layout">

                <thead>

                    <tr class="slds-text-title--caps">

                        <th scope="col">

                            <div class="slds-truncate" title="First Name">First Name</div>

                        </th>

                        <th scope="col">

                            <div class="slds-truncate" title="Last Name">Last Name</div>

                        </th>

                        <th scope="col">

                            <div class="slds-truncate" title="Relationship to Individual">Relationship to Individual</div>

                        </th>

                        <th scope="col">

                            <div class="slds-truncate" title="Provider Name">Provider Name</div>

                        </th>

                        <th scope="col">

                            <div class="slds-truncate" title="Priovider #">Priovider #</div>

                        </th>

                    </tr>

                </thead>



                <tbody>

                    <aura:iteration items="{!v.ObjInc}" var="violator">

                        <tr>

                            <td data-label="First Name">

                                <div class="slds-truncate">{!violator.First_Name__c}</div>

                            </td>

                            <td data-label="Last Name">

                                <div class="slds-truncate">{!violator.Last_Name__c}</div>

                            </td>

                            <td data-label="Relationship to Individual">

                                <div class="slds-truncate">{!violator.Relationship_to_Individual__c}</div>

                            </td>

                            <td data-label="Provider Name">

                                <div class="slds-truncate">{!violator.Provider_Agency__c}</div>

                            </td>

                            <td data-label="Priovider #">

                                <div class="slds-truncate">{!violator.Name}</div>

                            </td>

                        </tr>

                        

                    </aura:iteration>

                </tbody>

            </table>

        </div>

        <br/>

Salesforce to BIt.ly API Integration using HTTP CallOut

 1. Using in site URL

--------------------

@RestResource(urlMapping='/ProcessBitlyAPIService/*')

Global with sharing class BitlyWebService {

    @HttpPost

    global static void AcuityWebService1123() {

        string username = '**************'; //Bitly username

        String password = '**************'; //Bitly password


        Blob headerValue = Blob.valueOf(username + ':' + password);

        String authorizationHeader = 'BASIC ' +EncodingUtil.base64encode(headerValue);

        

        //String authorizationHeader = 'Basic'+base64encode(username + ":" + password);

        

       

        //BitlyCalloutService.doGet12(authorizationHeader);


}

}


2. HTTP Call Out

----------------

public class BitlyCalloutService {

    public static String getscheduleLink(String endPoint){

        HttpRequest req = new HttpRequest();

        req.setEndpoint(endPoint);

        req.setMethod('GET');

        

        Http h = new Http();

        String resp;

        HttpResponse res = h.send(req);

        resp=res.getBody();

        string shortUrl;

        JSONParser parser = JSON.createParser(resp);

        

        Map <String, Object> root = (Map <String, Object>) JSON.deserializeUntyped(resp);

        Map <String, Object> mapdata=(Map <String, Object> )root.get('data');

        Object url=mapdata.get('url');

        shortUrl=url.toString();

        

        return shortUrl;

    }

    public static void caseinsert(string shortUrl){

        case caselist = new case();

        if (Schema.sObjectType.case.fields.OpenSMSPro__Schedule_link__c.isUpdateable()) {

            caselist.OpenSMSPro__Schedule_link__c = shortUrl;

        }

        Update caselist;

    }

    

    public static String getRescheduleLink(Task taskObj){

        HttpRequest req = new HttpRequest();

        

        String longurl='https://app.acuityscheduling.com/schedule.php?action=appt&owner=18252599&id[]='+taskObj.OpenSMSPro__Reschedule_URL_Id__c+'&apptId='+taskObj.OpenSMSPro__Appointment_ID__c;

        

        //Blob b=EncodingUtil.base64Decode(longurl);

        String encodeurl=EncodingUtil.urlEncode(longurl, 'UTF-8');

        String endPoint='https://api-ssl.bitly.com/v3/shorten?access_token=21c0957767b791442080cf2674fada89ddf60171&longurl=';

        endPoint+=encodeurl;

        endPoint+='&format=json';

        req.setEndpoint(endPoint);

        req.setMethod('GET');

        Http h = new Http();

        String resp;

        HttpResponse res = h.send(req);

        resp=res.getBody();

        string shortUrl1;

        JSONParser parser = JSON.createParser(resp);

        

        Map <String, Object> root = (Map <String, Object>) JSON.deserializeUntyped(resp);

        Map <String, Object> mapdata=(Map <String, Object> )root.get('data');

        Object url=mapdata.get('url');

        shortUrl1=url.toString();

        

        return shortUrl1;

        

    }

    public static void taskinsert(string shortUrl1){

        task tasklist = new task();

        if (Schema.sObjectType.task.fields.OpenSMSPro__Reschedule_Link__c.isUpdateable()) {

            tasklist.OpenSMSPro__Reschedule_Link__c = shortUrl1;

        }

        Update tasklist;

    }

}

Sample Salesforce Batch Class

global class TaskShortURLBatch implements Database.Batchable<sobject>,Database.AllowsCallouts {

         //added code for reschedule link

  public  List<Id> t;

    public TaskShortURLBatch(List<Id> t){

        this.t=t;

    }

   global Database.QueryLocator start(Database.BatchableContext BC){

       //added code for reschedule link

       String query1='select id,OpenSMSPro__Reschedule_URL_Id__c,OpenSMSPro__Appointment_ID__c from task where id in:t';

      return Database.getQueryLocator(query1);

   }

   global void execute(Database.BatchableContext BC, List<sobject> scope){ 

       //added code for RescheduleLink

       List<task> tasklists = scope;

       for(Task taskobj : tasklists){

        String shortURL1=BitlyCalloutService.getRescheduleLink(taskObj);

           taskObj.OpenSMSPro__Reschedule_Link__c = shortUrl1;

       }  

           update tasklists;   

        //ended

   }

   global void finish(Database.BatchableContext BC){

   }

}

CSS Styling

Styling: 1. Inline Styling: < div style = "font-size: 2rem;font-weight: 400;" > Good Evening </ div > 2. Usi...