Top 1,000 Features Creators Events Podcasts Extensions Blog Explorer CSV Download

Apex

< >

Apex is a programming language created in 2007.

#660on PLDB 17Years Old 23kRepos

Apex is a proprietary programming language provided by the Force.com platform to developers similar to Java and C#. It is a strongly typed, object-oriented, case-insensitive programming language, following a dot-notation and curly-brackets syntax. Apex can be used to execute programmed functions during most processes on the Force.com platform including custom buttons and links, event handlers on record insertion, update, or deletion, via scheduling, or via the custom controllers of Visualforce pages. Due to the multitenant nature of the platform, the language has strictly imposed governor limitations[61] to guard against any code monopolizing shared resources. Salesforce provides a series of asynchronous processing methods for Apex to allow developers to produce longer running and more complex Apex code.


Example from hello-world:
global with sharing class HelloWorld { global static void main() { System.debug('Hello World'); } }
Example from Linguist:
public class GeoUtils { // generate a KML string given a page reference, call getContent() // then cleanup the output. public static string generateFromContent(PageReference pr) { string ret = ''; try { ret = (string) pr.getContent().toString(); ret = ret.replaceAll('"','\'' ); // get content produces quote chars \" ret = ret.replaceAll( '&','&amp;');// we need to escape these in the node value } catch (exception e ) { system.debug( 'ERROR '+e); } ret = ret.replaceAll('\n',' '); // must use ALL since many new line may get ret = ret.replaceAll('\r',' '); // get these also! // system.debug( ret); // dump the KML return ret ; } public static Map<String, String> geo_response = new Map<String, String>{'200'=>'G_GEO_SUCCESS', '400'=>'G_GEO_BAD_REQUEST', '500'=>'G_GEO_SERVER_ERROR', '601'=>'G_GEO_MISSING_ADDRESS', '602'=>'G_GEO_UNKNOWN_ADDRESS', '603'=>'G_GEO_UNAVAILABLE_ADDRESS', '604'=>'G_GEO_UNKNOWN_DIRECTIONS', '610'=>'G_GEO_BAD_KEY', '620'=>'G_GEO_TOO_MANY_QUERIES' }; public static string accountAddressString ( account acct ) { // form an address string given an account object string adr = acct.billingstreet + ',' + acct.billingcity + ',' + acct.billingstate; if ( acct.billingpostalcode != null ) adr += ',' + acct.billingpostalcode; if ( acct.billingcountry != null ) adr += ',' + acct.billingcountry; adr = adr.replaceAll('\"', '' ); adr = adr.replaceAll('\'', '' ); adr = adr.replaceAll( '\n', ' ' ); adr = adr.replaceAll( '\r', ' ' ); system.debug( adr ); return adr; } public static testmethod void t1() { PageReference pageRef = Page.kmlPreviewTemplate; Test.setCurrentPage(pageRef); system.assert ( GeoUtils.generateFromContent( pageRef ) != null ); Account a = new Account( name='foo', billingstreet='main', billingcity='springfield',billingstate='il', billingpostalcode='9',billingcountry='us'); insert a; system.assertEquals( 'main,springfield,il,9,us',accountAddressString( a) ); } }
abstract ABSTRACT Abstract activate ACTIVATE Activate and AND And any ANY Any array ARRAY Array as AS As asc ASC Asc assert ASSERT Assert autonomous AUTONOMOUS Autonomous begin BEGIN Begin bigdecimal BIGDECIMAL Bigdecimal blob BLOB Blob boolean BOOLEAN Boolean break BREAK Break bulk BULK Bulk by BY By case CASE Case cast CAST Cast catch CATCH Catch char CHAR Char class CLASS Class collect COLLECT Collect commit COMMIT Commit const CONST Const continue CONTINUE Continue convertcurrency CONVERTCURRENCY Convertcurrency decimal DECIMAL Decimal default DEFAULT Default delete DELETE Delete desc DESC Desc do DO Do double DOUBLE Double else ELSE Else end END End enum ENUM Enum exception EXCEPTION Exception exit EXIT Exit export EXPORT Export extends EXTENDS Extends false FALSE False final FINAL Final finally FINALLY Finally float FLOAT Float for FOR For from FROM From future FUTURE Future get GET Get global GLOBAL Global goto GOTO Goto group GROUP Group having HAVING Having hint HINT Hint if IF If implements IMPLEMENTS Implements import IMPORT Import in IN In inner INNER Inner insert INSERT Insert instanceof INSTANCEOF Instanceof int INT Int interface INTERFACE Interface into INTO Into join JOIN Join last_90_days LAST_90_DAYS Last_90_days last_month LAST_MONTH Last_month last_n_days LAST_N_DAYS Last_n_days last_week LAST_WEEK Last_week like LIKE Like limit LIMIT Limit list LIST List long LONG Long loop LOOP Loop map MAP Map merge MERGE Merge native NATIVE Native new NEW New next_90_days NEXT_90_DAYS Next_90_days next_month NEXT_MONTH Next_month next_n_days NEXT_N_DAYS Next_n_days next_week NEXT_WEEK Next_week not NOT Not null NULL Null nulls NULLS Nulls number NUMBER Number object OBJECT Object of OF Of on ON On or OR Or outer OUTER Outer override OVERRIDE Override package PACKAGE Package parallel PARALLEL Parallel pragma PRAGMA Pragma private PRIVATE Private protected PROTECTED Protected public PUBLIC Public retrieve RETRIEVE Retrieve return RETURN Return returning RETURNING Returning rollback ROLLBACK Rollback savepoint SAVEPOINT Savepoint search SEARCH Search select SELECT Select set SET Set short SHORT Short sort SORT Sort stat STAT Stat static STATIC Static strictfp STRICTFP Strictfp super SUPER Super switch SWITCH Switch synchronized SYNCHRONIZED Synchronized system SYSTEM System testmethod TESTMETHOD Testmethod then THEN Then this THIS This this_month THIS_MONTH This_month this_week THIS_WEEK This_week throw THROW Throw throws THROWS Throws today TODAY Today tolabel TOLABEL Tolabel tomorrow TOMORROW Tomorrow transaction TRANSACTION Transaction transient TRANSIENT Transient trigger TRIGGER Trigger true TRUE True try TRY Try type TYPE Type undelete UNDELETE Undelete update UPDATE Update upsert UPSERT Upsert using USING Using virtual VIRTUAL Virtual void VOID Void volatile VOLATILE Volatile webservice WEBSERVICE Webservice when WHEN When where WHERE Where while WHILE While yesterday YESTERDAY Yesterday

Language features

Feature Supported Example Token
Conditionals โœ“
Inheritance โœ“
Access Modifiers โœ“
Switch Statements โœ“
Exceptions โœ“
Constants โœ“
Classes โœ“
While Loops โœ“
Booleans โœ“ true false
MultiLine Comments โœ“
/* A comment
*/
/* */
Strings โœ“ '
Line Comments โœ“
// A comment
//
Comments โœ“
Semantic Indentation X

View source

- Build the next great programming language ยท About ยท Resources ยท Acknowledgements ยท Part of the World Wide Scroll