Skip to content

Instantly share code, notes, and snippets.

@RoyGilad
RoyGilad / DF13_ConvertCountryToISO.trigger
Last active December 24, 2015 20:58
Using a dictionary table, saved in custom Setting, to convert countries to Country ISO code.
trigger DF13_ConvertCountryToISO on Account (before insert, before update) {
for (Account a: Trigger.new)
{
if (a.BillingCountry != null)
a.BillingCountryIsoCode__c = Country__c.getValues(a.BillingCountry).BillingCountryIsoCode__c;
}
}
@RoyGilad
RoyGilad / DF13_SimpleLabelDemoWithCustomSettings.trigger
Created October 6, 2013 23:40
An example of a simple trigger with a label and hierarchy custom setting
trigger DF13_labelDemo on Account (before insert, before update) {
for (Account a: Trigger.new)
if (a.NumberOfEmployees < Account_Fields_Minimal_Value__c.getInstance().Minimal_Number_Of_Employees__c)
a.addError(System.Label.Error_SmallNumberOfEmployees);
}
@RoyGilad
RoyGilad / DF13_SimpleLabelDemo.trigger
Created October 6, 2013 19:01
An example of a simple trigger with a label were it should have
trigger DF13_labelDemo on Account (before insert, before update) {
for (Account a: Trigger.new)
if (a.NumberOfEmployees < 5)
a.addError(System.Label.Error_SmallNumberOfEmployees);
}
@RoyGilad
RoyGilad / DF13_NolabelDemo.trigger
Last active December 24, 2015 05:39
An example of a simple trigger with NO labels were it should have...
trigger DF13_labelDemo on Account (before insert, before update) {
for (Account a: Trigger.new)
if (a.NumberOfEmployees < 5)
a.addError('Please insert a higher number of Employees');
}
@RoyGilad
RoyGilad / DF13_SalesforceIntegrationUsingFieldSet.cls
Last active December 23, 2015 18:19
Field set are also useful when creating an integration: You can add and remove fields from the exposed API, without changes in the code, for example in the code below we have created a field set for the Account object named “IntegrationFields”:
//Salesforce Force.com Apex example: integration using field-set
@RestResource(urlMapping='/Account/*')
global with sharing class MyRestResource {
@HttpGet
global static Account doGet() {
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
String query = 'SELECT ';
@RoyGilad
RoyGilad / DF13_VisualforcePageFieldSetDemo.page
Last active December 23, 2015 18:19
Demo: A Visualforce Page with a Field Set named: "PageFields" in the Account object
<apex:page standardController="Account">
<apex:messages />
<apex:form >
<apex:pageBlock title="My Content" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="My Content Section" columns="2">
<apex:repeat value="{!$ObjectType.Account.FieldSets.SampleFieldSet}" var="f">
<apex:inputField value="{! Account [f]}" required="{!OR(f.required, f.dbrequired)}"/>