Path to Code
Begin Your Salesforce Coding Adventure
Episode 1
Basics, Data Types, Naming Convention
Sr Technical Architect
Salesforce MVP
23 Salesforce Certifications
Jitendra Zaa
Agenda
• Why we need code
• Developer Console
• Naming Conventions
• Data Types
• Collections
• Pass by Value and Pass by Reference
• Trailhead Modules
• Q&A
Some House Rules
• Mute your mic
• Keep adding questions in Zoom Q&A Window
• No question is too small
• Questions will be answered in last 15 mins
Why to learn Code
With great power comes great responsibility
Best Practices
• Write as little code as possible in Salesforce
• Code always used as a last option
• Salesforce has a rich toolset for configuration which is tested,
maintained, and upgraded
• Workflow rules, Process Builder, Approval Process, Visual Flow,
Validation rules, page layouts, and Record types are few alternatives
to customization
How to start
• Create a free Salesforce developer account here
• Start writing code in Developer Console
Developer Console
Where code is written
Variables
• Think of it as Box which holds data
• You must declare a variable before using it
NameData Type Value
Value
countInteger 10=
eNameString ‘John’=
Data Types
• Primitive Data Types
• Collections
• Enums
• Objects (parent of All Objects)
• sObject (Standard or Custom Object)
Primitive Data Types
• Boolean (True, False)
• DateTime (1-2-2019 8:00pm EST)
• Date (1-2-2019)
• Decimal (3.142)
• Double : 64 bit (3.142)
• ID (18 digit Salesforce Id)
• Integer (32 bit number)
• Long (64 bit number)
• Object (parent data type of everything )
• String
• Time
Bonus – When to use Enum ?
• If you want to have restrictive data with limited option then use
enum
• Just like picklist / dropdown you can choose any invalid data
accidently
Public ENUM Season {Summer, Winter, Spring}
Naming Convention
Camel Case
• Word in middle is Capital
• Used for method naming
• Example – iPhone, eBay, seasonName
Pascal Case or Upper Camel Case
• First letter and middle word starts with capital letter
• Companies like Microsoft encourages this
• It’s also known as Upper Camel Case
• Class names should be Pascal Case
• Example - AccountTriggerHandler
Hungarian Notation
• One of the mostly used naming convention
• Variable name indicates intention or Kind
• Example – lstAccount, setContact, mapAccountAddress
Collections
• List
• Map
• Set
List / Array
80 10 80 21 34 55 67 76 2 89
0 1 2 3 4 5 6 7 8 9
Values
Index
Set
80 10 80 21 34 55 67 76 2 89Unique Values
Map
Unique Key Value
1 One
2 Two
3 Three
4 Value
Pass by Value vs Pass by
Reference
Pass By Value
a=10
function
a=10
a=20
Copy of a passed to
method
Value changed in copy and actual
variable still has same value
Pass By Value
• All primitive data types like Integer, Double, Decimal, etc are Pass by
Value
Example
Pass By Reference
a=10
function
a=10
a=20
Copy of a passed to
method
Value changed everywhere
a=20
Pass By Reference
• Any object or Complex Data Type are pass by Reference
• Hint – Mostly Variable initialized using ‘new’ keyword is pass by
Reference
• sObject, object, or classes are Pass by Reference
Example
Resources
• Set Methods
• Primitive Data Types
• List Methods
• Map Methods
• Hungarian Notation
Trailhead Modules
Platform Development Basics Apex Basics & Database Developer Console Basics
Q & A
Thank You
Subscribe
Decimal vs Double
• You can set scale (number of digit to right of decimal) in Decimal but
not in Double
• Decimal has more methods compared to Double
• Currency field is by default Decimal
• Double does not support scientific (e) notation
• Double is 64 bit

