background preloader

Apex

Facebook Twitter

Web Services API Developer's Guide. Force.com Apex Code Developer's Guide. Force.com Apex Code Developer's Guide. App Logic. Navigation: Developer Force | App Logic Force.com (and Database.com) offers two unique approaches for implementing business logic for your apps: Point-and-click features for general app logic Apex Code for custom app logic Point-and-Click App Logic Most apps rely on standard business logic to help ensure the quality of data, improve usability, and automate processes.

App Logic

Force.com lets you implement a large percentage of your business logic using point-and-click declarative (no code) features such as: Apex Code Whenever possible, always use point-and-click features to implement app logic — it's easy to implement because no source code and unit tests are necessary, and consequently, everything is easier to maintain. An Introduction to Apex. Abstract Force.com Apex Code is a strongly-typed programming language that executes on the Force.com platform.

An Introduction to Apex

Apex is used to add business logic to applications, to write database triggers, and to program controllers in the user interface layer. It has a tight integration with the database and query language, good web services support, and includes features such as futures and governors for execution in a multi-tenant environment. This article introduces the Apex language. After providing an overview of the syntax, we look at its database support, followed by testing, web services, and dynamic apex. After reading this article you will have a good overview of the language and its use on the platform. Syntax Apex has a syntax that will be familiar to Java and C# programmers. Classes and Interfaces Here is a simple example of an interface and a class implementing the interface: You can create an instance of a class using the new keyword. PurchaseOrder po = new CustomPurchaseOrder(); Collections.

Apex Code Best Practices. Abstract Apex Code is the Force.com programming language used to write custom, robust business logic.

Apex Code Best Practices

As with any programming language, there are key coding principles and best practices that will help you write efficient, scalable code. This article illustrates many of the key best practices for writing and designing Apex Code solutions on the Force.com platform. Best Practice #1: Bulkify your Code Bulkifying Apex code refers to the concept of making sure the code properly handles more than one record at a time. Here is an example of poorly written code that only handles one record: The issue is that only one Account record is handled because the code explicitly accesses only the first record in the Trigger.new collection by using the syntax Trigger.new[0].

Here is a sample of how to handle all incoming records: Notice how this revised version of the code iterates across the entire Trigger.new collection with a for loop. Instead, move any database operations outside of for loops. Summary. From Java to Apex « Force 201 – Force.com Development. Firstly, use a modern browser such as Google Chrome for development work.

From Java to Apex « Force 201 – Force.com Development

Salesforce pages including the development oriented ones use a lot of JavaScript so you want that to run quickly. You can do initial work just working through the web “Setup” pages and the “Developer Console”. But you will most likely want to move to an IDE if you are writing anything but a trivial application so you can have all the files at your fingertips and track them in an external version control system. The most commonly recommended IDE is Mavensmate. There is also the Salesforce Force.com IDE and others. Here is the setup we use for version control and continuous integration: Development tools are poor compared to say Eclipse’s Java tooling so set your expectations accordingly.

Don’t expect to be able to “program at the speed of thought”. Apex is a small, closed language that has first-class built-in support for database operations but is more limited for general purpose programming. Like this: Examples for Apex Programming [ salesforce.com platform ] Write Your First Salesforce.com Apex Trigger – Overview. Salesforce.com has more automation features than any system I have ever seen. However, there are a few things that can’t be done without programming. A few examples are: Updating a master record with a value from a child record when the master record is a Standard Object. Cross-Object Workflow exists for Custom Objects, but not for Standard Objects.Workflow will not create records other than Task records.Getting around the formula compile size limit (Four Solutions to Salesforce.com “Too Big To Execute” Formula Error).

Apex Triggers can help with these and other scenarios. Salesforce’s documentation on Triggers is embedded in the overall Apex documentation, therefore, it sort of expects you to read everything and then pull out the parts you need. This blog entry attempts to put together an overview of the Trigger development process as a set of tips and related URL links. This might all sound very intimidating, but once you get through your first one, it actually is fairly simple.