Interview Questions.

Top 100+ Apex Interview Questions And Answers

fluid

Top 100+ Apex Interview Questions And Answers

Question 1. Onchange Event Does Not Work With <apex:actionsupport> In Ie9. How To Resolve This Error?

Answer :

If we upload the Header on Visualforce web page then it creates masses of hassle in IE9. I think there are few java-script library loaded by using Header of Salesforce which makes IE9 well suited. So the satisfactory solution is to allow the Header by means of the usage of “showHeader=true” in Apex page.

Question 2. If Ie9 Is Not Working With Your Custom Visualforce Page Then How To Tell Your Visualforce Code To Run In Ie8 Compatibility Mode?

Answer :

Add following metatag to pages:

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />

Web Services Interview Questions
Question 3. It May Happen That Above Tips Will Not Work As Lots Of Time The Page Header Already Set. Then, How To Achieve Same Result Using Apex?

Answer :

Add beneath line of code in Apex (Constructor)
Apexpages.CurrentPage().GetHeaders().Positioned('X-UA-Compatible', 'IE=8');

Question four. How To Display The Formatted Number / Date In Visual Force? Which Component Should Be Used?

Answer :

Use element “<apex:outputText>”.

Example : Format the range into forex.

<apex:outputtext value="0, number, 000,000.00">

   <apex:param value="!ValFromController" />

</apex:outputtext>

OR

<apex:outputtext value="0, number, ###,###.00">

   <apex:param value="!ValFromController" />

</apex:outputtext>

Web Services Tutorial
Question five. You Want To Display The Encrypted Field On Visualforce And You Are Using Component Apex:outputtext. Will It Work For Encrypted Fields?

Answer :

Encrypted custom fields which can be embedded inside the <apex:outputText> element show in clean textual content. The <apex:outputText> issue doesn’t admire the View Encrypted Data permission for users. To prevent displaying sensitive information to unauthorized customers, use the <apex:outputField> tag alternatively.

AJAX Interview Questions
Question 6. Will Below Query Work? Explain.
Pick Count(identity), Name, Address__c From Opportunity Group By Name

Answer :

Above question will throw an blunders.

Explanation: In Group by clause the columns decided on ought to be both utilized in Group with the aid of clause or in mixture capabilities. The Name field is neither utilized in aggregate techniques and in organization by way of clause and hence will bring about mistakes “Malformed Query”.

Question 7. Explain Difference In Count() And Count(fieldname) In Soql.?

Answer :

COUNT()

COUNT() should be the simplest element inside the SELECT list.
You can use COUNT() with a LIMIT clause.
You can’t use COUNT() with an ORDER BY clause. Use COUNT(fieldName) as an alternative.
You can’t use COUNT() with a GROUP BY clause for API version 19.Zero and later. Use COUNT(fieldName) alternatively.
COUNT(fieldName)

You can use COUNT(fieldName) with an ORDER BY clause.
You can use COUNT(fieldName) with a GROUP BY clause for API version 19.0 and later.
AJAX Tutorial Salesforce Admin Interview Questions
Question 8. How To Write The “where” Clause In Soql When Group By Is Used?

Answer :

We can't use the “Where” clause with Group By as a substitute we can need to use the “Having Clause“.

Example: 

Get all of the opportunity in which a couple of document exists with identical name and name carries “ABC”.

SELECT COUNT(Id) , Name FROM Opportunity GROUP BY Name  Having COUNT(Id) > 1 AND Name like '%ABC%'

Question 9. Let’s Consider That The First Component In Vf Page Is The Datepicker. In That Case Whenever The Page Loads, Salesforce Auto Focus The First Component Resulting In Datepicker Onfocus Event. Because Of This The Datepicker Component Opens Automatically. How We Can Avoid This?

Answer :

On load occasion, write the javascript code to autofocus some other discipline or any other non-visible issue.

Example :

<span id="focusDistraction"></span>

<script type="text/javascript">

    /* prevent autopup of the date inputfield via the default focus behavoir */

    window.Onload=feature() 

    record.GetElementById('focusDistraction').Focus();

    

</script>

Salesforce Developer Interview Questions
Question 10. How To Force Lead Assignment Rule Via Apex While Updating Or Adding The Lead?

Answer :

To implement Assignment Rules in Apex you will want to carry out following steps:

