Skip to content

Instantly share code, notes, and snippets.

View dhaniksahni's full-sized avatar

Dhanik Lal Sahni dhaniksahni

View GitHub Profile
@dhaniksahni
dhaniksahni / DownloadS3File.cmp
Last active July 10, 2020 16:34
Show File in Lightning Component using AWS Javascript SDK
<aura:component controller="S3FileController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<ltng:require scripts="/resource/AWSSDK" afterScriptsLoaded="{!c.doInit}"/>
<aura:attribute name="recordId" type="String" />
<lightning:button variant="brand" label="Download File" onclick="{!c.getFile}" />
</aura:component>
@dhaniksahni
dhaniksahni / GoogleAuthService.apxc
Created January 29, 2020 18:49
Google Authentication in Salesforce Apex
public class GoogleAuthService {
// use your information at *****
private static string key = '******************************.apps.googleusercontent.com';
private Static string secert = '******************************';
private Static string redirect_uri = 'https://*******-stackoverflow-dev-ed.lightning.force.com/lightning/n/GDriveStore';
private static string authUrl='https://accounts.google.com/o/oauth2/auth';
private static string scope='https://www.googleapis.com/auth/cloud-platform';
private static string tokenUrl='https://accounts.google.com/o/oauth2/token';
@AuraEnabled
<aura:component controller="GoogleAuthService" implements="lightning:isUrlAddressable,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="accessToken" type="String" />
<lightning:card title="Google Transcription">
<lightning:button variant="brand" label="Authorize Google" title="Google Drive Auth" onclick="{! c.doAuth }" />
</lightning:card>
</aura:component>
public class MetadataService {
public static void UpdateCustomMetadata(string token) {
Metadata.CustomMetadata customMetadata = new Metadata.CustomMetadata();
customMetadata.fullName = 'GoogleAuthSetting.AccessToken';
customMetadata.label = 'AccessToken';
customMetadata.protected_x = true;
Metadata.CustomMetadataValue accessToken = new Metadata.CustomMetadataValue();
accessToken.field = 'AccessToken__c';
<aura:component controller="GoogleSpeechService" implements="lightning:isUrlAddressable,force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<aura:attribute name="recordId" type="String"/>
<lightning:card title="Google Transcription">
<lightning:button variant="brand" label="Convert Audio to Text" title="Convert Audio to Text" onclick="{! c.translate }" />
<lightning:textarea name="translatedText" label="" value="Transcript Placeholder" />
</lightning:card>
</aura:component>
@dhaniksahni
dhaniksahni / AudioData.apxc
Last active March 3, 2020 18:42
Google Speech Translation in Salesforce Apex
public class AudioData {
public class Audio {
public String content;
}
public class Config {
public String encoding;
public Integer sampleRateHertz;
public String languageCode;
public Boolean enableWordTimeOffsets;
}
@dhaniksahni
dhaniksahni / FileReader.apxc
Last active June 4, 2024 07:10
Reading Files
public without sharing class FileReader {
private static final String BASE_URL = URL.getSalesforceBaseUrl().toExternalForm();
//Reterives all files of one case or account record
@AuraEnabled
public static List<FileData> GetEntityRecordFiles(string recordId)
{
List<ContentDocumentLink> links=[SELECT ContentDocumentId,LinkedEntityId FROM ContentDocumentLink where LinkedEntityId=:recordId];
Set<Id> ids=new Set<Id>();
@dhaniksahni
dhaniksahni / ViewFile.cmp
Last active February 2, 2020 08:59
File Reader from File object in Salesforce
<aura:component
controller="FileReader"
implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction"
access="global">
<aura:attribute name="data" type="String" />
<aura:attribute name="previewUrl" type="String" />
<aura:attribute name="urlLink" type="String" />
<aura:attribute name="recordId" type="String" />
<aura:attribute name="files" type="object[]" />
<aura:attribute name="file" type="object" />
@dhaniksahni
dhaniksahni / EmailHelper.apxc
Last active February 9, 2020 18:42
Queueable Finalizer
public class EmailHelper {
public boolean sendErrorNotification(string jobId)
{
Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
message.toAddresses = new String[] { 'itops@salesforcecodex.com' };
message.subject = 'Error in Job :' +jobId ;
message.htmlbody = 'Hello Admin, </br>There is error in job.</br> Please check</br></br>. Apex Job';
Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {message};
Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
public class UpdateCaseQueuable implements Queueable {
public List<Case> caseList ;
public UpdateCaseQueuable(List<Case> cases){
this.caseList = cases ;
}
public void execute(QueueableContext context) {
for(Case a :caseList){
a.Description ='Updated from UpdateCaseQueuable';
a.Status='Closed';