Skip to content

Instantly share code, notes, and snippets.

View xgeek-net's full-sized avatar

Xiaoan Lin xgeek-net

View GitHub Profile
//This is a sample code for AccountTriggerHandler
public class AccountTriggerHandler extends TriggerHandler{
public override void beforeInsert(){
System.debug( 'AccountTriggerHandler beforeInsert Start' );
System.debug( 'Trigger.isExecuting : ' + isExecuting );
System.debug( 'Trigger.isInsert : ' + isInsert );
System.debug( 'Trigger.isUpdate : ' + isUpdate );
System.debug( 'Trigger.isDelete : ' + isDelete );
trigger AccountTrigger on Account (before delete, before insert, before update,
after delete, after insert, after update,after Undelete) {
TriggerHandlerManager handlerManager = new TriggerHandlerManager();
handlerManager.add( new AccountTriggerHandler() );
handlerManager.run();
}
TriggerHandlerManager.stop( 'CustomObject__c' );
TriggerHandlerManager.resume( 'CustomObject__c' );
TriggerHandlerManager.stop( 'AccountTriggerHandler' );
TriggerHandlerManager.resume( 'AccountTriggerHandler' );
public class SObjectCreation {
public static sObject createObject( String typeName ) {
Schema.SObjectType targetType = Schema.getGlobalDescribe().get( typeName );
if ( targetType == null ) {
// throw an exception
}
// Instantiate an sObject with the type passed in as an argument
// at run time.
return targetType.newSObject();
Account a = ( Account )SObjectCreation.createObject( Account.sObjectType );
public class WS_Util {
//Normal Status Code
private static String API_STATUS_NORMAL = '200';
//Error Status Code
private static String API_STATUS_ERROR = '400';
/**
* Normal JSON Response
*/
global class WS_ZipUtil {
/**
* Receive Attachments info from Attachment ParentId
*/
webService static String getAttachmentByParentId( String sfdcId ){
if( String.isEmpty( sfdcId ) ) return WS_Util.errorJson('Parameter sfdcId is required.');
List<Attachment> attachmentList = [SELECT Id, Name, Body, ContentType FROM Attachment WHERE ParentId = :sfdcId];
<apex:page standardController="Account">
<apex:includeScript value="/soap/ajax/25.0/connection.js"/>
<apex:includeScript value="/soap/ajax/25.0/apex.js"/>
<apex:includeScript value="{!URLFOR($Resource.jQuery)}"/>
<apex:includeScript value="{!URLFOR($Resource.JSZip)}"/>
<script type="text/javascript">
//Download all Attachments from sobject id
function downloadFromObjectId( btn ){