1. Instantiate the “Database.DMLOptions” class.
2. Set the “useDefaultRule” assets of “assignmentRuleHeader” to True.
3. Finally name a native technique for your Lead called “setOptions”, with the Database.DMLOptions example as the argument.

// to show ON the Assignment Rules in Apex

Database.DMLOptions dmlOptn = new Database.DMLOptions();

dmlOptn.AssignmentRuleHeader.UseDefaultRule = genuine;
leadObj.SetOptions(dmlOptn);

Javascript Advanced Tutorial
Question eleven. Access Custom Controller-described Enum In Custom Component?

Answer :

We cannot reference the enum directly for the reason that enum itself isn't always seen to the page and you can’t make it a property.

Example:

Apex magnificence:

international with sharing class My_Controller 

  public Case currCase get; set; 

  public enum StatusValue RED, YELLOW, GREEN

  public StatusValues getColorStatus() 

    go back StatusValue.RED;  //demo code - simply return crimson

  

Visualforce page:

<apex:image url='stopsign.Png' rendered="!ColorStatus == StatusValue.RED"/>

Above code snippet will throw blunders something like “Save Error: Unknown property‘My_Controller.StatusValue’”

Resolution:

Add below method in Apex Controller:

public String currentStatusValue  get return getColorStatus().Name(); 

and exchange Visualforce code to

<apex:image url='stopsign.Png' rendered="!CurrentStatusValue == 'RED'" />

Javascript Advanced Interview Questions
Question 12. What Is The Need Of “custom Controller” In Visualforce As Everything Can Be Done By The Combination Of Standard Controller + Extension Class.?

Answer :

Sharing placing is applied on fashionable object/extension by default; In case we don’t want to apply sharing putting in our code then Custom controller is most effective choice.
It is viable that the capability of page does no longer required any Standard item or may require more than one preferred object, then if so Custom controller is needed.
Web Services Interview Questions
Question 13. In Class Declaration If We Don’t Write Keyword “with Sharing” Then It Runs In System Mode Then Why Keyword “with out Sharing” Is Introduced In Apex?

Answer :

Let’s take instance, there may be classA declared the use of “with sharing” and it calls classB approach. ClassB isn't always declared with any keyword then through default “with sharing” could be implemented to that magnificence because originating call is carried out thru classA. To avoid this we need to explicitly outline classB with keyword “without sharing”.

XHTML Tutorial
Question 14. If User Doesn’t Have Any Right On Particular Record And Have Only Read Level Access At Object Level. Can He Change The Record Owner?

Answer :

Yes. In profile, there may be putting for “Transfer Record”.

Question 15. In Which Scenario Share Object “mycustomobject__share” Is Not Available/created For Custom Object “mycustomobject” ?

Answer :

The item’s organisation-wide default get entry to degree should now not be set to the most permissive access level. For custom Objects, that is Public Read/Write.

XHTML Interview Questions
Question 16. How To Get The Picklist Value In Apex Class?

Answer :

Using Dynamic apex, we will obtain this. On object of type pickilist, call getDescribe(). Then name the getPicklistValues() approach. Iterate over result and create a listing. Bind it to <apex:selectOptions>.

Code Example:

Let’s say we've a custom item referred to as OfficeLocation__c. This item incorporates a picklist area Country__c.

The first element we need to do, within our controller is locate the getDescribe() approach to reap facts on

the Country__c discipline:

Schema.DescribeFieldResult fieldResult = OfficeLocation__c.Country__c.GetDEscribe();

We understand that Country__c is a picklist, so we need to retrieve the picklist values:

List<Schema.PicklistEntry> ple = fieldResult.GerPicklistValues();

The only factor left for us to do is map the picklist values into an <apex:selectOptions> tag can use for display. Here is the whole method from our controller to do that:

public List<SelectOption> getCountries()

  List<SelectOption> options = new List<SelectOption>();     

   Schema.DescribeFieldResult fieldResult =

 OfficeLocation__c.Country__c.GetDescribe();

   List<Schema.PicklistEntry> ple = fieldResult.GetPicklistValues();        

   for( Schema.PicklistEntry f : ple)

   

      options.Add(new SelectOption(f.GetLabel(), f.GetValue()));

          

   go back alternatives;

With our controller logic all whole, we are able to name the getCountries() method from our Visualforce web page,  and populate the <apex:selectList> tag:

<apex:selectList id="countries" value="!Office_Location__c.Country__c"

         size="1" required="true">

  <apex:selectOptions value="!Countries"/>

