Monday, 26 October 2020

Date Format in lightning Component dd-mmm-yy (22-OCT-2020)



var monthNames = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN",

"JUL", "AUG", "SEP", "OCT", "NOV", "DEC"

];


var date = new Date('01-JAN-2016')

date.setDate(date.getDate() - 1)

date = date.getDate()+"-"+monthNames[date.getMonth()]+"-"+date.getFullYear()


console.log(date)

Thursday, 10 September 2020

correct mime type for docx, pptx etc?

 

Extension MIME Type
.doc      application/msword
.dot      application/msword

.docx     application/vnd.openxmlformats-officedocument.wordprocessingml.document
.dotx     application/vnd.openxmlformats-officedocument.wordprocessingml.template
.docm     application/vnd.ms-word.document.macroEnabled.12
.dotm     application/vnd.ms-word.template.macroEnabled.12

.xls      application/vnd.ms-excel
.xlt      application/vnd.ms-excel
.xla      application/vnd.ms-excel

.xlsx     application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.xltx     application/vnd.openxmlformats-officedocument.spreadsheetml.template
.xlsm     application/vnd.ms-excel.sheet.macroEnabled.12
.xltm     application/vnd.ms-excel.template.macroEnabled.12
.xlam     application/vnd.ms-excel.addin.macroEnabled.12
.xlsb     application/vnd.ms-excel.sheet.binary.macroEnabled.12

.ppt      application/vnd.ms-powerpoint
.pot      application/vnd.ms-powerpoint
.pps      application/vnd.ms-powerpoint
.ppa      application/vnd.ms-powerpoint

.pptx     application/vnd.openxmlformats-officedocument.presentationml.presentation
.potx     application/vnd.openxmlformats-officedocument.presentationml.template
.ppsx     application/vnd.openxmlformats-officedocument.presentationml.slideshow
.ppam     application/vnd.ms-powerpoint.addin.macroEnabled.12
.pptm     application/vnd.ms-powerpoint.presentation.macroEnabled.12
.potm     application/vnd.ms-powerpoint.template.macroEnabled.12
.ppsm     application/vnd.ms-powerpoint.slideshow.macroEnabled.12

.mdb      application/vnd.ms-access

Friday, 7 August 2020

Get Database.SaveResult error and sucesses list

 

To get the Error for Database.update which can be used in Classes

if (accountstoUpd.size() > 0) {

Database.SaveResult[] lsr = Database.update(accountstoUpd,false);

Integer recordid = 0;

for (Database.SaveResult SR : lsr) {

if (!SR.isSuccess()) {

this.errormsgs += 'Account Record:' + accountstoUpd[recordid].id + ', ' + SR.getErrors()[0].getMessage() + '<br/>';

}

recordid++;

}

}

if (this.errormsgs.length() > 0) {

ErrorLogs__c errtoSave = new ErrorLogs__c(details__c = this.errormsgs);

insert errtoSave;

}

Thursday, 6 August 2020

Logout from Community Portal using apex


Please use below code to redirect to community login page :

window.location.replace("<community-domain>/secur/logout.jsp?retUrl=<redirect-URL>");

Eg: 

1)  window.location.replace("/testPortal/secur/logout.jsp?retUrl=%2Flogin");

2)  window.location.replace("https://mycommunity-domain.com/secur/logout.jsp?retUrl=https%3A%2F%2Fmycommunity-domain.com%2Flogin");

Monday, 29 June 2020

Internal Refresh on component when event occurs


Scenario: In the lightning Layout details page will be standard page and besides, we have custom components. when the status is changed in standard layout then component should be refreshed.

used the below code in the Lightning component.

<aura:dependency resource="markup://force:editRecord" type="EVENT" />
<aura:handler event="force:refreshView" action="{!c.doInit}" />

Wednesday, 15 April 2020

Get Parent Record Id From Lightning URL



In component Create an attribute.

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


In Init method use the below code to get parent record Id from Related list.

        var pageRef = component.get("v.pageReference");      
        console.log(JSON.stringify(pageRef));      
        var state = pageRef.state; // state holds any query params      
        console.log('state = '+JSON.stringify(state));      
        var base64Context = state.inContextOfRef;      
        console.log('base64Context = '+base64Context);      
        if (base64Context.startsWith("1\.")) {          
            base64Context = base64Context.substring(2);          
            console.log('base64Context = '+base64Context);      
        }      
        var addressableContext = JSON.parse(window.atob(base64Context));      
        console.log('addressableContext = '+JSON.stringify(addressableContext));
        component.set("v.recordId", addressableContext.attributes.recordId);
        console.log('rec Id---'+component.get("v.recordId"));

reference : https://sfdclesson.com/2019/11/23/get-parent-record-id-from-lightning-url/


Thursday, 9 April 2020

Disable right-click in Salesforce Lightning Page



component add this:

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

In JS file add this in doInit:

doInit : function(component, event, helper) {
       document.addEventListener('contextmenu', event => event.preventDefault());

},