129

Episode 1 – Introduction to Apex (Part 1)

So, you have decided to commence your journey as a Salesforce developer and put your career in the fast-paced lane. Join us as you embark on this wonderful journey to become a champion Salesforce developer. In this module we will introduce the Salesforce platform and acquaint the attendees with Apex.

Agenda

  • Declarative Vs Programmatic Approach of Development
  • Datatypes in Apex
  • Operators in Apex
  • System.Debug()
  • Familiarizing to Dev Tools – VS Code, Anonymous Block
  • Q & A

Most importantly don’t break a leg if you are overwhelmed with the pace of the live sessions. All Apex Hours for Student sessions will be recorded and will be available on our YouTube channel. Please Subscribe our YouTube Channel.

Here is Keynote from our session

Why code?

  • Customized applications
  • Tailored organization processes
  • Collaboration with external systems
  • Custom logic
  • Complex validation

What is Apex?

Strongly typed, object-oriented programming language that allows developers to execute flow & transaction control statements on Salesforce servers in conjunction with calls to the API.

How Apex Works
How Apex Works


Salesforce Application Anatomy

Data Types in Apex

Data Type Description Sample Value
Blob (Binary Large Object) Binary data stored as a single object. You can convert this data type to String or from String using the toString() and valueOf() methods, respectively.  VGhpcyBEb2N1bWVudCBjb250YWlucyBzYW1wbGUgdGV4dCBmb3IgdGhlIFZpc3VhbGZvcmNlIA0KRG9jdW1l
Boolean Logical value True, False, null
Date Indicates a particular day. Unlike Datetime values, Date values contain no information about time.  2020-02-10
Datetime A value that indicates a particular day and time, such as a timestamp. 2020-02-10 07:29:09
Time A value that indicates a particular time.  22:40:36.003Z
Decimal A number that includes a decimal point. Decimal is an arbitrary precision number. Currency fields are automatically assigned the type Decimal. 27.0

Variables in Apex

Variables are in-memory containers that can hold data belonging to a specific data-types during processing and can be reused based on their scope.

Integer inValue = 27;
System.debug(‘ID :’ +inValue);

Demo 2: Using Variables & Operators in Apex

String o = ‘Hello World’; //String
System.debug(‘Blob: ‘ + Blob.valueOf(o)); //Blob

Boolean isActive = true;
System.debug(‘Boolean: ‘ + isActive); //Boolean
System.debug(‘Date: ‘ + Date.newInstance(2020, 01, 18)); //Date

Datetime currDateTime = Datetime.now();
System.debug(‘Date: ‘ + currDateTime); //DateTime
System.debug(‘Time: ‘ + Time.newInstance(22, 40, 36, 03)); //Time

Decimal decValue = 27.01;
System.debug(‘Decimal: ‘ + decValue); //Decimal

Id recordId = [Select Id From Account Limit 1][0].Id;
System.debug(‘ID: ‘ + recordId); //ID

Integer intValue = 27;
System.debug(‘Integer: ‘ + intValue); //Integer

Long longValue = 2147483648L;
System.debug(‘Long: ‘ + longValue); //Long

Object objValue = o;
System.debug(‘Object: ‘ + objValue); //Object

Iterating Collections in Apex

5 Types of Procedural Loops in Apex

  • Do {Code Block} While (Boolean Exit Condition)
  • While (Boolean Exit Condition)
  • For
    • For (Initialization; Boolean Exit Condition; Increment) {Code Block}
    • For (Variable : Array or Set) {Code Block}
    • For (Variable : [Inline SOQL Query]) {Code Block}

Conditional Statements in A

  • If Else…
  • Switch Statements
  • Ternary Operators

Collection in Apex

We have all below collection option in apex. Please check this post to learn more about collection in Apex.

  1. List
  2. Set
  3. Map

Demo 3 – Using Collections in Apex

List<Integer> listOfNumbers = new List <Integer> ();
listOfNumbers.add(1);
listOfNumbers.add(2);
listOfNumbers.add(3);
listOfNumbers.add(3);
System.debug(‘listOfNumbers: ‘ + listOfNumbers);