</apex:selectList>

Question 17. What Are The Types Of Controller In Visualforce?

Answer :

There are essentially  varieties of Controller in Visual pressure page.

1.     Standard Controller 
2.      Custom Controller

Server Load Balancing Interview Questions
Question 18. How Many Controllers Can Be Used On Single Vf Page?

Answer :

Only one controller may be used salesforce. Other than them, Controller extension can be used.

There can be more than one Controller extension.

Example:

<apex:page standardController="Account"

extensions="ExtOne,ExtTwo" showHeader="false">

<apex:outputText value="!Foo" />

</apex:page>

if ExtOne and ExtTwo, both have the technique getFoo() then the approach of ExtOne can be accomplished.

A controller extension is any Apex class that incorporates a constructor that takes a unmarried argument of typeApexPages.StandardController or CustomControllerName, in which CustomControllerName is the name of a custom controller that you want to extend.

AJAX Interview Questions
Question 19. Explain System.Runas()?

Answer :

Generally, all Apex code runs in device mode, and the permissions and report sharing of the cutting-edge person aren't taken into consideration. The machine method, System.RunAs(), helps you to write test techniques that alternate user contexts to either an present consumer or a brand new user. All of that person’s report sharing is then enforced. You can most effective use runAs in a test technique. The original machine context is started again in spite of everything runAs() take a look at methods entire.

Example :

System.RunAs(u) 

// The following code runs as user 'u'

System.Debug('Current User: ' + UserInfo.GetUserName());

System.Debug('Current Profile: ' + UserInfo.GetProfileId()); 

// Run a few code that assessments file sharing

Question 20. Explain Test.Setpage().?

Answer :

It is used to set the context to current web page, usually used for checking out the visible pressure controller.

Oracle Apex Interview Questions
Question 21. How To Round The Double To Two Decimal Places In Apex?

Answer :

Decimal d = 100/three;
Double ans = d.SetScale(2);

Question 22. In How Many Ways We Can Invoke The Apex Class?

Answer :

1.     Visualforce web page
2.     Trigger
three.     Web Services
4.     Email Services

Question 23. Can We Create Master Detail Relationship On Existing Records?

Answer :

No. As mentioned above, first we need to create the research dating then populate the value on all existing document and then convert it.

Visualforce Interview Questions
Question 24. How Validation Rules Executed? Is It Page Layout / Visualforce Dependent?

Answer :

The validation regulations run at the facts version degree, so they're not tormented by the UI. Any record that is stored in Salesforce will run via the validation regulations.

Salesforce Admin Interview Questions
Question 25. What Is The Difference Between Database.Insert And Insert?

Answer :

insert is the DML declaration that is equal as databse.Insert.

However, database.Insert offers greater flexibility like rollback, default project rules etc. We are able to achieve the database.Insert behavior in insert by using the use of the approach setOptions(Database.DMLOptions)

Important Difference:

If we use the DML assertion (insert), then in bulk operation if error takes place, the execution will stop and Apex code throws an blunders which can be treated in attempt trap block.
If DML database methods (Database.Insert) used, then if mistakes occurs the last data will be inserted / up to date way partial DML operation could be accomplished.
Question 26. What Is The Scope Of Static Variable?

Answer :

When you declare a technique or variable as static, it’s initialized simplest once when a class is loaded. Static variables aren’t transmitted as a part of the view state for a Visualforce page.

Static variables are best static in the scope of the request. They aren't static across the server, or across the complete organization.

Question 27. Other Than Soql And Sosl What Is Other Way To Get Custom Settings?

Answer :

Other than SOQL or SOSL, Custom settings have their very own set of methods to get right of entry to the report.

For instance:If there's custom setting of name ISO_Country,

SO_Country__c code = ISO_Country__c.GetInstance(‘INDIA’);

//To go back a map of information sets defined for the custom object (all statistics in the custom item), //you will use:

Map<String,ISO_Country__c> mapCodes = ISO_Country__c.GetAll();

// display the ISO code for India

System.Debug(‘ISO Code: ‘+mapCodes.Get(‘INDIA’).ISO_Code__c);

//Alternatively you may go back the map as a listing:

List<String> listCodes = ISO_Country__c.GetAll().Values();

Salesforce Developer Interview Questions
Question 28. What Happens If Child Have Two Master Records And One Is Deleted?

Answer :

Child file can be deleted.

Question 29. What Is Difference In Render, Rerender And Renderas Attributes Of Visualforce?

