Skip to content

Instantly share code, notes, and snippets.

@mxalix258
mxalix258 / Field update if contained in set
Created May 31, 2013 15:42
Check if field value is contained in a defined set, and update the field.
trigger OnboardingEvacSectionUpdate on On_Off_Boarding__c (before insert, before update){
List <On_Off_Boarding__c> obToUpdate = new List <On_Off_Boarding__c> ();
//New set is defined that contains the values 202, 0-203A, etc
Set <String> s1 = new Set<String>{'202', '0-203A'};
For(On_Off_Boarding__c ob: Trigger.new){
// Checks if Desk_location1__c is in the set s1, and updates the field
@mxalix258
mxalix258 / Single VF related list with custom controller
Created June 18, 2013 01:38
Display a related list on a Visualforce page that is using a custom controller. This grabs the record ID from the URL to display the specified related list.
@mxalix258
mxalix258 / New record Visualforce replacement
Created June 26, 2013 01:04
Replace "New" page with visualforce page with apex extension
<apex:page standardController="Leave_Request__c" extensions="vacationdays" showHeader="true" sidebar="true">
<apex:form >
<apex:sectionHeader subtitle="New Leave Request" title="Leave Request Edit"/>
<apex:pageBlock title="Leave Request Edit" mode="edit" >
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Information" >
<apex:outputField label="Owner" value="{!UserInfo.Name}"/>
@mxalix258
mxalix258 / Visualforce Extension Test
Created June 26, 2013 01:19
Method for testing a visualforce extension and controller methods.
@isTest
//class name
private class vacationdaysTEST{
//test method
private static testMethod void vacationdaysTEST(){
//instantiate the object on which the extension is defined.
Leave_Request__c lr = new Leave_Request__c();
//instantiate standardcontroller, pass object variable into constructor
ApexPages.StandardController sc = new ApexPages.StandardController(lr);
//instantiate extension controller, pass standard controller variable into constructor
@mxalix258
mxalix258 / Populate user field Test class
Created June 26, 2013 01:24
For each new leave request, should find the user's manager, and populate the user id into the lookup on the leave request record.
@isTest
private class UpdateLeaveRequestTEST {
static testMethod void validateUpdateLeaveRequest() {
Leave_Request__c LR = new Leave_Request__c();
System.debug('Manager before insert'+ LR.Manager__c);
// Insert Time Sheet
insert LR;
@mxalix258
mxalix258 / SOQL to find records with related records
Created August 26, 2013 23:08
SOQL Query to find all records, with a specific related record. In this case, it is finding all Accounts with atleast one opportunity record
@mxalix258
mxalix258 / Fiscal year calculations apex
Created August 27, 2013 01:06
Programatically find fiscal year values in apex
//for loop to find Opportunity Stages that are Closed and Won
for(OpportunityStage oppstage : oppstages){
if(oppstage.IsClosed == True && oppstage.IsWon == True){
wonstages.add(oppstage.MasterLabel);
}
}
Integer currentFY;
Integer currentFYMonth;
Integer CurrentFYDays;
Date today;
@mxalix258
mxalix258 / example SQL.sql
Created January 29, 2014 21:45
Function to parse a delimited string and return a table
--declare a table where the parsed values can be stored
DECLARE @ParsedStringTable TABLE
(
--set a column named "Source"
Source varchar(20)
)
INSERT INTO @ParsedStringTable
-- pass delimited string and delimter into function (CKI+FEE+IHS, '+')
@mxalix258
mxalix258 / Caution Message.java
Created March 29, 2014 18:58
Caution message display in Visualforce
<apex:pageMessage summary="Now click on Display options button to select custom setting." severity="warning" strength="3" rendered="{!DisplayMsgFlag}"/>
@mxalix258
mxalix258 / Page Messages & Icons.java
Created March 29, 2014 22:17
Visualforce page messages and icons. Error, caution, info, warning, fatal
<apex:page >
<apex:pageBlock title="Small Messages">
<apex:pageMessage summary="This is a warning" severity="confirm" strength="1" />
<apex:pageMessage summary="This is a piece of information" severity="info" strength="1" />
<apex:pageMessage summary="This is a warning" severity="warning" strength="1" />
<apex:pageMessage summary="This is an error" severity="error" strength="1" />
<apex:pageMessage summary="This is a fatal message" severity="fatal" strength="1" />
</apex:pageBlock>
<apex:pageBlock title="Medium Messages">
<apex:pageMessage summary="This is a warning" severity="confirm" strength="2" />