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
trigger CompetitorContactTrigger on Contact (before insert, before update) { | |
//Get a list of all our Competitors' names from our Custom Metadata | |
//Create an empty List of Strings to hold your Competitors' names | |
for(){//Query your Custom Metadata and get its Label field | |
//Add the Label to your List of Strings | |
} | |
//Create a Map of IDs to Accounts; populate your map on the same line by putting a query in the parentheses. | |
//Your query will just get Account IDs from Account where the Name is in your List of Strings |
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
trigger LeadTrigger on Lead (After Update) { | |
Map<Id, Lead> leadsToUpdate = new Map<Id, Lead>(); | |
List<Competitor__mdt> competitorRecords = [Select Label from Competitor__mdt];//Retrieve our Custom Metadata Records | |
List<String> competitorNames = new List<String>();//Instantiate an empty list to hold the names of our competitors | |
for(Competitor__mdt record : competitorRecords){//Loop through the Custom Metadata records our query returned | |
competitorNames.add(record.Label);//Add them to our empty list | |
} | |
for(Integer i = 0 ; i < trigger.new.size() ; i++){ |
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 | |
public class LeadTriggerTest { | |
public static testMethod void testOneClosedNotConverted(){ | |
Lead l = new Lead(); | |
l.LastName = 'Lead Last Name'; | |
l.Company = 'Lead Company'; | |
insert l; | |
test.startTest(); |
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 simple batch Apex class to demonstrate updating a field on Opportunity | |
* Can be executed from Anonymous Apex using 2 lines: | |
* OpportunityBatch oppBatch = new OpportunityBatch(); | |
* database.executeBatch(oppBatch); | |
*/ | |
global class OpportunityBatch implements Database.Batchable<sObject> { | |
global Database.QueryLocator start(Database.BatchableContext BC) { | |
String query = 'SELECT Id,Name FROM Opportunity'; | |
return Database.getQueryLocator(query); | |
} |
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
trigger AccountTrigger on Account (after update) { | |
//prepare an empty Map of ID-to-Account for your updates | |
Map<ID, Account> acctMapToUpdate = new Map<Id, Account>(); | |
//prepare a for-loop you can use to compare old and new field values | |
for(Integer i = 0 ; i < trigger.new.size() ; i++){ | |
Account old = trigger.old[i]; | |
Account nw = trigger.new[i]; | |
//Evaluate Custom Settings to decide whether to execute actions |
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
public class LogUtility { | |
public static void messageLog(String classMethod, String customMessage, Set<Id> recordIds) { | |
Case logEntry = new Case( | |
Type = 'Message', | |
Subject = customMessage, | |
Description = 'Record IDs: ' + recordIds + '\n' | |
+ customMessage); | |
insertLog(logEntry, classMethod); | |
} | |
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
/* BatchRecordUpdate will update any 1 field on any 1 object. | |
* | |
* String values must be set to Object, Field and Value to be added to Field. | |
* | |
* Query can be modified to limit records updated. | |
* Example below excludes records for which Degree Offering already equals the new value. | |
* | |
* All 4 strings' values must be set to operate when executed. | |
* | |
* Execute in Anonymous Apex. |
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
public class ContactAfterInsert { | |
public static void setContactDeptIT(List<Contact> cons){ | |
List<Contact> consToUpdate = new List<Contact>(); | |
for(Contact conInTrigger : cons){ | |
Contact c = new Contact(Id = conInTrigger.Id, Department = 'IT'); | |
consToUpdate.add(c); | |
} | |
update consToUpdate; |
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
public class ContactBeforeInsert { | |
public static void setContactTitle(List<Contact> cons){ | |
for(Contact c : cons){ | |
c.Title = 'Admin'; | |
} | |
} | |
} |
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
Trigger ContactBeforeTrigger on Contact (before insert) { | |
for(Contact c : Trigger.new){ | |
c.Title = 'Admin'; | |
} | |
} |
NewerOlder