Answer :

render – It works like “show” assets of CSS. Used to reveal or cover detail.

Rerender – After Ajax which issue have to be refreshed – available on commandlink, commandbutton, actionsupport and so on.

Renderas – render page as pdf, doc and excel.

Question 30. How To Get The List Of All Available Sobject In Salesforce Database Using Apex (dynamic Apex)?

Answer :

Map<String, Schema.SObjectType> m =  Schema.GetGlobalDescribe();

Question 31. How To Create Instance Of Sobject Dynamically? Normally The Sobject Is Created Like “account A = New Account();”. But If You Are In Situation That You Don’t Know Which Sobject Is Going To Be Instantiated? Means It Will Be Decided At Runtime, How You Will Handle It?

Answer :

public SObject getNewSobject(String t)

    // Call worldwide describe to get the map of string to token.

            Map<String, Schema.SObjectType> gd = Schema.GetGlobalDescribe();

    // Get the token for the sobject primarily based on the kind.

            Schema.SObjectType st = gd.Get(t);

    // Instantiate the sobject from the token.

            Sobject s = st.NewSobject();

            go back s;

Question 32. How To Get All The Fields Of Sobject Using Dynamic Apex?

Answer :

Map<String, Schema.SObjectType> m  = Schema.GetGlobalDescribe() ;

Schema.SObjectType s = m.Get('API_Name_Of_SObject') ;

Schema.DescribeSObjectResult r = s.GetDescribe() ;

Map<String,Schema.SObjectField> fields = r.Fields.GetMap();

Question 33. How To Get All The Required Fields Of Sobject Dynamically?

Answer :

There isn't any direct belongings available in Apex dynamic API to symbolize the required field. However there is some other way to recognise about it.

If any fields have underneath 3 properties then it is obligatory discipline.

If it's far Creatable
If it isn't nillable and
If it does now not have any default cost
Map<String, Schema.SObjectType> m  = Schema.GetGlobalDescribe() ;

Schema.SObjectType s = m.Get(so.ApiName) ;

Schema.DescribeSObjectResult r = s.GetDescribe() ;

Map<String,Schema.SObjectField> fields = r.Fields.GetMap() ;

for(String f : fields.Keyset())

    Schema.DescribeFieldResult desribeResult = fields.Get(f).GetDescribe();

    if( desribeResult.IsCreateable()  && !DesribeResult.IsNillable() && !DesribeResult.IsDefaultedOnCreate() )

    

//This is obligatory / required field

    

Javascript Advanced Interview Questions
Question 34. What Is Property In Apex? Explain With Advantages.?

Answer :

Apex particularly consists of the syntax from the well known programming language Java. As a practice of encapsulation in java we declare any variable as non-public after which create the setters and getters for that variable.

Non-public String name;

public void setName(String n)

  name = n;

public String getName()

 go back name;

However, the Apex delivered the brand new concept of property from language C# as proven under:

public String call get; set;

As we are able to see how easy the code is and in preference to the use of nearly eight to 11 lines all accomplished in 1 line only. It might be very useful whilst masses of member is said in Apex elegance. It has another gain in “variety of strains of code” restrict with the aid of salesforce which will significantly reduced.

Question 35. What Is The Controller Extension?

Answer :

Any apex class having a public constructor with Custom Controller or Standard Controller item as a single argument is called controller extension.

Question 36. Explain The Need Or Importance Of The Controller Extension.?

Answer :

Controller extension could be very useful and crucial idea introduced by the salesforce recently. It offers the strength to programmer to increase the functionality of existing custom controller or preferred controller.

A Visualforce will have a unmarried Custom controller or wellknown controller however many controller extensions.

We can say that the custom extension is the supporter of custom or preferred controller.

Consider one instance: If there is one controller written and used by the a couple of visualforce pages and one of them desires some greater common sense. Then in place of writing that logic to controller elegance (Which is utilized by many visualforce pages) we will create a controller extension and practice to that page simplest.

XHTML Interview Questions
Question 37. How To Read The Parameter Value From The Url In Apex?

Answer :

Consider that the parameter name is “RecordType”.

String recordType = Apexpages.CurrentPage().GetParameters().Get('RecordType');

Question 38. If One Object In Salesforce Have 2 Triggers Which Runs “before Insert”. Is There Any Way To Control The Sequence Of Execution Of These Triggers?

Answer :

