Skip to content

Instantly share code, notes, and snippets.

Dhanik Lal Sahni dhaniksahni

View GitHub Profile
@dhaniksahni
dhaniksahni / childModule.html
Created Jul 9, 2020
childModule for errorCallback
View childModule.html
<template>
<c-grand-child></c-grand-child>
</template>
@dhaniksahni
dhaniksahni / parentModule.html
Created Jul 9, 2020
parentModule for errorCallback
View parentModule.html
<template>
<template if:true={hasError}>
<div class="slds-notify slds-notify_alert slds-theme_alert-texture slds-theme_error" role="alert">
<span class="slds-assistive-text">error</span>
<h2>Application Error:{error.message}
</h2>
</div>
</template>
<c-child-module></c-child-module>
</template>
View EinsteinOCRReponse.cls
public class EinsteinOCRReponse {
public list<Probability> probabilities{get;set;}
public String objects{get;set;}
public String task{get;set;}
public class Probability{
public boundingBox boundingBox{get;set;}
public String label{get;set;}
public Decimal probability{get;set;}
}
public class BoundingBox{
@dhaniksahni
dhaniksahni / EinsteinOCR.cls
Last active Jul 8, 2020
EinsteinOCR API Call from Apex
View EinsteinOCR.cls
public class EinsteinOCR {
public static String VISION_API = 'https://api.einstein.ai/v2/vision/ocr';
public static string extractText(String imageUrl, String token, String model) {
HttpRequest req = new HttpRequest();
req.setMethod('POST');
req.setEndpoint(VISION_API);
req.setHeader('content-type', 'multipart/form-data; charset="UTF-8"; boundary="1ff13444ed8140c7a32fc4e6451aa76d"');
req.setHeader('Authorization', 'Bearer '+ token); //replace token with your access token
@dhaniksahni
dhaniksahni / EinsteinController.cls
Created Jun 24, 2020
API Token Generator for Einstein AI Services
View EinsteinController.cls
public class EinsteinController {
public String getAccessToken() {
ContentVersion base64Content = [SELECT Title, VersionData FROM ContentVersion where Title='einstein_platform' OR Title='predictive_services' ORDER BY Title LIMIT 1];
String keyContents = base64Content.VersionData.tostring();
keyContents = keyContents.replace('-----BEGIN RSA PRIVATE KEY-----', '');
keyContents = keyContents.replace('-----END RSA PRIVATE KEY-----', '');
keyContents = keyContents.replace('\n', '');
JWT jwt = new JWT('RS256');
jwt.pkcs8 = keyContents;
@dhaniksahni
dhaniksahni / CaseService.apxc
Last active Jun 16, 2020
License Plate Number Reader in Salesforce
View CaseService.apxc
public class CaseService {
public static void UpdatePlateNumber(string record,string plate)
{
try
{
Case caseRecord=[Select Id, Plate_Number__c from Case where id=:record];
caseRecord.Plate_Number__c=plate;
update caseRecord;
}
@dhaniksahni
dhaniksahni / code.ts
Created Jun 7, 2020
Salesforce Codex Plugin
View code.ts
import * as fs from 'fs';
import * as fse from 'fs-extra';
import * as path from 'path';
export class Code
{
updateContent=function(content, values) {
const splitValues = values.split('=');
const varName = splitValues[0];
@dhaniksahni
dhaniksahni / trigger.cls
Created Jun 7, 2020
Salesforce Codex Plugin
View trigger.cls
public trigger {{objectName}}Trigger on {{entityName}}( after insert, after update, before insert, before update)
{
{{objectName}}TriggerHandler handler = new {{objectName}}TriggerHandler(Trigger.isExecuting, Trigger.size);
if( Trigger.isInsert )
{
if(Trigger.isBefore)
{
handler.OnBeforeInsert(trigger.New);
}
@dhaniksahni
dhaniksahni / apex.cs
Created Jun 7, 2020
salesforcecodex plugin
View apex.cs
public with sharing class {{objectName}} {
//save record
public void save{{objectName}}(string name) {
try
{
{{objectName}}Selector objRecord=new {{objectName}}Selector();
{{objectName}} record=objRecord.getByName(name);
if(record!=null)
@dhaniksahni
dhaniksahni / metadataInfo.html
Created May 31, 2020
Metadata Information using Lightning Tree Node
View metadataInfo.html
<template>
<h2>Hkhdshsa</h2>
<lightning-card title="Used Custom Metadata" icon-name="custom:custom10">
<div class="slds-grid">
<div class="slds-size--1-of-1">
<div>
<lightning-button label="Export in CSV" onclick={handleFileDownload}></lightning-button>
</div>
</div>
</div>
You can’t perform that action at this time.