ApexGuru OR ApexLearner Quiz 2

ApexGuru OR ApexLearner Quiz 2

Unpredictability means what it means. I don't know how you define it. It is what it is. (Michael Keaton)

But don't worry if your fundamentals are strong in Apex programming you can predict the output for almost any of the code :)

ApexGuru Apex class code as mentioned below.


public class ApexGuru {
    
    public void methodOne(){
        
        Map<Id,Contact> apexGuruMap = new Map<Id,Contact>();
        methodTwo(apexGuruMap);
		System.debug('Apex Guru has won with count :::'+apexGuruMap.size());
    }
    
    public void methodTwo(Map<Id,Contact> apexGuruMap){
        
       apexGuruMap = new Map<ID, Contact>([SELECT Id, LastName FROM Contact LIMIT 3]);
    }

}

ApexLearner Apex class code as mentioned below.

public class ApexLearner {
    
    public void methodOne(){
        
        Map<Id,Contact> apexLearnerMap = new Map<Id,Contact>();
        methodTwo(apexLearnerMap);
        System.debug('Apex Learner has won with count :::'+ apexLearnerMap.size());
    }
    
    public void methodTwo(Map<Id,Contact> apexLearnerMap){
        
       Map<Id,Contact> apexLearnerMapTemp = new Map<ID, Contact>([SELECT Id, LastName FROM Contact LIMIT 3]);
       apexLearnerMap.putAll(apexLearnerMapTemp);
    }

}

Let me know the output in the comment section if we execute below syntax through Anonymous window.


ApexGuru aGuru = new ApexGuru();
aGuru.methodOne();
------------------------------

ApexLearner aLearner = new ApexLearner();
aLearner.methodOne();

?


*Note: Please don't waste your time if you run the same in Developer console and paste the output here as this way we are not going to make any changes in our development skills. 


If you like this article please share with other Salesforce programmers as well.

Ashutosh Garg

Certified Salesforce Application Architect | 11 X Salesforce Certified | Delivery Hero

5 年

Apex Guru has won with count :::0 Apex Learner has won with count :::0

回复
Nishant Prajapati

Technical Lead | 4x Certified Salesforce Developer | APEX | Visualforce | JavaScript | Aura | LWC | Integration

7 年

Apex Guru has won with count :::0 Apex Learner has won with count :::3 When ApexGuru class in instantiated and methodOne is called, apexGuruMap Map variable is local to methodOne and exist on stack frame of methodOne in stack Memory.In methodTwo call, we are initializing the map variable, that means, the variable is local to methodTwo. Where as in ApexLearner, a new map variable is created and its value is Copied to the apexGuruMap. So in output the size of the map is 3.

回复
Ashok Kumar Nayak

Director of Salesforce Architecture @ Cint | Designing Innovative Salesforce Solutions

7 年

For both the controllers the output will be only debug statement with count 0. Apex Guru has won with count :::0 Apex Learner has won with count :::0

回复

要查看或添加评论,请登录

Viren Sa的更多文章

  • Sometimes Age and Certification count comes alone !

    Sometimes Age and Certification count comes alone !

    Here are few things which I should ask to myself ? 1. Do I judge maturity level of person with his/her Age ? 2.

    1 条评论
  • Outcome is same but journey experience matters !

    Outcome is same but journey experience matters !

    “Success is a journey, not a destination. The doing is often more important than the outcome.

    1 条评论
  • WORA : Write Once Use Everywhere

    WORA : Write Once Use Everywhere

    Hello Bhaiyo and Bhano, Ladies and Gentleman, Boys and Girls. I hope you have heard about this phrase Necessity is the…

    1 条评论
  • ApexGuru or ApexLearner Quiz 1

    ApexGuru or ApexLearner Quiz 1

    Can you please help us to find out what will be the correct output on console log for below code snippet as for us this…

    7 条评论
  • What will be the output ?

    What will be the output ?

    Assume we have one Trigger defined on Case Object in Salesforce. Trigger code will look like below.

    3 条评论
  • How much difficult to learn Salesforce ( Admin Role)

    How much difficult to learn Salesforce ( Admin Role)

    **NO TECHNICAL BACKGROUND REQUIRES TO LEARN SALESFORCE ADMIN :) Before to understand how much difficult to learn…

    4 条评论
  • ForceFunda has been launched

    ForceFunda has been launched

    Key to unlock excellence in Salesforce for a beginner as a duck takes to water. Introduction video is here.

社区洞察

其他会员也浏览了