Salesforce.Com has documented that trigger series can not be predefined. As a satisfactory exercise create one cause per item and use comment blocks to separate different common sense blocks. By having all logic in a single trigger you can additionally be able to optimize for your SOQL queries.

Question 39. What Is The Difference Between Trigger.New And Trigger.Old In Apex – Sfdc?

Answer :

Trigger.New:

Returns a listing of the new variations of the sObject statistics

Note that this sObject list is simplest available in insert and replace triggers

i.E., Trigger.New is available in before insert, after insert, before update and after update

In Trigger.New the information can handiest be changed in earlier than triggers.

Trigger.Vintage:

Returns a list of the antique versions of the sObject facts

Note that this sObject list is only to be had in replace and delete triggers.

I.E., Trigger.Old is available in after insert, after update, before delete and after update.

Question 40. How To Restrict Any Trigger To Fire Only Once?

Answer :

Triggers can fire twice, once earlier than workflows and as soon as after workflows.

“The earlier than and after triggers hearth one more time only if some thing desires to be updated, If the fields have already been set to a price, the triggers aren't fired again.”

Workaround:

public elegance HelperClass 

   public static boolean firstRun = actual;

cause affectedTrigger on Account (earlier than delete, after delete, after undelete) 

    if(Trigger.IsBefore)

        if(Trigger.IsDelete)

            if(HelperClass.FirstRun)

                        Trigger.Old[0].AddError('Before Account Delete Error');

                        HelperClass.FirstRun=false;

                        
             
      


Server Load Balancing Interview Questions
Question forty one. What Are Global Variables Explain With Examples?

Answer :

Global variables are the variables used to reference the overall facts about the modern-day person or your corporation on a page.

Example:

Global variables should be referenced using Visualforce expression syntax to be evaluated, as an instance, !$User.Name.

List of to be had worldwide variables are as beneath:

1.     $Action
2.     $Api
three.     $Component
four.     $ComponentLabel
5.     $CurrentPage
6.     $Label
7.     $Label.Site
8.     $ObjectType
9.     $Organization
10.  $Page
eleven.  $Profile
12.  $Resource
thirteen.  $SControl
14.  $Setup
15.  $Site
sixteen.  $User
17.  $UserRole
18.  $System.OriginDateTime 
19.  $ User.UITheme and $User.UIThemeDisplayed

Question 42. How To Create Many To Many Relationships Between Object?

Answer :

Creating Many to Many dating in salesforce is little intricate. You can not create this form of dating at once. Follow underneath steps to create this sort of dating.
Create both objects which have to be interlinked.
Create one custom item (additionally called as junction object), which have to have car variety as particular identity and create two master relationships for both gadgets, no want create tab for this object.
Now on each items, add this subject as related list.
Oracle Apex Interview Questions
Question forty three. In Which Sequence Trigger And Automation Rules Run In Salesforce.Com?

Answer :

The following is the order salesforce logic is implemented to a record.

1.     Old record loaded from database (or initialized for brand new inserts)
2.     New record values overwrite antique values
three.     System Validation Rules
four.     All Apex “before” triggers (EE / UE best)
5.     Custom Validation Rules
6.     Record stored to database (however not dedicated)
7.     Record reloaded from database
eight.     All Apex “after” triggers (EE / UE most effective)
nine.     Assignment policies
10.  Auto-response guidelines
eleven.  Workflow policies
12.  Escalation guidelines
thirteen.  Parent Rollup Summary Formula cost up to date (if gift)
14.  Database devote
15.  Post-commit good judgment (sending e mail)
Additional notes: There is no way to govern the order of execution within every institution above.

Question forty four. What Is S-manage?

Answer :

S-Controls are the fundamental salesforce.Com widgets which are absolutely primarily based on Javascript. These are hosted by using salesforce however executed at consumer side. S-Controls are outdated through Visualforce now.

Question forty five. What Is A Visualforce Page?

Answer :

Visualforce is the new markup language from salesforce, by way of the usage of which, We can render the same old forms of salesforce. We can still use HTML here in Visualforce. Each visualforce tag usually begins with “apex” namespace.

All the design element can be acomplished via the use of Visualforce Markup Language and the enterprise common sense can be written in custom controllers associated with the Page.

Question forty six. Will Visual Force Still Supports The Merge Fields Usage Like S-manage?

Answer :

Just like S-Controls, Visualforce Pages help embedded merge fields, just like the !$User.FirstName used in the instance.

Question forty seven. What Are Merge Fields? Explain With Example?

Answer :

Merge fields are fields that we can put in Email templates, mail merge templates, custom hyperlink or system fields to comprise values from a file.

Example: !CustomObject.FieldName__c

Question 48. Where To Write Visualforce Code?

Answer :

You can write the code basically in 3 approaches.

1.     Setup->App Setup->Develop->Pages and create new Visulaforce page.

2.     Setup -> My Personal Information -> Personal Information -> Edit test the checkbox improvement mode. When you run the web page like this, https://ap1.Salesforce.Com/apex/MyTestPage.You will find the Page editor at the lowest of the page. You can write you web page in addition to the controller class related to it, there itself.

Three.     Using Eclipse IDE you could create the Visulaforce page and write the code.

Question forty nine. What Is Difference In Isnull And Isblank?

Answer :

ISNULL:

Determines if an expression is null (clean) and returns TRUE if it is. If it includes a value, this feature returns FALSE.
Text fields are never null, so the usage of this function with a text area constantly returns false. For example, the system field IF(ISNULL(new__c) 1, zero) is constantly 0 no matter the fee in the New discipline. For textual content fields, use the ISBLANK characteristic instead.
Multi-choose picklist fields are by no means null in s-controls, buttons, and e-mail templates, so using this feature with a multi-select picklist subject in the ones contexts usually returns fake.
Empty date and date/time fields usually return real while referenced in ISNULL features.
Choose Treat clean fields as blanks to your system while referencing various, percent, or foreign money subject in an ISNULL characteristic. Choosing Treat clean fields as zeroes offers blank fields the price of zero so none of them could be null.
Merge fields can be dealt with as blanks, which can affect the effects of components like s-controls because they are able to call this characteristic.
When the use of a validation rule to make certain that a number discipline consists of a particular price, use the ISNULL feature to consist of fields that don't comprise any cost. For instance, to validate that a custom discipline consists of a fee of ’1,’ use the subsequent validation rule to show an mistakes if the sector is blank or any other wide variety: OR(ISNULL(field__c), field__c<>1)
ISBLANK:

Determines if an expression has a fee and returns TRUE if it does now not. If it carries a price, this function returns FALSE.
Use ISBLANK as opposed to ISNULL in new formulation. ISBLANK has the equal functionality as ISNULL, however also helps text fields. Salesforce.Com will maintain to assist ISNULL, so that you do no longer need to alternate any current formulas.
A subject isn't empty if it carries a character, clean area, or 0. For instance, a discipline that contains a space inserted with the spacebar isn't empty.
Use the BLANKVALUE function to go back a particular string if the sector does not have a fee; use the ISBLANK function in case you handiest want to check if the sector has a fee.
If you use this feature with a numeric discipline, the characteristic best returns TRUE if the sector has no fee and is not configured to treat clean fields as zeroes.
Question 50. How To Schedule A Class In Apex?

Answer :

To invoke Apex lessons to run at specific instances, first enforce the Schedulable interface for the magnificence, then specify the time table the use of both the Schedule Apex web page inside the Salesforce user interface, or the System.Time table method.

After you implement a class with the Schedulable interface, use the System.Schedule method to execute it. The scheduler runs as machine: all classes are completed, whether the user has permission to execute the magnificence or not.

The System.Schedule approach takes three arguments: a call for the activity, an expression used to represent the time and date the activity is scheduled to run, and the call of the class. 

Salesforce most effective provides the method to the queue on the scheduled time. Actual execution may be delayed primarily based on provider availability. The System.Schedule approach makes use of the person's time sector for the idea of all schedules. You can only have 25 lessons scheduled at one time.

Example Code:

String CRON_EXP = 'zero 0 * * * ?';

clsScheduledHourly sch = new clsScheduledHourly();

machine.Time table('Hourly Sync', CRON_EXP, sch);

Question fifty one. What Are Different Apis In Salesforce.Com?

Answer :

REST API:

REST API provides a effective, convenient, and simple REST-based Web services interface for interacting with Salesforce. Its blessings encompass ease of integration and development, and it’s an exceptional desire of technology for use with cell applications and Web initiatives. However, if you have a large variety of facts to process, you could wish to apply Bulk API, that is primarily based on REST standards and optimized for large sets of facts.

SOAP API:

