Git Product home page Git Product logo

apex-hello-world's Introduction

apex-hello-world

Create your first hello world project in Apex/Salesforce code.

global class HelloWorld {
  public String hello() {
    return 'Hello World!';
  }
}
@isTest
private class HelloWorldTest {
  @isTest static void hello() {
    HelloWorld hello_world = new HelloWorld();
    String result = hello_world.hello();

    system.assertEquals(result, 'Hello World!');
  }
}

Tutorial

Setup Salesforce.com

Create a salesforce.com developer account.

You'll receive an email from Salesforce with a link to confirm. Click it.

On the next screen, set your password. Yeah, it's an odd flow, but it's salesforce so what do you expect.

You now have a developer account.

Generate your security token. We will need this later. While logged into your developer account, click "Your Name > My Settings" at the top right portion of your developer account dashboard.

Then on the left side of the screen click "Personal > Reset My Security Token". Click the "Reset Security Token" button. Salesforce emails you a security token. You will need this later.

Setup local environment

Install Sublime Text 3.

Install Mavens Mate.

Open up Sublime Text 3, and then open up Mavens Mate on your machine. There should be a Mavens Mate icon, at the top bar of your screen. Click it and then click "Plugins".

On the next window, click "Install Plugin". This installs the Mavens Mate plugin into Sublime Text 3.

Close and reopen Sublime Text 3.

Click Mavens Mate > Settings > User at the top Sublime Text 3 Toolbar.

This will open a file called mavensmate.sublime-settings. Paste the following in that file. Adjust to the path and directory you want to store your salesforce code in.

{
  "mm_workspace": "/Users/scottmotte/code/salesforce"
}

Save and close that file.

Create a project

With Sublime Text 3 still open, click Mavens Mate > Project > New Project.

On the next screen enter the following:

  • For project name: name it something you'd like
  • For username: enter your email address
  • For password: enter your password APPENDED with your salesforce security token. (see above for how to generate the security token)
  • Click the Advanced tab and unselect everything except ApexClass and CustomObject.

When you're ready click the 'Create Project' button.

This will create the project up on Salesforce.com and locally on your machine. That's what we want. It's the way salesforce development works. Now when we develop locally it will sync things up remotely. Yeah, it's strange. I feel bad for Salesforce developers.

Create a class

With Sublime Text 3 still open, click "Mavens Mate > Metadata > New Apex Class". Then from the popup click "Default". Finally, name your class "HelloWorld".

Edit that file to look like the following.

global class HelloWorld {
  public String hello() {
    return 'Hello World!';
  }
}

Create a test class

Next, click "Mavens Mate > Metadata > New Apex Class". Then from the popup click "Unit Test". Finally, name this class "HelloWorldTest".

Edit that file to look like the following.

@isTest
private class HelloWorldTest {
  @isTest static void hello() {
    HelloWorld hello_world = new HelloWorld();
    String result = hello_world.hello();

    system.assertEquals(result, 'Hello World!');
  }
}

Let's run this test.

Click "Mavens Mate > Unit Testing > Open Apex Test Runner UI".

On the next screen, make sure the HelloWorldTest is selected and click the Run Tests button.

You're done

Congrats, you wrote your first Apex hello world code!

It was much more difficult than most languages, but we got through it. If you can avoid it, don't become a salesforce developer. Learn Go, Ruby or NodeJS. You will be even happier.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.