---
title: Trigger Happy!
description: Trigger Happy!
---

- [Home](https://purplenerd.com/#home)
- [Services](https://purplenerd.com/rev-ops-services)
- [Contact](https://purplenerd.com/blog/2011/05/13/trigger-happy#contact)
- [Blog](https://purplenerd.com/blog)
- [Partners](https://purplenerd.com/partners)

# Trigger Happy!

[postaweek2011](https://purplenerd.com/blog/tag/postaweek2011) [automagic](https://purplenerd.com/blog/tag/automagic) [trigger](https://purplenerd.com/blog/tag/trigger) [@knthornt](https://purplenerd.com/blog/tag/knthornt) [help from my friends](https://purplenerd.com/blog/tag/help-from-my-friends) [Dabbling Dev](https://purplenerd.com/blog/tag/dabbling-dev) [@michaelforce](https://purplenerd.com/blog/tag/michaelforce) [learning Salesforce](https://purplenerd.com/blog/tag/learning-salesforce)

![Becka](https://purplenerd.com/hubfs/Imported_Blog_Media/cert.jpg?noresize) [Becka](https://purplenerd.com/blog/author/sfdcnerd)

I talk a lot about the 'auto-magic' in salesforce.com, but we all know it has it's limitations. One of the things that I always wished could be done with [button-clicking](http://http://buttonclickadmin.com/) was to create a new record when conditions on another record were met (ya know, using some workflow powers). I really just considered myself out of luck.

That is until I started dabbling in the developer world. And while I consider myself knowing just enough to causing catastrophic damage, [a business case](http://forcebehindtheforce.com/2011/04/08/blow-your-mind/) presented itself in which trying out my new skills was the perfect fit. In short, the team wanted a record auto-created every time a specific type of event was created.

Here it is, my debut into triggers (excluding my copy-edit-paste of [one from MichaelForce](http://www.michaelforce.org/recipeView?id=a0G30000006aQgCEAU)):

```
trigger createPDtask on Event (after insert) {     
List<Support_Request__c> sr = new List<Support_Request__c>();
    for (Event newEvent: Trigger.New)
         if (newEvent.Type__c == '1. Meeting - Initial'){
                 sr.add (new Support_Request__c(
                     Name = 'New PD',
                     Task_Type__c = 'PD',
                     SFDC_Record_ID__c = newEvent.Id,
                     Rep__c = newEvent.OwnerId,
                     Event_Date__c = newEvent.ActivityDate));   
         }
   insert sr;
 }
```

So there it is. Short & fairly simple, but a HUGE productivity win. Plus, now everyone thinks I'm magic! And if you want a deeper dive explanation on the anatomy of this trigger, read [my post](http://teachmesalesforce.wordpress.com/2011/05/16/trigger-to-create-a-new-record/) on the Teach Me Salesforce blog!

UPDATED!! Here is my test class (Huge thanks to [Kyle](http://www.twitter.com/knthornt) for help with the System.assertEquals bit:

```
@isTest private class createPDtask_Test { 
   private static testmethod void testTriggerForEvent(){         
 Event e = new Event();   
               
 //Required Fields         
 e.Subject = 'testSubject';         
 e.IM_Type__c = '1. Meeting - Initial';         
 e.Product_Interest__c = 'None';         
 e.StartDateTime = DateTime.NOW();         
 e.EndDateTime = DateTime.NOW()+1;                  
 
 //Insert the Record         
 insert e;                  
 
 //Query for Inserted SR         
 List<Support_Request__c> testRequests = [SELECT id FROM Support_Request__c             
 WHERE SFDC_Record_ID__c = :e.Id];                      
 
 //We expect one record to be created         
 System.assertEquals (1, testRequests.size());        
 } 
}
```

## Recent Blog Posts

[![Recent Blog](https://purplenerd.com/hubfs/Imported_Blog_Media/oct6-user-group.jpg)](https://purplenerd.com/blog/im-finally-going-to-unbound)

[Events](https://purplenerd.com/blog/tag/events) [Hubspot](https://purplenerd.com/blog/tag/hubspot) [IRL](https://purplenerd.com/blog/tag/irl)

#### [Ten Years In and I'm Finally Going to UNBOUND!](https://purplenerd.com/blog/im-finally-going-to-unbound)

Every September my LinkedIn feed fills up with show floor ...

## Recent Blog Posts

[![Recent Blog](https://purplenerd.com/hubfs/Hand%20writing%20with%20a%20black%20mark%20on%20a%20transparent%20board%20-%20Smiley.jpeg)](https://purplenerd.com/blog/7-ways-revops-consulting-improves-customer-journeys)

[Rev Ops](https://purplenerd.com/blog/tag/rev-ops) [Listicle](https://purplenerd.com/blog/tag/listicle)

#### [7 Ways RevOps Consulting Improves Customer Journeys](https://purplenerd.com/blog/7-ways-revops-consulting-improves-customer-journeys)

When sales, marketing, and customer success aren't rowing ...

## Recent Blog Posts

[![Recent Blog](https://purplenerd.com/hubfs/Beautiful%20young%20lady%20thinking%20with%20question%20marks%20overhead-1.jpeg)](https://purplenerd.com/blog/10-questions-before-hiring-a-revops-consultant)

[Rev Ops](https://purplenerd.com/blog/tag/rev-ops) [Consultant](https://purplenerd.com/blog/tag/consultant)

#### [10 Questions Before Hiring a RevOps Consultant](https://purplenerd.com/blog/10-questions-before-hiring-a-revops-consultant)

The revenue operations consulting market has exploded, but ...

- <https://www.linkedin.com/company/purple-insights/>
- <http://www.twitter.com/sfdc_nerd>
- <http://www.instagram.com/sfdc_nerd>

© 2026 by Purple Insights Inc

[info@purplenerd.com](mailto:info@purplenerd.com)

```json
{
  "@context" : "https://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Becka",
    "url" : "https://purplenerd.com/blog/author/sfdcnerd"
  },
  "dateModified" : "2025-04-17T14:16:44.898Z",
  "datePublished" : "2011-05-13T14:00:32.000Z",
  "headline" : "Trigger Happy!",
  "mainEntityOfPage" : {
    "@id" : "https://purplenerd.com/blog/2011/05/13/trigger-happy",
    "@type" : "WebPage"
  },
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "url" : "https://purplenerd.com/hubfs/logo-transparent-svg-1.svg"
    },
    "name" : "Purple Insights"
  }
}
```