SOAP API affords a powerful, handy, and simple SOAP-based Web offerings interface for interacting with Salesforce.You can use SOAP API to create, retrieve, replace, or delete records. You can also use SOAP API to perform searches and lots extra. Use SOAP API in any language that helps Web offerings.

For instance, you can use SOAP API to combine Salesforce with your corporation’s ERP and finance structures, deliver real-time sales and aid facts to business enterprise portals, and populate essential enterprise structures with client facts.

Chatter API:

Chatter API is a REST API that offers programmatic get admission to to Chatter feeds and social records including users, businesses, fans, and files. It's used by builders who need to combine Chatter into a selection of packages including mobile applications, intranet sites, and 1/3-party Web packages. Chatter API is just like APIs offered with the aid of other businesses with feeds, which include Facebook and Twitter. Its benefits consist of ease of integration and improvement.

Bulk API:

Bulk API is primarily based on REST ideas and is optimized for loading or deleting massive units of records. You can use it to query, insert, replace, upsert, or delete a big wide variety of statistics asynchronously via filing batches which might be processed within the heritage with the aid of Salesforce.

SOAP API, in comparison, is optimized for actual-time patron packages that replace small numbers of facts at a time. Although SOAP API can also be used for processing large numbers of statistics, whilst the statistics sets incorporate loads of thousands of facts, it becomes much less realistic. Bulk API is designed to make it simple to process statistics from some thousand to millions of information.

The simplest manner to apply Bulk API is to allow it for processing statistics in Data Loader the usage of CSV files. This avoids the need to write down your own purchaser application.

Metadata API:

Use Metadata API to retrieve, deploy, create, update, or delete customizations on your enterprise. The most common use is to migrate adjustments from a sandbox or checking out employer for your manufacturing surroundings. Metadata API is supposed for dealing with customizations and for constructing equipment that can manage the metadata version, not the information itself.

The easiest way to get entry to the capability in Metadata API is to apply the Force.Com IDE or Force.Com Migration Tool. These gear are constructed on pinnacle of Metadata API and use the standard Eclipse and Ant equipment respectively to simplify the project of working with Metadata API. Built on the Eclipse platform, the Force.Com IDE offers a cozy surroundings for programmers acquainted with included improvement environments, allowing you to code, compile, check, and installation all from inside the IDE itself. The Force.Com Migration Tool is good in case you want to apply a script or a command-line utility for moving metadata between a neighborhood listing and a Salesforce agency.

Streaming API:

Use Streaming API to receive notifications for adjustments to information that fit a SOQL query which you outline.

Streaming API is useful when you need notifications to be driven from the server to the patron. Consider Streaming API for packages that poll often. Applications which have constant polling movement towards the Salesforce infrastructure, consuming pointless API call and processing time, could benefit from this API which reduces the variety of requests that return no information. Streaming API is likewise best for applications that require preferred notification of information modifications. This enables you to reduce the wide variety of API calls and improve performance.

Apex REST API:

Use Apex REST API when you want to show your Apex instructions and techniques so that outside packages can get entry to your code thru REST architecture. Apex REST API helps each OAuth 2.Zero and Session ID for authorization.

Apex SOAP API:

Use Apex SOAP API whilst you want to expose your Apex techniques as SOAP Web carrier APIs so that outside packages can get admission to your code through SOAP. Apex SOAP API supports both OAuth 2.0 and Session ID for authorization.

Question 52. How To Display Error Message On Visualforce Page?

Answer :

In the Visualforce web page add the tag:

 <apex:pageMessages />

 In the controller class upload the mistake message in which required

if ( requiredFieldName == null)

            ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please enter a cost within the Required Field'));

Question 53. What Is Visualforce View State? And What Are Best Practices To Reduce The View State Size?

Answer :

Visualforce pages that comprise a form factor also include an encrypted, hidden form subject that encapsulates the view state of the page. This view kingdom is robotically created, and as its call suggests, it holds the nation of the web page – nation that includes the components, discipline values and controller country.

Best Practices to lessen the view kingdom size:

Minimize variety of shape on a web page.  Use apex:actionRegion in place of the usage of 2 or more forms.
Refine your SOQL to best retrieve the statistics wished by the page.
All public and personal statistics participants found in Standard, Custom and Controller extensions are stored.
Mark any Apex variables that aren't essential to the view country as Transient. (The brief variables aren't surpassed to view state and therefore now not saved in View State)
Create wizards with as few pages as possible
Use outputLink additives instead of commandLink or commandButton components in which feasible as they don’t need to be nested in a form.
Question fifty four. What Are Custom Settings?