Set<Integer> setOfNumbers = new Set<Integer>();
setOfNumbers.add(3);
setOfNumbers.add(2);
setOfNumbers.add(2);
setOfNumbers.add(1);
System.debug(‘setOfNumbers: ‘ + setOfNumbers);

Map <Integer,String> mapOfIntegerString = new Map <Integer,String> ();
mapOfIntegerString.put(1, ‘one’);
mapOfIntegerString.put(2, ‘two’);
mapOfIntegerString.put(3, ‘three’);
mapOfIntegerString.put(3, ‘four’);
System.debug(‘mapOfIntegerString: ‘ + mapOfIntegerString);
System.debug(‘Value at 3: ‘ + mapOfIntegerString.get(3));

Demo 4 – Using Loops in Apex

List<integer> listOfNumbers = new List <integer> ();
Integer maxListSize = 5;
for(Integer i = 1; i <= maxListSize; i++){
listOfNumbers.add(i);
}
System.debug(‘listOfNumbers: ‘ + listOfNumbers);

When should I use Apex?

Recording

Here is link of recording

Episode 1 will be presented by Jigar Shah on Feb 10, 2020 at 6 PM Indian Standard Time.

Further Learning

Apex Hours TrailMixes

Assignment

Complete below assignment to win $1000 Salesforce Voucher. Click here for rule.

Write an Apex program to store all the numbers in a List starting from 1 until 20. Only numbers stored at even positions in the List should be added to get their sum which should be output to the Debug Log.

