Basic apex Interview Questions and answers part - 2

apex-Interview-questions

Basic apex Interview Questions and answers

Apex basic concepts on data types, Control Flow Statements, collections, Methods, classes and Access Modifiers Interview questions.

11. What are the data types and Variables supported by apex?
Ans: Force.com apex language supports following data types.
  • Primitive (Integer, Double, Long, Date, Datetime, String, Id, and Boolean)
  • Collections (List, Set and Map)
  • Sobjects (Ex: account, contact, custom_object__c etc)
  • Enums
  • Classes, Objects and Interface
12. What are the Control Flow Statements supported by Apex?
Ans: Control flow statements are used to controls the flow of the code execution order in any language.
Apex programming language supports the following control flow statements.
  • If else statements
  • do while
  • while
  • for (initialization; Boolean_exit_condition; increment)
  • for (variable : array_or_set)
  • for (variable : [inline_soql_query])
Use Break to exit the loop and Continue to Skip to next iteration of the loop.

13. What are the collection types Used in Apex?
Ans: Apex supports 3 types of collections.
  • List
  • Set
  • Map

14. What is the difference between List and Set?
Ans:
List: List is a Ordered items of collection. List can contain duplicate items. List items can be  primitive data types, collections, s-objects, user defined types and built in apex types.
Ex: List<String> my_list = new List<String>();

Set: Set is a un Ordered items of collection. Set can't contains duplicate items. Set items can be  primitive data types, collections, s-objects, user defined types and built in apex types.
Ex: Set<String> my_set = new set<String>();

15. What is a constructor? and How to write a constructor in apex?
Ans: Apex Constructor is a Special Method in a Class and it's used to initialize the object. and apex constructor is called at the time of object creation. It's used to  provides data for the object.
  • Keep in mind before you create a apex Constructor.
  • Apex Constructor Name must be same name of the class name
  • Apex Constructor don't have a return type (even not support void )
We can write a constructor in apex, like in java. see the following example.
public with sharing class AccountInfo{
    public AccountInfo(){
        // statements
    }
}

16. What are the Access Modifiers in Apex?
Ans: Apex language supports following access modifiers for Methods and Variables.
  • Private
  • Protected
  • Public
  • Global

17. What is the difference between Global and Public classes?
Ans:
Public: When we declare a Method or Variable as a Public it can be used within application or namespace.

Global: When we declare a Method or Variable as a Public it can be used any application or namespace. Web service must be declared as Global.because it can be accessed anywhere.

Note: If we declare a method or variable as a Global, then you must also declare the class as Global.

18. What is the difference between Private and Protected?
Ans:
Private: by default all the methods and variables are private, if you don't specify any access modifier. private methods or variables are accessible within that apex class only.

Protected: when we declare a Method or Variable as a Protected, it's visible to inner classes of that apex class and classes that extend the defining apex class.
It's more strictly permissive then private.

19. What is the difference between Apex classes and Java classes?
Ans: I can't say in single line. follow the below link, there explained detailed.

20.What is a with sharing and Without Sharing classes in Apex?
Ans: When we declare a apex classes with sharing or without sharing to whether or not to enforce sharing rules.

Without Sharing: Without define any keyword by default all the apex code runs in system context. It means Not applied current user object permissions, field-level security, sharing rules. so you don't get any error like, You don't have edit permissions. Without specifying any keyword apex code is Without Sharing.

With Sharing: when we Use With sharing keyword apex code runs current user sharing rules.

COMMENTS

Name

Android Apps,1,Apex,7,Apex Methods,1,Batch Apex,2,Chrome Add-on,1,Chrome browser,1,Coding Best Practices,2,CRM Basics,1,cURL,1,Database Query,1,Dataset,1,Dynamic Apex,3,Dynamic SOQL,1,Einstein Analytics,9,Future Apex,1,Git,1,Google Chrome,1,IDs and Urls Hacks,1,JS for LWC,5,Lightning Components,2,lightning Page,1,Lightning Web Components,14,Linux for Windows users,1,LWC,16,LWC-JEST,7,Queueable Apex,1,Redirect page,1,REGEX,1,REST API,1,Salesforce CRM,1,Salesforce Errors,1,Salesforce Handy Commands,1,Salesforce Interview Questions,14,Salesforce Lightning,1,Salesforce New Features,1,Salesforce Tasks,2,Schedule Apex,1,SLDS,4,SVG Image,3,Test Class,1,Triggers,1,uiObjectInfoApi,1,Visualforce Pages,3,Visualforce Pagination,2,VS Code,2,Wave Analytics,7,Winter Release Notes,1,workbench,1,
ltr
item
SWDC WORLD (Software Development Center Of The World) - is a Multi author and Multi Technology Blog: Basic apex Interview Questions and answers part - 2
Basic apex Interview Questions and answers part - 2
Apex basic Interview questions and answers on concepts on data types, Control Flow Statements, collections, Methods, classes and Access Modifiers .
https://1.bp.blogspot.com/-pO6NzdC9lDA/V_ZUZOBwhvI/AAAAAAAAACE/FhhIUb1Bk2g4GyKfREhBgvB3rVlqmoTjgCLcB/s400/apex_Interview_Questions-part-2.jpg
https://1.bp.blogspot.com/-pO6NzdC9lDA/V_ZUZOBwhvI/AAAAAAAAACE/FhhIUb1Bk2g4GyKfREhBgvB3rVlqmoTjgCLcB/s72-c/apex_Interview_Questions-part-2.jpg
SWDC WORLD (Software Development Center Of The World) - is a Multi author and Multi Technology Blog
https://www.swdcworld.com/2016/10/basic-apex-interview-questions-and.html
https://www.swdcworld.com/
https://www.swdcworld.com/
https://www.swdcworld.com/2016/10/basic-apex-interview-questions-and.html
true
5370056087523941001
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy