Ever felt you needed a decoder ring to understand developer documentation? Are you an admin wanting to understand what ?those Apex coders? are talking about? Want to move from Awesome Admin to Admin who Codes (but need a translator)? You?re in the right place! Join us on a beginner?s guided tour to Apex for Awesome Admins, where we will translate coding concepts into plain English for non-developers and provide real-time demonstrations. Together we?ll explore the wild and wonderful world of Force.com programming, including: the Cavern of Classes, the Ocean of Objects, Method Mountain, the Valley of Variables, the Sea of SOQL, and Trigger Territory. By the end of this session, you?ll understand the basic building blocks of Apex and when (and why) they are used to extend the Salesforce platform.
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
The Force.com Coding Tour (Decoding Coding for Awesome Admins)
1. The Force.com Coding Tour
Kieren Jameson
Digital Solutions Manager (ETR)
Salesforce MVP
@KierenJameson
WomenCodeHeroes.com
Decoding Coding for Awesome Admins
Angela Mahoney
Cat Herder (iCloudSalesforce)
Salesforce MVP
@icloudsf
icloudsalesforce.com
2. Safe harbor statement under the Private Securities Litigation Reform Act of 1995:
This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties materialize
or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results expressed or implied by the
forward-looking statements we make. All statements other than statements of historical fact could be deemed forward-looking, including any
projections of product or service availability, subscriber growth, earnings, revenues, or other financial items and any statements regarding
strategies or plans of management for future operations, statements of belief, any statements concerning new, planned, or upgraded services or
technology developments and customer contracts or use of our services.
The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new functionality for
our service, new products and services, our new business model, our past operating losses, possible fluctuations in our operating results and rate
of growth, interruptions or delays in our Web hosting, breach of our security measures, the outcome of any litigation, risks associated with
completed and any possible mergers and acquisitions, the immature market in which we operate, our relatively limited operating history, our ability
to expand, retain, and motivate our employees and manage our growth, new releases of our service and successful customer deployment, our
limited history reselling non-salesforce.com products, and utilization and selling to larger enterprise customers. Further information on potential
factors that could affect the financial results of salesforce.com, inc. is included in our annual report on Form 10-K for the most recent fiscal year
and in our quarterly report on Form 10-Q for the most recent fiscal quarter. These documents and others containing important disclosures are
available on the SEC Filings section of the Investor Information section of our Web site.
Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently available and
may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are
currently available. Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.
Safe Harbor
3. Kieren Jameson Angela Mahoney
@kierenjameson
WomenCodeHeroes.com
RAD Women Co-Founder
ETR Digital Solutions Manager
@icloudsf
icloudsalesforce.com
forcelandia.com
Portland Developers Group
Portland Girly Geeks Group
RAD Women Co-Founder
FORCE.COM
DEVELOPER
SALESFORCE
ADMINISTRATOR
ADVANCED
ADMINISTRATOR
SALESCLOUD
CONSULTANT
FORCE.COM
DEVELOPER
4. You'll understand why you should know what is
going on with code, even if you don't want to
write code yourself.
You'll understand what your options are for
process automation: clicks vs code.
You'll begin to understand the seven basic
building blocks of force.com coding.
You'll see some code in action!
You'll get further resources to learn code.
What will you walk away with today?
5. Because there are
some things you
can’t do with clicks.
If you work with
developers, it’s
helpful to know what
they are talking
about.
Because we’re
admins–there's
nothing we can’t do!
But why is code so hard?
Because developer documentation is very
“developer-y” and is sometimes (often!)
hard to understand for non-coders.
Because the first (and trickiest)
part of learning about code
is understanding what the
heck the building blocks
are and hew they related
to what you already know.
Why should you care about code?
Photo Source:
http://bit.ly/1UPStiM
6. CLICKS (Declarative)
Formula Fields
Validation Rules
Workflow Rules
Visual Workflow
Approval Processes
Lightning Process Builder
CODE (Programmatic)
Apex Classes & Apex Triggers
If you want to create/update records are not related to the
object that you are working with.
Run processes that need a particular order of operation
(workflows are triggered randomly).
When you want to create complex business logic that doesn’t
require user intervention, including if you have a bunch of
workflow rules that run on a single object.
When to “Click” and when to “Code”?
If you can do it with clicks then generally you should.
7. 1. If you wanted to add a follow-up Task every time a new “hot” Account was
created and assign it to the owner of the Account?
Quick Quiz! – Clicks or Code?
8. 1. If you wanted to add a follow-up Task every time a new “hot” Account was
created and assign it to the owner of the Account?
CLICKS!
Quick Quiz! – Clicks or Code?
9. 1. If you wanted to add a follow-up Task every time a new “hot” Account was
created and assign it to the owner of the Account? CLICKS!
2. If you wanted to add a follow-up Task every time a new “hot” Account was
created and assign it to your top Sales Person from the previous FQ?
Quick Quiz! – Clicks or Code?
10. 1. If you wanted to add a follow-up Task every time a new “hot” Account was
created and assign it to the owner of the Account? CLICKS!
2. If you wanted to add a follow-up Task every time a new “hot” Account was
created and assign it to your top Sales Person from the previous FQ?
CODE!
Quick Quiz! – Clicks or Code?
11. Basic Apex Building Blocks
Classes: the "Archetypes"
Objects: the "Individuals"
Methods: the "Doers"
Variables: the "Collectors"
Getting Data In & Out of Salesforce
DML: the "Courier"
SOQL: the "Researcher"
Putting it all together
Triggers: the "Listeners"
What are we decoding today?
Force.com Code Tour Itinerary
12. Classes are blueprints or templates for
the “stuff” that we’re working with.
Classes are like Objects in Salesforce
They know stuff about themselves
(these are their variables)
They can do things (these are their
methods)
Variables
First Name, Last Name,
Birthday, Age, Record
ID, Favorite Pastime,
is Tacky?, Annoyance
Rating…
Classes – the “Architypes”
Methods
Eat, Drink, Snorkel,
Ride Horses, Sightsee,
Take Photos, Complain,
Talk Loudly, Tip Poorly,
Be Annoying …
13. Apex objects are like Salesforce records.
Objects are what we create from classes.
If a class is a template for an tourist, then
an object is an actual, individual person.
Objects – The “Individuals”
The Tourista Family!
Instances of the
Tourist Class
(aka Objects)
These are
objects
Photo Credit: http://bit.ly/1JnkRXD
Tessa Tourista
14. Force.com/Apex Salesforce Examples
Basic Apex
Building Blocks
Class The Architype Salesforce Contact Object
Object The Individual Individual Contact Record
*These are loose translations
Your Force.com Decoder Ring
15. Variables are like luggage…they are reusable
containers to hold things (data)
They come in different shapes and sizes to
store different types of things: small, large, and
specialty shapes (e.g., hats, golf clubs)
They have a data type, a name, and a value.
Variables – The “Collectors”
The type of Luggage
(e.g., small case)
(data type)
mySuitcase
(variable name)
what
mySuitcase
contains
(value)
String mySuitcase = 'Full of Stuff';
data type name value
16. Force.com/Apex
Data Types
Salesforce Field Type
String Text, Text Areas, Auto Number, Url, Phone, Email
Integer or Decimal Number, Percent, Currency
Boolean Checkbox
ID ID of a Salesforce Record
Date, DateTime Date, DateTime
Your Force.com Field/Data Type Decoder Ring
17. String firstName = 'Tessa';
String lastName = 'Tourista';
Integer numTours = 0;
Decimal height = 5.4;
Date birthdate = '1983-02-01';
Boolean isTacky = TRUE;
String tipLevel = 'Generous';
ID id = '00300000003S5PGBC0';
Tessa Tourista’s Variables
typeOfVariable myContainer = contentsOfContainer;
data type name value
Photo Credit: http://bit.ly/1JnkRXD
Tessa
Tourista
18. Methods are the things
that objects and classes
can do.
They have a name and can
be passed arguments
(values) that can be used
inside the method.
Methods – The “Doers” Snorkeling
Building
sand
castles
Sunbathing
Photo source: http://i.huffpost.com/gen/2062638/images/o-TACKY-
TOURIST-facebook.jpg
19. What to wear snorkeling!
+ OR
We have our fins,
snorkel, and mask.
But how do we decide
what else to wear?
23. Full wetsuit
Under 66◦F
What to wear snorkeling!
Shorty wetsuit
66-72◦F
Bathing
Suit Time!
Not true
Not true
75◦F
24. Demo Time: Code in ACTION!!
Photo Source: https://www.flickr.com/photos/raneko/5198682308
25. Force.com/Apex Salesforce Examples
Basic Apex
Building Blocks
Class The Architype Salesforce Contact Object
Object The Individual Individual Contact Record
Variable The Collector Contact Field
Method The Do-er Workflow Action*
*These are loose translations
Your Force.com Decoder Ring
26. DML – The “Courier” SOQL– The “Researcher”
Database Manipulation Language
DML pushes record changes to Salesforce
DML
Salesforce Object Query Language
SOQL pulls records from Salesforce
SOQL
27. DML – The “Courier”
DML is used to send
data to Salesforce
Insert
Update
Upsert
Delete
Undelete
DML
DATA PACKAGE
DML
28. SOQL – The “Researcher”
SOQL is used to pull data from Salesforce
It can do a LOT, but at minimum, SOQL
has 3 basic pieces:
SELECT – what fields are you want to see
FROM – the Salesforce object that contains
these fields
WHERE – any filters on the data
SOQL
29. Demo Time: Code in ACTION!!Photo Source: http://hdwallpapersbase.com/wp-content/uploads/2013/01/Husky-Puppy-Wallpaper1.jpg
30. Force.com/Apex Salesforce Examples
Basic Apex
Building Blocks
Class The Architype Salesforce Contact Object
Object The Individual Individual Contact Record
Variable The Collector Contact Field
Method The Do-er Workflow Action*
Get Data In &
Out of Salesforce
DML The Courier Save Button*
SOQL Query The Researcher Tabular Report*
*These are loose translations
Your Force.com Decoder Ring
31. Photo credit: Melvin Gaal (Mindsharing.eu) / Foter.com
Triggers kick off code-based
automated processes.
They listen for certain database
events (e.g., a record being
inserted, updated, etc.).
They either link to or contain the
code that makes the magic
happen.
This lets us do things like…
Compare data before & after
a change is made.
Create new, and update
existing, related records.
Interact with external data
and web services
(e.g., external databases &
SMS text message services)
Triggers– the “Listeners”
32. Trigger Example (avoid double booking)
We have tours and we have tourists.
Tourists can only be on one tour at a time.
Need something to double-check that we're
not double booking tourists.
Step 1: Try to add a tourist Contact
to a tour.
Step 2: Find out what other tours this
contact is already booked on.
Step 3: Compare the start date of the
tours that the person is already on with
the start date of the tour we want to add
them to.
Step 4: If the tour you want to add
them to conflicts with the dates of their
existing tours, then give an error
message and don't let us book the tour.
????
33. What does this look like in code?
???
//1. When we try and add or update a tourparticipants__c
record, then before you commit the data to the database
run this trigger.
trigger RejectTourDoubleBooking on TourParticipants__c
(before insert, before update) {
//2. Create a list of all the records (called TPs for "Tour
Participants") that we sent to the trigger. Then loop over
all these records, and for each one run some code.
for (TourParticipants__c TPs : trigger.new) {
//3. For each item in the TP list, create another list (called
tour) that gets the ID and the start date of the tour we
are wanting to add the contact to.
Tour__c tour =
[SELECT id, startDate__c FROM Tour__c
WHERE id = :TPs.tour__c];
//4. Create another list of TourParticipant__c records
(called conflicts). Put in this list any records from the
TourParticipants__c custom object where the same
person we're wanting to add to a tour is already on a
tour with the same start date as the tour we are
wanting to add them to.
list <TourParticipants__c> conflicts =
[SELECT id FROM TourParticipants__c
WHERE contact__c = :TPs.contact__c AND
tour__r.startDate__c = :tour.startDate__c];
//5. If the "conflicts" list is NOT (!) empty, then block the
contact from being added to the tour.
if (! conflicts.isEmpty() ) {
TPs.addError('***DOUBLE BOOKING ERROR***');
}
}
}
WARNING: WE KNOW THIS CODE IS FLAWED
34. What does this look like in code?
???
trigger RejectTourDoubleBooking on TourParticipants__c
(before insert, before update) {
for (TourParticipants__c TPs : trigger.new) {
Tour__c tour =
[SELECT id, startDate__c FROM Tour__c
WHERE id = :TPs.tour__c];
list <TourParticipants__c> conflicts =
[SELECT id FROM TourParticipants__c
WHERE contact__c = :TPs.contact__c AND
tour__r.startDate__c = :tour.startDate__c];
if (! conflicts.isEmpty() ) {
TPs.addError('***DOUBLE BOOKING ERROR***');
}
}
}
WARNING: WE KNOW THIS CODE IS FLAWED
35. Demo Time: Code in ACTION!!Photo Source: https://upload.wikimedia.org/wikipedia/commons/f/ff/Cat_on_laptop_-_Just_Browsing.jpg
36. Force.com/Apex Salesforce Examples
Basic Apex
Building Blocks
Class The Architype Salesforce Account Object
Object The Individual Individual Account Record
Variable The Collector Account Field
Method The Do-er Workflow Action*
Get Data In &
Out of Salesforce
DML The Courier Save Button*
SOQL Query The Researcher Tabular Report*
Putting it All
Together
Triggers The Listener Workflow Rule Criteria*
*These are loose translations
Your Force.com Decoder Ring
37. More Admins who Code at Dreamforce
Sessions for Beginning Coders
Intro to Apex for Admins
Intro to Apex Triggers*
From "Awesome Admin" to "Champion
Coder" (How to become a force.com
developer)
Triggers for Admins: A Five-step
Framework for Creating Triggers
Workflow Formulas as a Gateway to
Coding
The Dev Zone &
Developer Library
(Moscone West)
Hands-on Trainings
Getting Started with
Apex Code for Admins
Getting Started with
Visualforce for Admins
* Already happened but may have been recorded
38. Want to know more?
Salesforce Trailhead
Free online training and tutorials (clicks & code)
bit.ly/sfdc-trailhead
Force.com Video Training
Udacity, Pluralsight
bit.ly/apex-video-training
RAD Women
Learn to code on force.com with other women
bit.ly/rad-women
Women Code Heroes
Helping awesome admins learn to code.
Decoder ring included
WomenCodeHeroes.com
sfdc99.com
Apex coding for the 99%
sfdc99.com
Salesforce Dev Community
Tip sheets, workbooks, cookbooks,
documentation…
developer.salesforce.com
39. Keep the learning going in the Admin Lodge
Admin Theater
55+ Sessions by Admins for Admins!
Visit Customer-Led Demos Learn more with Trailhead!
Earn your Apex Basics & Database
badge
40. Share Your Feedback and Win a GoPro
Enroll in a session1 Tap the bell to take a
survey
2 3
Earn a GoPro prize entry
for each completed
survey
ANGELA
Please make purchasing purchase decisions based upon features that are currently available.
Kieren then angela (I'd rather introduce myself(
So now that you know about us, what about you?
KIEREN
Shout out AWESOME ADMIN if you are a salesforce admin
Shout out ADMIN WHO CODES if you are an admin who does even a little bit of code
ANGELA
Shout out CODER if you are a salesforce developer
If you're none of these, then shout out "I DON'T KNOW WHAT I'M HERE FOR BUT I HEARD THEY WERE GIVING AWAY A FREE TRIP TO HAWAII"
So wrong!
*** (angela) so what do we have in store for you today…
KIEREN
Both Angela and I love traveling, so the first thing you'll see is a lot of travel related stuff.
We have built this session around the Forcelandia Terriffic Tour Company. So with that in mind what will you see on todays day trip?
We’ll look at why you might want to learn code
When you should click and when you should code
We'll go over the seven basic building blocks of force.com coding including see those blocks in action
OUT CUE>>>Lastly we'll give you further resources to learn to code
ANGELA
*** not a lot of information about there…hence this session.
OUT CUE >>> So let's start with the most basic question…
KIEREN
…and that is… when click and when code.
First off, if you can click, you probably should.
There are a ton of declarative options for Salesforce development from formula fields and workflow rules to the new lightning process builder.
There are, however some times when it's helpful to code. For example, if you are running very complex code that is updating or creating records and you want to control the order that your automation is run in. then it's proably a good time to code. There are also times when you don't want to deal with security roles and sharing rules, these are also great times to code. We'll see that code can also summarize data in ways that clicks can't.
*** So time for our clicks vs code pop quiz . We have two scenarios, and we'll ask you to choose whether you should click or code.
ANGELA
SHOUT OUT – who thinks you would click? Who think you would code?
OUT CUE >>>
ANGELA
OUT CUE >>> You could easily do this with a workflow rule
KIEREN
Scenario #2 – If you wanted to do the same task, but assign it to the top sales person from the previous fiscal quarter…will you click or code?
SHOUT OUT – hoot and holler for clicks? Hoot and holler for code?
KIEREN
That's right…you would need to use code, because that's the only way you can automate assigning it to the top sales person.
Great! It looks like you all have a basic understanding of when to click and when to code, so it's
OUT CUE >>> time to embark on our force.com tour . So let's put on our sun hats and leis and start the tour!
KIEREN
As we prepare our journey, it’s a good idea to understand our itinerary. Any time you are visiting another country, there is the possibility you need to learn some key phrases in another language. You can think of Force.com coding as another language; and we'll show you seven of them today.
We will relate them all to something that will hopefully make them easier to understand and remember.
There are for basic building blocks : classes, objects, methods, and variables
There are two ways to transport data: DML and SOQL
<<OUT CUE>>>And pulling it all together, we have triggers. Let's check out each of these in turn.
KIEREN
We'll first start with is the place were most of the work happens in apex. The apex class. We call this the Architype, because Classes act like a blueprint or template for the stuff that we will be creating. If I were to equate this to what you know about Salesforce as admins, it would be close to say that Apex Classes are like Salesforce Objects.
We will go into this in more depth, but classes know things about themselves (they have variables) and can do things (they have methods). Let me demonstrate what I mean.
I'd like you to close your eyes for me…yep…that means you!
Picture in your mind a typical tourist. Think about what they are wearing, and what kind of person they are. What is their age, what are the favorite activities, are they annoying and loud? Are they a tacky tourist? These are the variables or what the class knows about itself
Now picture what your typical or archetypal tourist can do…can it eat and drink, can it sightsee, or go snorkeling… these are our tourist class methods, or things that our tourist class can do.
Great…open your eyes again but keep that archetypal tourist class in your mind
<OUT CUE>>> so now we have what the classes are all about…let's look how this relates to Apex objects.
ANGELA – they are our actual tourists.
<OUT CUE>>> let's whip out our decoder ring.
KIEREN
So we have now described both classes our architypes and objects our individuals,
<OUT CUE>>> so let's move on to our next building block
KIEREN –
We call Variables the Collectors, because they're kind of like luggage, they are containers that collect and hold things, like data.
And just like luggage, there are different types of variables that hold different types of data. With luggage, you may have large bags and small bags, and toiletry bags, and hat bags and even bags to hold your golf clubs! In Apex, you have variables that can store, for example, text values, numbers, and dates.
You can think of variables as similar to fields in salesforce. And like fields, they have a name, a type and a value.
Just like there are fields in salesforce to hold text, in Apex we call these String variables.
So looking at the example on the screen, we have a string variable, that is called mySuitcase, and it has a value of “Full of Stuff”
<<OUT CUE>>> let's open our phrase book again and see how we can translate Force.com variables into Salesforce fields.
KIEREN
This is where we're doing the same thing, but using different words.
*** so lets look at some specific variables related to one our Tourist objects…tessa tourista.
ANGELA –
<OUT CUE >>> now we can describe her…let's look at what she can do.
ANGELA
Methods, as I’ve said are the bits of objects are the Doers of the coding world. They like to take action.
They also have a name and you can pass them data.
An example of a method in Salesforce, might be the search. It does something...it take the data that you pass it, and searches all your salesforce records for it.
The bit of data that you send it is called an argument (fancy name for a value). And the method uses it and then, in many cases sends something back. In our search example, it sends back search results.
Thinking back to our tourist example, the various methods that tourists might do would be to sun bathe, to build sand castles and to snorkel.
Kieren – shopping or drink mai tai …
*** no….
ANGLEA – coding is fun, it's problem solvers. we're just showing you different ways to solve problems. As we dive into the code.
But there is the perennial problem of what to wear? If I'm the object Tessa, I know that I have fins and snorkel and mask, but I need to know whether I'll be ok in my bathing suit, or if I should put in my super shorty?
<OUT CUE >>> So let's see some code that will help us decide!
KIEREN
What you're looking at now is real live code! We will be going through this in detail, so keep calm, but in broad strokes, the first part (in blue) is where we are using (or calling) the snorkel method
The second part (in gold) is the actual method with everything it is programmed to do.
*** <<OUT CUE>> let's step though this bit by bit
KIEREN
You can see that in the top part, we call the snorkel method and we pass it the water temperature (75 degrees Farenheit).
Look at the matching pieces below.
Ignore the public void bit, but you can see that we are naming the method and then setting up an integer (or number) variable called waterTemp.
<<OUT CUE>>> Next let's look at the functioning of this method
KIEREN
Who here has created a formula field in Salesforce?
And who has use a conditional IF statement?
Well this next piece of code is like that. We are saying, if the water temp is under 65 – bloody cold, then Tessa would need to put on a full wetsuit.
If that test fails (the temperature is 65 or more degrees) , then we go on to the next one, if the temperature is less than 73 degrees, then Tessa should put on a shorty wetsuit.
If that test fails (because the temp is 73 or more degrees), then Tessa just needs a bathing suit .
So another pop quiz…Look at the temperature that we're passing in to the snorkel variable (it's boxed in red).
From this… who thinks that Tessa should put on a full wet suite?
Ok…and who thinks she should put on a shorty wetsuit
And lastly, who think's she fine in her super sporty swim suit?
<<<OUT CUE>>> Let's find out who's right!
KIEREN
Congrats to most of you who picked right…if the water temperature of 75 degrees, then the first two tests fail, which leaves Tessa wearing a bathing suit!
KIEREN
But let's see this code in action.
//Call the snorkel method and
//pass it the water temperature
snorkel(75);
//Code for the snorkel method,
//which takes an integer variable
Public void snorkel(Integer waterTemp){
//Put on different snorkeling equipment
//based on water temperature
IF (waterTemp < 65) {
System.debug('=== It is bloody cold!');
System.debug('=== Tourists should put on a full wetsuit');
//code for putting on full wetsuit
} ELSE IF (waterTemp < 73){
System.debug('=== It is a bit chilled out there.');
System.debug('=== Tourists should wear their shorty wetsuit!');
//code for putting on shorty wetsuit
} ELSE {
System.debug('=== Woo hooo! It water is so lovely!');
System.debug('=== Tourists should only wear swim suits!');
//code for putting on bathing suit
} //end if
} //end snorkel method
ANGELA
Let's recap what we know.
We have gone through all four basic building blocks of apex – Classes, objects, variables and methods.
<OUT CUE>>> next let's look at how we get data in and out of salesforce.
ANGLEA
So enough about Objects and classes and such. Let's talk about two other great Force.com Coding concepts for working with data.
DML and SOQL
These are the coding tools we use to get data in and out of salesforce.
I call DML the courier because we package up data and it delivers it to our Salesforce database
SOQL is the researcher, because with it we write queries that pull data back from the salesforce database.
<<<OUT CUE>>> let's look at them individually.
ANGELA
There are various actions you can take in a DML statement…
Creating a contact object and setting all the variables and values
<OUT CUE>>> Then the bit at the bottom is the actual DML. It's small but it's mighty!
KIEREN
We call SOQL the researcher, because we ask it questions and it sends us back results.
There are three basic pieces to a SOQL query, SELECT, FROM and WHERE.
Let's look at the example to the right. If I were to say this in plain English, it would say
Go find me the name, id and tiplevel fields from the contact salesforce object where the tiplevel is generous.
<OUT CUE>>> Now we know who to give extra attention to in our tour
KIEREN –
Run query
Add tessa
Run query again
KIEREN
To recap, we have the four basic building blocks of apex, classes, objects, variables and methods, and we have introduced the two ways to transport data to and from salesforce.
<<<OUT CUE>>> so what's left?
KIEREN
The last concept we'll talk about today is the Trigger.
We call the trigger the listener, because that is what it does…it's whole job is listening for things to happen in the database and then triggering code to happen.
The stuff that they're listening for are any time a record is added, updated, deleted, or undeleted from the Salesforce database.
They are cool because they can also compare data before and after a change happens, which is great for data validation.
They can also create new records and update existing ones. They can also interact with things outside of salesforce, like text message services.
*** let's look at a real life example.
ANGLEA
*** lets put together some comments
ANGELA –
First let's look at how we would talk about writing this in code.
Everything in brown is a comment – this is code that just says what we are wanting to do. It helps us understand what we're looking at (especially later when we forget!).
Note that this is for demonstration purposes…there are problems with this code and it breaks quite a few best practices, but it's short and that's good enough for today!
*** now let's pull out our phrase book and translate this into force.com Apex code.
ANGELA – now we add the actual code.
Everything in blue is a variable name
Everything in teal is SOQL
Everything in purple are special keywords that do stuff (like create the trigger, or loop over a list of records, or perform and if statement).
ANGELA – show code in dev console.
Go into tours > Kenyan tour
Add tessa – no problem
Add tony – problem
Make joke.
KIEREN
Wow…sad to say, but we're almost at the end of our fabulous Force.com Coding Tour. If you liked the show, then please feel free to tip your tour guides. We particularly like fruity coctails with umbrellas.
If you liked this tour, and you're ready for the next step, we have some side trips you may be interested in.
***so here are some great resources to keep the coding bus rolling
ANGELA
*** and for when you get home…
KIEREN (left ) ANGELA (right)
Trailhead is an amazing and amazingly free resource with all sorts of online learing related to both the clicks and code sides of Salesforce.
You can also access some free Force.com Video training at the url provided there.
If you're an advanced admin and would like to take a step to the coding side, then check out Rad women
ANGLEA
Here are some amazing free resources to keep you coding.
<<<OUT CUE>>> salesforce Dev community.
As part of the Admin Track at Dreamforce we want the learning to continue about this subject past this presentation. You can visit the Admin Zone to see customer led demoes and specifically look for the Coding for Admins station. And go to Trailhead to learn more and earn your Apex Basics and Database badges.