Salesforce coding lessons for the 99%
Finally, Apex tutorials for point-and-click admins! Written by a self-taught Google engineer.
  • Beginner Tutorials
    • Apex
    • Certifications
    • Career Info
    • Technical Architect
    • Visualforce
    • Videos
  • Apex Academy
  • Success Stories
  • About Me
  • Misc
    • Mailbag
    • Challenges
    • Links
    • Login to my Org
Follow @dvdkliuor SUBSCRIBE!

Where to write code in Salesforce

May 13, 2013

Preface: this post is part of the Write Your First Trigger From Start to Finish series.

There are only two places you can write code in Salesforce:

  1. Sandbox – most people will want to code here! Sandboxes are developer-friendly copies of your normal org and they’re easy to create.
  2. Developer Edition – if you don’t have an instance of Salesforce to call home, you can practice here.

You can follow along in either version! If you want to eventually deploy into your normal “production” org though, you’ll want to use a sandbox.

To open up the trigger coding UI in either version, navigate here:

Setup >> Customize >> Users >> Triggers >> New

Note: every object in Salesforce has a “Triggers” section, even custom objects!

Next, copy over the code from our simple trigger example and… your code is now active! Go ahead and create a new user to test it out!

Don’t want to create your own environment? Log in to mine!

Username: learn@sfdc99.com
Password: Click here to reveal

Next post: Example: How to write a simple Apex trigger!

25 Comments
Namit Gundale
August 8, 2018 @ 2:45 am

i want to a time field on a object and that time field is automatically filled with current time of system. i do it by taking time datatype and some formula but its showing different time ..im also changing the timezone from the setting but its not taking system time
NOTE:we have to display only time in that field not date.

please help me,any one have solution then please ping me.
thank you!

Reply
Teena Olsen
May 7, 2018 @ 10:37 pm

Hi,
I have retrieved and deployed the below apex class (Opportunity_Test) but unable to see the apex class in my developer edition where the deployment status is success.

Opportunity_Test
ApexClass

How to find this Apex Class in my salesforce instance? Why i am not able to find this class?

Thanks in Advance.

Reply
Mahesh
February 1, 2016 @ 2:27 am

hi david…
its mahesh i want to learn salesforce pls insist me to get some resources

Reply
    David Liu
    February 1, 2016 @ 8:26 pm

    Tell me what resources you need that aren’t already on sfdc99 and I will try to find them!

    Reply
      Mahesh
      February 2, 2016 @ 8:57 pm

      Sir I want some of the basic codes and their descriptions …..

      Reply
Jai
February 5, 2015 @ 4:09 am

Hi David,

I am new to SFDC. I am failing Administrator WI15 exam on 1st trial, So please help me how to clear Administrator-WI15 exam in 2nd trial.

Reply
    David Liu
    February 5, 2015 @ 8:12 pm

    Haven’t passed that one yet myself!

    Reply
vammshi
December 3, 2014 @ 11:17 am

hi david,
i am new to salesforce while now i am practicing with developer edition ,can u show me path ,How to deploy triggers using sanbox to production??

and how can i find sanbox??

Reply
    David Liu
    December 4, 2014 @ 9:46 pm

    Go through these one by one =)
    https://www.sfdc99.com/beginner-tutorials/

    Reply
kumar
November 27, 2014 @ 9:40 am

I have Interview next so I have some Important question with Answer. I have Java background and new for SFDC.
Plz share Interview question.

Reply
    David Liu
    November 28, 2014 @ 9:42 pm

    I’ll have a post on this, I get this question a lot!

    But not soon unfortunately!

    Reply
Charan
October 29, 2014 @ 6:52 pm

Hi David,

I am new to SFDC.Taken the coaching outside.I am failing in the interviews.So please help me how to overcome this problem.

Reply
    David Liu
    October 29, 2014 @ 9:00 pm

    Interviews are all about preparation. Know everything about the company you’re interviewing for, and even the people who are interviewing you. I used to memorize every single person’s hobbies before going in to my first interviews!

    Nothing beats knowing the platform inside and out beforehand too!

    I’ll have a post up soon with interview tips!

    David

    Reply
      charan
      November 1, 2014 @ 8:34 pm

      I scheduled an interview in this week.So how to prepare and what to prepare..It’s a great a help gor me…

      Reply
        David Liu
        November 1, 2014 @ 11:24 pm

        This is a big topic with too many variables depending on the position and company!!

        My short advice: don’t pretend to know something if you don’t know it!

        Reply
Neenu Mathew
August 20, 2014 @ 2:55 am

Hi David,

What is the execution order of workflows and triggers?Which comes first??

Reply
    David Liu
    August 20, 2014 @ 10:40 pm

    Check this post out:
    https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_order_of_execution.htm

    Reply
      Neenu Mathew
      August 21, 2014 @ 2:37 am

      Thankyou David :)

      Reply
    Anonymous
    September 9, 2014 @ 12:03 am

    Trigger comes first then Workflow
    Just fyi , the flow is as mentioned below
    Validation Rule
    Triggers
    Assignment Rule
    Auto-response Rule
    Workflow rule
    Escalation Rule
    at last Roll-up summary fields

    Reply
Sayan
July 21, 2014 @ 9:17 pm

the login id and password is not working

Reply
    David Liu
    July 27, 2014 @ 10:03 pm

    Updated!

    Reply
Srinath Reddy
June 12, 2014 @ 3:05 am

Hi David,

I am not able to get 75% code coverage for my test class. Can you please help me get 75%-100% code coverage for my below test class.

@isTest(SeeAllData=true)
global class QuoteToUpdateTest1{
static String CRON_EXP = ‘0 0 0 15 3 ? 2022′;

public static testMethod void QuoteToUpdate_Test() {
System.debug ( LoggingLevel.ERROR ,’QuoteToUpdate_Test — Start’) ;
Test.startTest();
User user = [SELECT Id FROM User WHERE IsActive = true LIMIT 1];
System.debug ( LoggingLevel.ERROR ,’QuoteToUpdate_Test — before quoteUtilTest.quotes[0]’) ;
Quote__c testQuote= QuoteUtilTest.quotes[0];
System.debug ( LoggingLevel.ERROR ,’QuoteToUpdate_Test testQuote=’ + testQuote) ;

/* Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
req.setComments(‘Submitting request for approval.’);
req.setObjectId(testQuote.Id);
Approval.ProcessResult result = Approval.process(req);*/

// Schedule the test job
String jobId = System.schedule(‘ScheduleApexClassTest’,CRON_EXP, new QuoteForUpdate());

// Get the information from the CronTrigger API object
CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :jobId];

// Verify the expressions are the same
System.assertEquals(CRON_EXP , ct.CronExpression);

// Verify the job has not run
System.assertEquals(0, ct.TimesTriggered);

// Verify the next time the job will run
System.assertEquals(‘2022-03-15 00:00:00’,
String.valueOf(ct.NextFireTime));

Test.stopTest();

}
}

Reply
    David Liu
    June 12, 2014 @ 10:37 pm

    Srinath,

    Two things you need to do!
    1. Remove the SeeAllData=true annotation! Create your records from scratch!
    2. I need to see your trigger =)

    David

    Reply
Brian
December 18, 2013 @ 4:46 pm

Hi David,

I can’t create “new” from the triggers page, using your login listed.

Reply
    David Liu
    December 18, 2013 @ 6:53 pm

    Hey Brian =)

    You’ll actually need your own (free) environment to do so!
    https://events.developerforce.com/signup?d=70130000000EjHb

    I locked it down so I wouldn’t have to clean up a bunch of code =)
    David

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *


*

*

Theme: Simple Style by Fimply