Answer :

Custom settings are much like custom items and enable utility builders to create custom sets of data, in addition to create and partner custom facts for an agency, profile, or unique person. All custom settings facts is exposed in the application cache, which permits green get entry to with out the value of repeated queries to the database. This information can then be utilized by formula fields, validation guidelines, Apex, and the SOAP API.

There are two kinds of custom settings:

List Custom Settings

A form of custom placing that provides a reusable set of static information that can be accessed throughout your agency. If you use a selected set of facts often inside your utility, putting that records in a listing custom putting streamlines access to it. Data in listing settings does not vary with profile or consumer, but is available agency-huge. Because the statistics is cached, get right of entry to is low-value and efficient: you do not should use SOQL queries that be counted in opposition to your governor limits.

Hierarchy Custom Settings

A kind of custom placing that uses a integrated hierarchical logic that helps you to “customize” settings for unique profiles or users. The hierarchy logic checks the employer, profile, and person settings for the modern user and returns the most specific, or “lowest,” fee. In the hierarchy, settings for an organization are overridden by means of profile settings, which, in turn, are overridden by using consumer settings.

Question fifty five. What Is Apex?

Answer :

It is the in-house era of salesforce.Com that is just like Java programming with object orientated principles and to put in writing our own custom good judgment.

• Apex is a procedural scripting language in discrete and finished by way of the Force.Com platform.
• It runs natively at the Salesforce servers, making it extra powerful and faster than non-server code, including JavaScript/AJAX.
• It uses syntax that seems like Java
• Apex can written in triggers that act like database saved methods.
• Apex lets in builders to attach business logic to the file save process.
• It has built-in help for unit take a look at advent and execution.

Apex offers integrated guide for commonplace Force.Com platform idioms, together with:

• Data manipulation language (DML) calls, together with INSERT, UPDATE, and DELETE, that encompass integrated DmlException handling
• Inline Salesforce Object Query Language (SOQL) and Salesforce Object Search Language (SOSL) queries that return lists of sObject statistics

- Looping that allows for bulk processing of multiple records at a time
- Locking syntax that prevents file replace conflicts
- Custom public Force.Com API calls that may be constructed from stored Apex methods
- Warnings and mistakes issued while a user attempts to edit or delete a custom object or discipline that is referenced by way of Apex

Note: Apex is protected in Unlimited Edition, Developer Edition, Enterprise Edition, and Database.Com

Apex vs. Java: Commonalities

• Both have classes, inheritance, polymorphism, and different not unusual OOP functions.
• Both have the same name variable, expression, and looping syntax.
• Both have the same block and conditional assertion syntax.
• Both use the same item, array, and comment notation.
• Both are compiled, strongly-typed, and transactional. 

Apex vs. Java: Differences 

• Apex runs in a multi-tenant surroundings and is very managed in its invocation and governor limits.
• To avoid confusion with case-insensitive SOQL queries, Apex is likewise case-insensitive.
• Apex is on-demand and is compiled and performed in cloud.
• Apex isn't always a popular motive programming language, however is as an alternative a proprietary language used for specific enterprise logic functions.
• Apex requires unit checking out for development right into a production surroundings.

Question 56. Explain The Apex Data Manipulation Language (dml) Operations?

Answer :

Use information manipulation language (DML) operations to insert, update, delete, and repair information in a database.

You can execute DML operations using  distinct bureaucracy:

Apex DML statements, together with:

insertSObject[]

Apex DML database strategies, together with:

Database.SaveResult[] result = Database.Insert(SObject[])

While maximum DML operations are available in both shape, a few exist only in a single shape or the alternative.

The unique DML operation paperwork allow different styles of exception processing:

    Use DML statements in case you need any errors that happens during bulk DML processing to be thrown as an Apex exception that right now interrupts control waft (by using using try. . .Trap blocks). This behavior is just like the manner exceptions are dealt with in most database procedural languages.

         Use DML database methods in case you want to permit partial success of a bulk DML operation—if a file fails, the the rest of the DML operation can nonetheless prevail. Your utility can then check out the rejected information and in all likelihood retry the operation. When using this form, you may write code that in no way throws DML exception errors. Instead, your code can use the right outcomes array to decide achievement or failure. Note that DML database methods also consist of a syntax that supports thrown exceptions, just like DML statements.




CFG