Skip to content

Instantly share code, notes, and snippets.

@ykurnia
ykurnia / gist:4162169
Created November 28, 2012 15:59
Salesforce trigger to generate invoice number, reset each year
trigger InvoiceTrigger on Invoice__c (before insert) {
if (trigger.isBefore && trigger.isInsert)
{
// ---- GENERATE INVOICE NUMBER, AUTO RUNNING NUMBER, RESET EVERY YEAR BASED ON CREATED DATE --- //
// ---- INVOICE NUMBER FORMAT : {0000} --//
Integer iCharLen = 4; // character length for number
Integer iLastNo = 0; // information last running number this year
Integer iThisYear = Date.Today().year();
// search latest invoice number
@ykurnia
ykurnia / gist:4176831
Created November 30, 2012 16:35
Salesforce trigger to generate invoice number, reset each month, based on Invoice Date {YYYY}-{MM}-{000}
trigger InvoiceTrigger2 on Invoice__c (before insert) {
if (trigger.isBefore && trigger.isInsert)
{
// ---- GENERATE INVOICE NUMBER, AUTO RUNNING NUMBER, RESET EVERY MONTH BASED ON INVOICE DATE --- //
// ---- INVOICE NUMBER FORMAT : {YYYY}-{MM}-{000} --//
// ---- ASSUME THAT INVOICE DATE CAN BE BACKDATED -- //
Integer iCharLen = 3; // character length for number
Integer iLastNo = 0; // information last running number this year
String strZero = '0';
@ykurnia
ykurnia / trigger_autonumber3.java
Created December 4, 2012 13:10
Salesforce trigger to generate invoice number, each account has its own running number, format {AccountNumber}-{YYYY}-{MM}-{000}
trigger InvoiceTrigger3 on Invoice__c (before insert) {
if (trigger.isBefore && trigger.isInsert)
{
// ---- GENERATE INVOICE NUMBER, AUTO RUNNING NUMBER, EACH ACCOUNT HAS ITS OWN RUNNING NUMBER --- //
// ---- INVOICE NUMBER FORMAT : {ACCOUNTNUMBER}-{YYYY}-{MM}-{000} --//
// ---- ASSUME THAT ACCOUNT NUMBER IS MANDATORY -- //
// ---- BECAUSE WE HAVE YEAR AND MONTH INFORMATION IN THE NUMBER, EASIER IF WE CREATE A FIELD FOR THE NUMBER [ACC RUNNING NO] --//
Integer iCharLen = 3; // character length for number
Integer iLastNo = 0; // information last running number this year
String strZero = '0';
@ykurnia
ykurnia / NewQuotationController.java
Created August 29, 2013 10:41
This is Controller example how to override New button, and provide some default value for Name field and Record Type selection in salesforce.com
// transition page to create new page with default Name field
public class NewQuotation_Controller
{
public NewQuotation_Controller(ApexPages.StandardController controller)
{
//CreateNew();
} // constructor
// function to process
@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>
@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 / 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 / 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 / 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 / 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()));