(Hint: Use a while loop and if else along with System. debug()

Don’t forget to register for our next session. Check this post for all other session details.

Please note that we have limit of 500 attendees that can join the online sessions. However, recording will be posted on our YouTube channel. Make sure to subscribe our YouTube channel to get notification for video upload.

So, learn at your pace and free will and ace your journey to Salesforce!

Thanks,

Comments(129)

  1. Reply
    Darshan says:

    Is the link to join the live session if so I am unable to see it if you could share would be wonderful.

    • Reply
      Amit Chaudhary says:

      Say Connected we will share the registration link soon

    • Reply
      Jessica says:

      I have completed Assignment `

  2. Reply
    Lucien YSR OULA ☁️ says:

    Ok 👌look forward to 👍

  3. Reply
    Rama says:

    please share the link

  4. Reply
    Alisha says:

    Link to join the session

    • Reply
      Amit Chaudhary says:

      Click on registration link in the post

  5. Reply
    Pani says:

    Are you available on Udemy?

    • Reply
      Amit Chaudhary says:

      This is totally free, We will upload on YouTube.

      • Reply
        Seetharaman says:

        Thanks for your videos. Waiting for upcoming videos.

  6. Reply
    Dhanalakshmi Vellachamy says:

    Does this entire Developer Program cover the Salesforce Developer Certification modules Or Does it help in Developer Certification?

  7. Reply
    Anuj Sahu says:

    ApexHours Completed my first Assignment of Apex. Looking forward to explore more

  8. Reply
    Amit Pande says:

    Hello Jigar/Apex Team – Thanks for a good starting session for Apex development today. Appreciate your team efforts on the same. I am aware it will take some time and efforts to upload daily recording on youtube and this site, however could you please upload daily ppt used and trailhead links immediately after each session so that we can refer them before next day’s session. Also seen that ppt is not uploaded for last year’s admin sessions and trailhead links for also few. Could you please check that once and upload ppt and trailhead links for all admin session? It will be very useful. – Amit

    • Reply
      Amit Chaudhary says:

      Uploaded all content and Demo code as well

      • Reply
        cBooM says:

        where ? 🙁

  9. Reply
    Dhanalakshmi Vellachamy says:

    Assignment Answer :

    Integer listSize = 20;
    Integer sum=0;
    for (Integer i =1; i<=listSize; i++)
    {
    testList.add(i);
    }
    Integer count = 0;
    while(count < 20 )
    {
    if(math.mod(count, 2) == 0)
    {
    sum = sum + testList[count];
    }
    count++;
    }
    System.debug('Total Sum is ' +sum);

    // Total Sum is 100

    • Reply
      Aswini says:

      integer sum=0;
      list listnumber=new list();
      integer i=1;
      while(i<=20)
      {
      listnumber.add(i);
      i++;
      }
      System.debug('listnumber 1 to 20:'+listnumber);
      for(integer i=1;i<listnumber.size();i++)

      {
      if(Math.mod(listnumber[i], 2)==0)
      {
      sum=sum+listnumber[i];
      System.debug('totalsum value:'+sum);
      }

      }
      System.debug('final totalsum::'+sum);

      out put:istnumber 1 to 20:1,2,3,4,5,6,7,8,9,10……
      inal totalsum::110

      • Reply
        Arnab Saha says:

        integer totalssum=0;
        list listofnumbers=new list();
        for( integer i=1; i<=20 ; i++)
        {
        listofnumbers.add(i);
        }
        System.debug('listnumbers 1 to 20:'+listofnumbers);
        for(integer i=1;i<listofnumbers.size();i++)

        {
        if(Math.mod(listofnumbers[i], 2)==0)
        {
        totalssum=totalssum+listofnumbers[i];
        System.debug('totalsum value:'+totalssum);
        }

        }
        System.debug('final totalsum::'+totalssum);

        • Reply
          Arnab Saha says:

          listofnumbers ko integer define karo

      • Reply
        ritanshu kumar says:

        totalsum::210

  10. Reply
    Asmita says:

    Completed the assignment

  11. Reply
    Asmita says:

    Completed the assignment for day 1

  12. Reply
    Archit Dutt Sharma says:

    Completed the first assignment

  13. Reply
    Isaac Arcos Huicochea says:

    Completed the first Assignment

  14. Reply
    Venkatesh says:

    Many thanks for arranging sessions even in busy schedules. Really appreciate your team efforts.
    I have completed first assignment.

  15. Reply
    Venkatesh says:

    Many thanks for arranging sessions even in your busy schedules. Really appreciate your team efforts.
    I have completed first assignment given today.

  16. Reply
    Ankit Desai says:

    Completed Assignment for Day 1

  17. Reply
    Ankit Desai says:

    Competed Assignment for day 1

  18. Reply
    Dave says:

    I realize that it takes time to accomplish this, but the sooner you could post the video to Youtube the better. For me, it is 4:30am for the sessions. I made it today and fell asleep during it. It had nothing to do with you guys! It was just too early in the morning to be awake. I’d love to be able to schedule watching the video the same day it was done and do the work.

    Thanks for being awesone!

    • Reply
      Amit Chaudhary says:

      We will upload all recording by 6 MARCH

      • Reply
        Sadaf Khan says:

        Thanks

        Assignment Complete-Day 1

  19. Reply
    Natalya says:

    Wohoo, my assignment 1 is complete 🙂 Thank you so much for running these sessions, guys!

  20. Reply
    Ajay Gupta says:

    Completed the assignment of Day 1.

  21. Reply
    Sadaf Khan says:

    Day 1 -Assignment Complete

    Thank you for hosting these sessions.

  22. Reply
    Bhargavi says:

    My assignment for Day 1 is complete

  23. Reply
    Sadaf Khan says:

    Day 1- Assignment Completed.

    Thank you for hosting these session.

  24. Reply
    Sadaf Khan says:

    Assignment Complete

  25. Reply
    Vikas Sharma says:

    Thank you Jigar/Amit for this amazing Initiative.
    Completed my assignment for Day#1

  26. Reply
    Shaik says:

    Done with assignment. Thanks

  27. Reply
    Quang Du says:

    Assignment 1 completed. Thank you deeply for this learning opportunity.

  28. Reply
    Quang Du says:

    Assignment 1 completed. Thank you!

  29. Reply
    Quang says:

    Assignment 1 completed. Thank you!

  30. Reply
    Latha Vemula says:

    Thank you guys so much for motivating other to learn with your good work. This is really exciting and definitely a staring point for people like me to achieve goals to become a salesforce developer. Assignment is completed for day1 #Apexhours session. Looking forward to learn and experience the awesomeness with in this journey.

  31. Reply
    A Belano says:

    Completed Assignment for Day 1. Great first session. Excited to learn more!

  32. Reply
    A Belano says:

    Completed Day 1 Assignment

  33. Reply
    A Belano says:

    Assignment for Day 1 completed!

  34. Reply
    isthiyaq ahamed says:

    Completed the assignment for day 1

  35. Reply
    Erick says:

    Completed the assignment for day 1.

  36. Reply
    Erick says:

    Completed the assignment for day 1.

  37. Reply
    Erick says:

    Completed the assignment for day 1

  38. Reply
    Vandana says:

    First Assignment completed

  39. Reply
    Aathirai says:

    Completed Day 1 Assignment. Waiting eagerly for the next session.

  40. Reply
    Aathirai says:

    Completed Day 1 Assignment.

  41. Reply
    Vanita Sangle says:

    Completed assignment for session 1 ..thank you for your efforts..

  42. Reply
    Vanita Sangle says:

    Completed assignment 1..thank you.

  43. Reply
    waruna says:

    Completed the assignment

  44. Reply
    Diksha Chhabra says:

    Thannks for the valuable session.
    Introduction to Apex Part 1 : Assignment completed

  45. Reply
    Rishab Goyal says:

    Completed Assignment 1

  46. Reply
    Surabhi says:

    completed

  47. Reply
    Surabhi says:

    COmpleted assignment 1 .:)

  48. Reply
    Akhil Kulshrestha says:

    the assignment is complete

  49. Reply
    Prakash says:

    successfully completed assignment1 🙂

  50. Reply
    surabhi says:

    List mylist=new list();

    Integer sum=0;
    for (Integer i =1; i<=20; i++)
    {
    mylist.add(i);
    //system.debug(mylist);
    }
    Integer j = 0;
    while(j < 20 )
    {
    integer check=math.mod(j, 2);
    if(check == 0)
    {
    sum = sum + mylist[j];
    }
    j++;
    }
    System.debug('Sum is ' +sum);

  51. Reply
    Deepak Sah says:

    Thank you so much for wonderful session.

    Assignment is completed.

  52. Reply
    Deepak Sah says:

    Competed Assignment for day 1

  53. Reply
    Marishell Cruz says:

    Completed first assignment for day 1

  54. Reply
    Nishith Agrawal says:

    Completed assignment for day1.

  55. Reply
    Praveen says:

    ApexHours is the best platform that i have seen so far. Thanks for helping people to code. Its is good initiative by the great people working on Salesforce Platform to help people code.

    Thanks for all you hard work to keep this running!! 🙂

    I have completed Assignment 1.

  56. Reply
    Praveen Venkata says:

    It’s a great platform to interact with all great leaders who initiated this program to help people learn code.

    Completed Assignment 1.

  57. Reply
    Preeti says:

    Hi ..Thanks for the really useful and knowledgeable session..Completed Assignment for Day1.

  58. Reply
    Preeti says:

    Thanks for the wonderful session.Completed Assignment 1 of Day 1

  59. Reply
    Paranthaman K says:

    Assignment Completed..

  60. Reply
    Paranthaman K says:

    Assignment 1 Completed..

  61. Reply
    Quang says:

    Assignment 1 completed.

  62. Reply
    Bhavin says:

    Assignment day#1
    —————————-

    Integer totalsum=0;
    List numbers = new List();
    for (Integer i = 1; i <= 20; i ++)
    {
    numbers.add(i);
    }

    //System.debug('listofnumbers'+ numbers);

    for (Integer i=1;i<numbers.size();i++)
    {
    if (Math.mod(numbers[i],2)==0)
    {
    totalsum= totalsum + numbers[i];

    }
    }

    System.debug('total sum is'+totalsum);

  63. Reply
    Bhavin says:

    Assignment#1
    ————————
    Integer totalsum=0;
    List numbers = new List();
    for (Integer i = 1; i <= 20; i ++)
    {
    numbers.add(i);
    }

    //System.debug('listofnumbers'+ numbers);

    for (Integer i=1;i<numbers.size();i++)
    {
    if (Math.mod(numbers[i],2)==0)
    {
    totalsum= totalsum + numbers[i];

    }
    }

    System.debug('total sum is'+totalsum);

  64. Reply
    Gugulothu Anil says:

    assignment is completed

  65. Reply
    Arjinder Kaur says:

    Assignment done

  66. Reply
    Arjinder Kaur says:

    Day1 Assignment done

  67. Reply
    Modi says:

    Hello,
    Assignment Day 1 completed.
    Integer Totalsum = 0;
    List listOfNumbers = New List ();
    For(Integer i=0; i<20; i++){
    listOfNumbers.add(i+1);
    }
    System.debug('listOfNumbers:' +listOfNumbers);
    For(Integer j=0; j<20; j++){
    if(Math.mod(j,2)==0){
    Totalsum = Totalsum +listOfNumbers[j];
    System.debug('Totalsum value:' +Totalsum);
    }
    }
    System.debug('Final summation:' +Totalsum);

  68. Reply
    Brisilda says:

    Day 1 Assignment is completed!

  69. Reply
    balaji manikandan says:

    Day 1 Assignment is completed.

  70. Reply
    balaji manikandan says:

    Assignment 1 completed

  71. Reply
    Keerthana Ramesh says:

    Completed Day 1 Assignment

  72. Reply
    Michael Wind says:

    complete Assigment Day 1

  73. Reply
    Chetan Sharma says:

    Completed Day 1 assignment

  74. Reply
    Rana Khan says:

    Completed the Assignment

  75. Reply
    SaiSagar says:

    Day 1 Assignment Done
    Thanks

  76. Reply
    Sai Sagar says:

    Day 1 Assignment Done
    Thanks

  77. Reply
    Raman Chopra says:

    Day 1 Assignment is completed.

  78. Reply
    Raman Chopra says:

    Day1 Assignment Completed

  79. Reply
    Otieno says:

    Thanks for hosting this awesome session.
    Really looking forward my SalesForce Dev Career.
    Day 1- Assignment Completed.

  80. Reply
    Otieno says:

    Assignment 1: Completed.
    Thanks for the upskilling opportunity.

  81. Reply
    Adnan says:

    Day 1 Assignment Complete

  82. Reply
    Titli Banerjee says:

    Assignment is complete

  83. Reply
    Raman Chopra says:

    #ApexHoursDev @ApexHours
    Day1 Assignment Completed

  84. Reply
    crystal says:

    Integer Totalsum = 0;
    List listOfNumbers = New List ();
    For(Integer i=0; i<20; i++){
    listOfNumbers.add(i+1);
    //System.debug (listOfNumbers[i]);
    }
    System.debug('listOfNumbers:' +listOfNumbers);
    For(Integer j=0; j<20; j++){
    if(Math.mod(j+1,2)==0){
    Totalsum = Totalsum +listOfNumbers[j];
    //System.debug('Totalsum value:' +Totalsum);
    }
    }
    //Final Summation: 110
    System.debug('Final Summation:' +Totalsum);

  85. Reply
    crystal says:

    Day1 Assignment Completed

  86. Reply
    crystal says:

    Integer totalsum=0;
    List numbers = new List();
    for (Integer i = 1; i <= 20; i ++)
    {
    numbers.add(i);
    }

    //System.debug('listofnumbers'+ numbers);

    for (Integer i=1;i<numbers.size();i++)
    {
    if (Math.mod(numbers[i],2)==0)
    {
    totalsum= totalsum + numbers[i];

    }
    }

    System.debug('total sum is'+totalsum);

  87. Reply
    Siva Kumar Gampala says:

    I am new to Salesforce ecosystem and interested in development .Luckily I got to know about this program and started my SalesforceDevelopment journey with ApexHours.Thank you for the great content and helping the community.

  88. Reply
    Imtiaz Ali says:

    Great platform and it help people to learn code. i am new to the world however, looks with your support i would be able to learn much!

  89. Reply
    Jaya Iyer says:

    Assignment 1 Complete

  90. Reply
    James Fody says:

    Assignment 1 complete

  91. Reply
    Shilpa Srikantachar says:

    DAY 1 Assignment Complete

    This is a great initiative and love the great content .
    Being a Salesforce Admin , trying to transition to being a Developer .Hope I get there .

  92. Reply
    Anand says:

    I just went through the Apex hours DAY 1 Video. Its very usefull and I have completed the assignment 1:

    Integer sumofnum = 0;
    List listofn = new List();
    for (Integer i=1; i<=20; i++){
    listofn.add(i);
    }
    System.debug('listofn: '+listofn);

    for (Integer i=1; i < listofn.size(); i++){
    if(Math.mod(listofn[i],2) ==0){
    sumofnum = sumofnum + listofn[i];
    system.debug('sumofnum: ' + sumofnum);
    }
    }
    system.debug('Finalsumofnumbers: ' + sumofnum);

  93. Reply
    Pritam Pramod Dalvi says:

    Day 1 Assignment Completed.

  94. Reply
    Louis Macwan says:

    Day 1 Assignment Completed.

  95. Reply
    Sonia Soni says:

    Done with Day 1 assignment

  96. Reply
    ASHOK KUMAR PANIGRAHI says:

    #ApexHoursDev @ApexHours
    Day1 Assignment Completed

  97. Reply
    NARESH CHANDA says:

    Day 1 Assignment Completed.

  98. Reply
    Pratik Pandey says:

    Day 1 assignment completed

  99. Reply
    kushagra bhardwaj says:

    Thank you so much for these sessions. It really means a lot.
    completed assignment one.

    I just encountered an issue when going through part one of basic loops.
    Program which you have created at 1:18:43, the second loop to add the even numbers.
    The loop you started was from index 1 but it should be from 0.

    Correct me if i am wrong.

  100. Reply
    Ankit Desai says:

    Code for Assignment Day 1
    ——————————–
    Integer countSize = 20;
    Integer counter = 0;
    Integer sum=0;
    List listOfNumbers = new List ();
    for (Integer i =1; i<=countSize; i++){
    listOfNumbers.add(i);
    }
    System.debug('Size of list:' +listOfNumbers.size());
    while(counter < listOfNumbers.size() ){
    if(math.mod(counter, 2) == 0){
    sum = sum + listOfNumbers[counter];
    }
    counter++;
    }
    System.debug('Total Sum for numbers which stored at even positions:' +sum);

    • Reply
      Hurmat says:

      Hi Ankit,
      Integer countSize = 20;
      Integer counter = 0;
      Integer sum=0;
      List listOfNumbers = new List ();
      for (Integer i =1; i<=countSize; i++){
      listOfNumbers.add(i);
      system.debug('the list'+i);
      }
      System.debug('Size of list:' +listOfNumbers.size());
      while(counter<listOfNumbers.size() ){
      if(math.mod(listOfNumbers[counter], 2) == 0){
      sum = sum + listOfNumbers[counter];
      system.debug('the value of sum' +sum);
      }
      counter++;
      }

      System.debug('Total Sum for numbers which stored at even positions:' +sum);
      The sun should come as 110

  101. Reply
    Jim says:

    I realize this training has ended and I attempted the assigments, firstly for Assignment 1; Where can i find the answers to see if I am correct.

    • Reply
      Amit Chaudhary says:

      Just check the other comment in this post only

  102. Reply
    prateek alavadi says:

    integer Sum=0;
    List listOfNumbers = new List();
    for(integer i=1; i<=20; i++){
    listOfNumbers.add(i);
    }
    System.debug('The list of Numbers Are:-'+listOfNumbers);

    for(integer i=0; i<20; i++){
    if(math.mod(i,2)==0){
    sum=sum+listOfNumbers[i];
    }
    }
    System.debug('The addition is:-'+sum);

  103. Reply
    sirish says:

    List listOfNumbers = new List ();
    Integer maxListSize = 20;
    integer j=0;
    for(Integer i = 1; i <= maxListSize; i++){
    listOfNumbers.add(i);
    j=listOfNumbers.size();
    }
    integer i=0;
    integer k=0;
    for(i=0;i<=j;i+=2)
    {
    k=k+i;
    }
    System.debug(k);

  104. Reply
    Priyanka says:

    Integer sum=0;
    List numList= new List();

    for (Integer i=0; i<=20; i++)
    {
    numList.add(i);
    }

    system.debug('numbers added' +numList);

    for(Integer count=1;count<numList.size();count++)
    {
    if(Math.mod(numList[count], 2)==0)
    {
    sum= sum + numList[count];

    }

    }
    system.debug('numbers added in even list' +sum);

    Answer is 110

  105. Reply
    Rahul Das says:

    Hi i am Rahul… I love the way you guys delivery the session. Now i am preparing for developer role. But i can see the developer playlist is not completed. Can you update the playlist with all the video.
    Thank you in advance 🙂

  106. Reply
    Nia says:

    Can you please upload the full ppt showed in videos for every session in .ppt format same as video

  107. Reply
    Sravani says:

    Integer listSize = 20;
    Integer sum=0;
    list testList = new list();
    for (Integer i =1; i<=listSize; i++)
    {
    testList.add(i);
    }
    System.debug('list' + testlist);
    Integer count = 0;
    while(count < 20 ){
    if(math.mod(count, 2) == 0){
    sum = sum + testList[count];
    }
    count++;
    }
    System.debug('Total Sum is ' +sum);

    Total Sum is 100

  108. Reply
    Aruna Devkar-Mulik says:

    List oddNumList=new List();
    for(Integer i=1;i<=20;i++)
    {
    if(Math.mod(i,2)!=0)
    {
    oddNumList.add(i); //List will contain all odd numbers from 1 t 20
    }
    }
    System.debug('List of Odd numbers : '+oddNumList);
    Integer sum=0;
    Integer count = 1;
    while(count< oddNumList.size())
    {
    System.debug('count is :'+(count+1)+' Number at count is : '+oddNumList[count]);
    /*
    List index starts from 0 so to add numbers at even position we need to consider odd index
    list -1,3,5,7,9,11,13,15,17,19 for us even position numbers are 3,7,11,15 & 19
    */
    if(math.mod(count, 2) != 0)
    {
    sum = sum + oddNumList[count];
    }
    count++;
    }
    System.debug('Total Sum is ' +sum);

  109. Reply
    Waqar says:

    list myEvenList = new list();
    integer sum = 0;
    for(integer i=1; i<=20; i++)
    {
    Integer reminder = math.mod(i, 2);
    if(reminder == 0){
    system.debug('Even: '+i);
    sum = sum + i;
    system.debug('Sum '+sum);
    }
    }

  110. Reply
    Sidhant says:

    integer totalSum=0;
    List listOfNumbers = new List();
    for(integer i=1; i<=20; i++){
    listOfNumbers.add(i);
    }
    System.debug('listOfNumbers: ' + listOfNumbers);

    integer i=1;
    While(i < listOfNumbers.size()){
    if(Math.mod(listOfNumbers[i],2)==0){
    totalSum = totalSum + listOfNumbers[i];
    System.debug('totalSum Value: ' + totalsum);
    }

    i++;
    }
    System.debug('Final sumation: ' + totalSum);

  111. Reply
    Dheeraj Gurbani says:

    public class ApexHours1 {
    public static void main(){
    Integer sum = 0;
    List iList = new List();
    for(Integer i = 0; i < 20; i++){
    iList.add(i);
    if(math.mod(i, 2) == 0){
    sum = sum + i;
    }
    }
    System.debug(sum);
    }
    }

Post a comment