Episode 1 - PathToCode.com

  • 1.
    Path to Code BeginYour Salesforce Coding Adventure
  • 2.
    Episode 1 Basics, DataTypes, Naming Convention
  • 3.
    Sr Technical Architect SalesforceMVP 23 Salesforce Certifications Jitendra Zaa
  • 4.
    Agenda • Why weneed code • Developer Console • Naming Conventions • Data Types • Collections • Pass by Value and Pass by Reference • Trailhead Modules • Q&A
  • 5.
    Some House Rules •Mute your mic • Keep adding questions in Zoom Q&A Window • No question is too small • Questions will be answered in last 15 mins
  • 6.
  • 7.
    With great powercomes great responsibility
  • 8.
    Best Practices • Writeas little code as possible in Salesforce • Code always used as a last option • Salesforce has a rich toolset for configuration which is tested, maintained, and upgraded • Workflow rules, Process Builder, Approval Process, Visual Flow, Validation rules, page layouts, and Record types are few alternatives to customization
  • 9.
    How to start •Create a free Salesforce developer account here • Start writing code in Developer Console
  • 10.
  • 11.
    Variables • Think ofit as Box which holds data • You must declare a variable before using it NameData Type Value Value countInteger 10= eNameString ‘John’=
  • 12.
    Data Types • PrimitiveData Types • Collections • Enums • Objects (parent of All Objects) • sObject (Standard or Custom Object)
  • 13.
    Primitive Data Types •Boolean (True, False) • DateTime (1-2-2019 8:00pm EST) • Date (1-2-2019) • Decimal (3.142) • Double : 64 bit (3.142) • ID (18 digit Salesforce Id) • Integer (32 bit number) • Long (64 bit number) • Object (parent data type of everything ) • String • Time
  • 14.
    Bonus – Whento use Enum ? • If you want to have restrictive data with limited option then use enum • Just like picklist / dropdown you can choose any invalid data accidently Public ENUM Season {Summer, Winter, Spring}
  • 15.
  • 16.
    Camel Case • Wordin middle is Capital • Used for method naming • Example – iPhone, eBay, seasonName
  • 17.
    Pascal Case orUpper Camel Case • First letter and middle word starts with capital letter • Companies like Microsoft encourages this • It’s also known as Upper Camel Case • Class names should be Pascal Case • Example - AccountTriggerHandler
  • 18.
    Hungarian Notation • Oneof the mostly used naming convention • Variable name indicates intention or Kind • Example – lstAccount, setContact, mapAccountAddress
  • 19.
  • 20.
    List / Array 8010 80 21 34 55 67 76 2 89 0 1 2 3 4 5 6 7 8 9 Values Index
  • 21.
    Set 80 10 8021 34 55 67 76 2 89Unique Values
  • 22.
    Map Unique Key Value 1One 2 Two 3 Three 4 Value
  • 23.
    Pass by Valuevs Pass by Reference
  • 24.
    Pass By Value a=10 function a=10 a=20 Copyof a passed to method Value changed in copy and actual variable still has same value
  • 25.
    Pass By Value •All primitive data types like Integer, Double, Decimal, etc are Pass by Value
  • 26.
  • 27.
    Pass By Reference a=10 function a=10 a=20 Copyof a passed to method Value changed everywhere a=20
  • 28.
    Pass By Reference •Any object or Complex Data Type are pass by Reference • Hint – Mostly Variable initialized using ‘new’ keyword is pass by Reference • sObject, object, or classes are Pass by Reference
  • 29.
  • 30.
    Resources • Set Methods •Primitive Data Types • List Methods • Map Methods • Hungarian Notation
  • 31.
    Trailhead Modules Platform DevelopmentBasics Apex Basics & Database Developer Console Basics
  • 32.
  • 33.
  • 34.
  • 35.
    Decimal vs Double •You can set scale (number of digit to right of decimal) in Decimal but not in Double • Decimal has more methods compared to Double • Currency field is by default Decimal • Double does not support scientific (e) notation • Double is 64 bit