Skip to content

Instantly share code, notes, and snippets.

@ykurnia
ykurnia / SampleTestClass.cls
Created May 2, 2024 06:06
Salesforce Apex Test Class example for Callout or API call
@IsTest public class SampleTestClass {
@IsTest public static void Test1()
{
// upload a file in static resource first
StaticResourceCalloutMock mock = new StaticResourceCalloutMock();
mock.setStaticResource('SampleResource'); // name of static resourc
mock.setStatusCode(200);
mock.setHeader('Content-Type', 'application/json'); // change with correct content type
@ykurnia
ykurnia / SalesforceRestModel.php
Created August 24, 2023 06:22
example rest api model to salesforce integration
<?php
namespace app\models;
use Yii;
/**
* CLASS AS WRAPPER FOR SF REST API functions
*
* @author Yudi K.
@ykurnia
ykurnia / validateUEN.js
Created July 5, 2023 06:43 — forked from mervintankw/validateUEN.js
validates that UEN (Unique Entity Number) number is valid based on https://www.uen.gov.sg/ueninternet/faces/pages/admin/aboutUEN.jspx
/**
* validates UEN of businesses in Singapore
* https://www.uen.gov.sg/ueninternet/faces/pages/admin/aboutUEN.jspx
* @param {string} uen
* @returns {boolean}
*/
function validateUEN (uen) {
var debug = true;
const entityTypeIndicator = [
'LP', 'LL', 'FC', 'PF', 'RF', 'MQ', 'MM', 'NB', 'CC', 'CS', 'MB', 'FM', 'GS', 'GA',
@ykurnia
ykurnia / AddEditMetadata.cls
Last active August 12, 2022 07:39
Contoh Update/Insert Custom Metadata Type di Salesforce
/*// update metadata type that save the counter
Di contoh ini, Custom Metadata bernama OrderLineCounter__mdt
Custom fields : Prefix__c (text), Counter__c (integer)
Input adalah map<string, Integer> berisi daftar data yang ingin diupdate/insert (bisa lebih dari satu)
*/
@future
public static void UpdateCounterMetadata(Map<String, Integer> mapCount)
{
Map<String, OrderLineCounter__mdt> mapMDT = new Map<String, OrderLineCounter__mdt>(); // prefix -> metadata
@ykurnia
ykurnia / Utility.cls
Created July 6, 2022 08:10
Utility - Kumpulan fungsi yang mungkin berguna saat membuat apex class ataupun VF Page
public class Utility {
// public get picklist options in map (string, string)
public static Map<String, String> getMapPicklist(String strObject, String strField) {
Map<String, String> options = new Map<String, String>();
Map<String,Schema.SObjectType> gd = Schema.getGlobalDescribe();
Map<String, Schema.SObjectField> field_map = gd.get(strObject).getDescribe().fields.getMap();
List<Schema.PicklistEntry> picklistValues = field_map.get(strField).getDescribe().getPickListValues();
for (Schema.PicklistEntry pv : picklistValues) {
// options.add(new SelectOption(pv.getValue(),pv.getLabel()));
@ykurnia
ykurnia / SSSCsvReader.cls
Last active August 25, 2021 11:19
Controller to upload data in CSV format to Contact and Custom object (Cases__c) as child of Contact. This example uses mapping fields, to make this programme generate and easily adopted to another object just modify the mapping.
/**
* Used to read a delimited file.
* https://gist.github.com/ngaller/858086
*/
public class SSSCsvReader {
private String delim = ',';
// the input data
private String[] buffer;
public SSSCsvReader(String data){
@ykurnia
ykurnia / CustomActiveRecord
Created April 30, 2020 11:12
Turunan dari ActiveRecord di Yii2, dengan tambahan di beforeSave yang otomatis mengisi data terkait update record (modif by, modif time, etc)
<?php
namespace app\models;
use Yii;
/**
* This is the custom model class for tables
* By Yudi K.
*/
@ykurnia
ykurnia / UserIdentity.php
Created April 30, 2020 11:09
Modified UserIdentity.php from Yii2 template, to use session instead of token, and reduce connection to database
<?php
namespace app\models;
class UserIdentity extends \yii\base\BaseObject implements \yii\web\IdentityInterface
{
public $id;
public $username;
public $password;
public $authKey;
@ykurnia
ykurnia / belajarcse1.php
Created September 3, 2015 04:47
Contoh aplikasi untuk menggunakan Google API Client untuk melakukan pencarian terhadap keyword tertentu memakai Google API
<html>
<head><title>Simple Google Search API Example</title></head>
<body>
<h1>Simple Google Search API Example</h1>
<?php
// asumsi file ini ada di folder example, folder dengan level yang sama dengan src
require_once realpath(dirname(__FILE__) . '/../src/Google/autoload.php');
$client = new Google_Client();
$client->setApplicationName("Nama Aplikasi");
@ykurnia
ykurnia / SimpleLeadList
Created November 18, 2013 08:11
Simple list of Lead with hyperlink to record
<apex:pageBlockTable var="items" value="{!listLead}" >
<apex:column headerValue="Lead">
<apex:outputLink title="Lead" value="/{!items.Id}">{!items.name}</apex:outputLink>
</apex:column>
<apex:column title="Company" value="{!items.Company}" />
<apex:column title="Phone" value="{!items.Phone}" />
<apex:column title="Email" value="{!items.Email}" />
</apex:pageblocktable>