This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@isTest | |
private class TestDemoWebCallout { | |
static testMethod void testRestfulCallout() { | |
Lead l = new Lead(); | |
l.Status = 'Open'; | |
l.LastName = 'Owen'; | |
l.FirstName = 'Bob'; | |
l.Street = '1234 Sesame Street'; | |
l.City = 'Houston'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
====================================================================== | |
The following apex code demonstrates logging into another salesforce | |
org via the SOAP/XML web service api and then using session id to | |
query the standard REST API as well as the Chatter REST API. | |
To run this code, simply copy and paste into execute anonymous, | |
then replace the value of the first three variables accordingly. | |
NOTES: | |
(1) You'll need to create a remote site setting for both the login |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Taken from: http://www.johnwestenhaver.com/2015/03/how-much-of-your-apex-is-comments.html | |
I am unsure why string method .replaceAll is needed but I assume it is because the .trim method doesn't remove white | |
space at the start of a line. | |
http://www.salesforce.com/us/developer/docs/dbcom_apex250/Content/apex_methods_system_string.htm | |
This is an execute anon script */ | |
Integer classLines = 0; | |
Integer classComments = 0; | |
Integer triggerLines = 0; | |
Integer triggerComments = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This Javascript snippet can be used on a custom button to pass a parameter to a report allowing dynamic reports. | |
// window.open("salesforce_instance.com/reportId?firstparamater) | |
// More info on using Javascript behind custom buttons to create dynamic reports can be found here: http://www.tgerm.com/2011/04/passing-params-to-reports-salesforce.html | |
window.open("https://eu0.salesforce.com/00O11000000P42z?pv0={!Account.Id}", "Key_Contacts", "toolbar=0, scrollbars=1"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Typically you would use Batch Apex for this or if you wanted it via a trigger, it would utilize a helper class. Nonetheless, the code may be useful. | |
trigger NumberOfApprovedContracts on Contract (after delete, after insert, after update, after undelete) { // trigger context variables | |
Set<Id> toUpdateAccIds = new Set<Id>(); | |
//Set<Id> zeroAccIds = new Set<Id>(); | |
// IF CONTRACT CREATED OR UNDELETED, FOR ALL THESE CONTRACTS, IF APPROVED THEN ADD CONTRACT ACCOUNT ID TO THE SET | |
if(Trigger.isInsert || Trigger.isUndelete) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//A common pattern for triggered operations in Apex | |
public static void updateContactPhone (List<Account> priorAccounts, List<Account> updatedAccounts) { // static method, takes 2 List params of Account sObject type | |
Set<Id> modifiedAccounts_Ids = new Set<Id>(); | |
for (Integer i=0; i<updatedAccounts.size(); i++) { // Array notation - Alternative is... for (Account a : updatedAccounts) { | |
if (updatedAccounts[i].Phone != priorAccounts[i].Phone) { // if the phone number is different... (use dot notation to get to field value) | |
modifiedAccounts_Ids.add(updatedAccounts[i].Id); // add the Account Id to the List collection | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Custom controller for Visualforce Page - Example 1 | |
// Probably the nicest part of this controller is: 'AND OwnerId = :UserInfo.getUserId' | |
// which utilizes the getUserId method from the UserInfo class. More info here: salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_userinfo.htm | |
public class OpportunityRevisitDatesController { | |
public ApexPages.StandardSetController ssc { // allows us to create list controllers | |
get { | |
if(ssc == null) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page controller="OpportunityRevisitDatesController" sidebar="true" showHeader="true"> | |
<apex:pageBlock > | |
<b>Hi {!$User.FirstName} - you have <u>{! opportunities.size}</u> New Business opportunities which have | |
a revisit date in the past. Please update these opportunities with a correct revisit date.</b> | |
<apex:pageBlockSection > | |
</apex:pageBlockSection> | |
<apex:pageBlockTable value="{! opportunities}" var="opps" rendered="{! opportunities.size>0}"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is a Salesforce formula which uses CASE, ISPICKVAL and boolean conditions. | |
CASE(Split_Region__c, | |
"Hong Kong", "Hong Kong", | |
"Singapore", "Singapore", | |
"Australia & NZ", "Australia & NZ", | |
"Japan", "Japan", | |
"Canada", "Canada", | |
"Caribbean", "LATAM", | |
"Latin America", "LATAM", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This simple trigger changes the value of the standard Activity field 'Type' on task records to 'Email' if, before insert, the task is BLANK. | |
// This trigger could be improved upon by creating a method in a helper class to keep the trigger logicless. | |
trigger TaskWithBlankType of Task (before insert) { // 'before insert' is the trigger context variable | |
for (Task t : Trigger.new) { // for loop - for all tasks which match the trigger context variable... | |
if (t.Type == null) { // if branch nested in the for loop. If the type on the task is empty... | |
t.Type = 'Email'; // change the value of the Type to 'Email'. Remember: no DML operations required on 'before' trigger context variables | |
} | |
} | |
} |