Apex ApplicationCreate Web Service by integrating other systems Create email services for an email blast or Email Setup Perform Complex Validation over multiple objects at the same time and also custom validation implementation. Create complex business processes that are not supported by existing workflow functionality or Flows Create custom transactional logic Perform some Logic when a record is modified. Working Structure of Apex Flow of Action Developer Action End User Action Understanding the Apex SyntaxVariable Decalation SOQL Query Loop Statement Flow Control Statement DML Statement Apex
Apex is a strongly typed, object-oriented Programming language that allows developers to execute the flow and transaction control statements on the force.com platform server in conjunction with calls to the Froce.com API. Features of Apex as a language Integrated Java-like syntax and easy to use Strongly Integrated with Data Strongly Typed Multitenant Environent Upgrades Automatically |
More String ExamplesPliblic Boolean equalsIgnoreCase(String stringtocompate) String MyString1 = 'MySTRING'; String MyString2 = 'MyString'; Boolean result = myString2.equalsIgonoreCase(myString1); Sytem.debug(' your message :' +result); String Examplespublic Boolean equalsIgnoreCase(String stringtocompare) String myString1 = 'MySTRING'; String myString2 = 'MyString'; Boolean result = myString2.equalsIgnoreCase(myString1); System.debug('Value of equal will be true as they are same and result is : ' +result); Apex - StringString in Apex: is any set of character with no character limit. String companyName = 'ABC'; String Methods Syntax public Boolean contains(String substring) Example String myProductName1 = 'HCL' ; String myProductName2 = 'NAHCL' ; Boolean result = myProductName2.contains(myProductName1); System.debug('O/P will be true as it contains the string and Output is :' +result) ; Apex - VariablesDeclaring Variables String StrName = 'My String'; Integer myInterger = 1; Boolean mtBoolean = true; Apex Variables are case-Insensitive( you cannot declare a variable two times) Integer m = 100; For (Integer I = 0; I < 0; I++){ integer m = 1; Scope of Variables List<string> Products = new List<strings>(); Products.add(HCL); } Primitive Data TypesInterger Interger X = 1000; System.debug(' value of x Variables: ' +x); Boolean Boolean x; x = true; System.debug(' ' +x); Date Date x = date,today(); Long/String Long x = 2313212654654445643; Object Account x = new Account ( Name ='Test AC'); Understanding the Data TypesApex Supports the Followings data types Primitive(Integer, Double, Long, Date, Datetime, String, ID, or Boolean) Collections(Lists, Sets and Maps) sObject Enums Classes, Objects and Interfaces Apex - EnviromentApex Code Development Tools Force.com Developer Console Froce.com IDE Code Editor in the Salesforce use Interface |
Apex - ArraysSyntax <String> [ ] arrayOfProducts = new List<String>(); Ex: String [ ] arrayofproduts = new List <String>(); //Adding elements in arrays arrayOfProducts.add('HCL'); arrrayOfProducts.add('H2SO4'); For (Integer i=0; I<arrayOfProducts.size( ); i++){ System.debug('Value In Array :' +arrayOfProducts[ I ]);} Accessing array element by using index Apex - ConstantsConstants are variables which donot change their values Ex: public class CustomerOperationClass{ Static final Double regularCutomerDiscount = 0.1; Static Double finalPrice = 0; public static Double provideDiscount (Integer price){ // calculate the Discount finalPrice = price - price * rebularCustomerDiscount; return finalPrice; } } OUTPUT Double finalPrice = CustomerOperationClass.provideDiscount(100); System.debug('FinalPrice :' +finalPrice); Apex - Decision MakingDecision-making structures require that the programmer specify one or more conditions to be evaluated. Apex - LoopsLoop Type & Description For loop : This loop performs a set of statements for each item In a set of records. SOQL for Loop: Execute a sequence of statements directly over the returned set of SOQL query. Java-Like for Loop : Execute a sequence of statements in traditional Java-like syntax Conti...While loop: Repeats a statement or group of statements while a given condition is true. it tests the condition before executing the loop body. do...while loop Like a while statement, except that it tests the condition at the end of the loop body. |
Apex - CollectionsLists Ex: List<String> ListOfCities = new List<String>(); System.debug('Value of ListOfCities :' +ListOfCities); List <account> AccountToDelete = new List<account> (); System.debug('Value Of ListOfCities' +AccountToDelete); There is a limitation on heap size. Methods For Lists: size() add() get() clear() set() Sets and Method for SetsSet<string> ProductSet = new Set<string>{'Phenol', 'Benzene', 'H2SO4'}; ProdcctSet.add('HCL'); System.debug('Set with New Value :' +ProductSet); ProductSet.remove('HCL'); ProductSet.contains('HCL'); MapsMap<string, string> ProductCodeToProductName = New Map<string, string> {'1000' =>'HCL', '1001' => 'H2SO4'}; |
Cheatography
https://cheatography.com
Apex Cheat Sheet (DRAFT) by bharatswati
Apex for interview and
This is a draft cheat sheet. It is a work in progress and is not finished yet.