Skip to content

Instantly share code, notes, and snippets.

View dhaniksahni's full-sized avatar

Dhanik Lal Sahni dhaniksahni

View GitHub Profile
@dhaniksahni
dhaniksahni / S3FileController.apxc
Created January 23, 2020 18:52
Get File Information for S3 Server
public class S3FileController {
@AuraEnabled
public static string getFileUrl(string record)
{
try
{
List<FileStore__c> files=[SELECT S3ServerUrl__c,FileExtension__c FROM FileStore__c
where Id=:record];
FileStore__c file=files[0];
return file.S3ServerUrl__c;
public class S3Controller {
@AuraEnabled
public static FileData GetS3FileUsingFileId(string recordId)
{
String key = '**************';
String secret = '*********************************';
String bucket = 'salesforcecodex';
String host = 's3-us-west-1.amazonaws.com';
String method = 'GET';
<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 / CaptureScreen.cmp
Last active January 30, 2020 13:42
CaptureSignature
<aura:component controller="CommandController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<aura:attribute name="commandText" type="string" />
<lightning:card title="Capture Screen">
<p>
<button id="start" onclick="{! c.takeScreenShot }">Start Capture</button>&nbsp;
<button id="stop">Stop Capture</button>
</p>
<div style="display: none;">
<video id="video" autoplay="true"></video>
@dhaniksahni
dhaniksahni / FileReader.apxc
Last active February 2, 2020 08:07
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';