Salesforce Interview Questions – Part 10

Author posted by Jitendra on Posted on under category Categories Salesforce and tagged as Tags , , , , with 6 Comments on Salesforce Interview Questions – Part 10

This Part of Salesforce interview question series depict on browser compatibility issue (Internet Explorer 9) and Visualforce normally for AJAX, Group By and Having Clause.


91. How to add the Document Header in Visualforce page?
Ans : Directly there is no way to add the document type in visualforce. However in most of the cases IE9 does not work with Visualforce pleasantly. And then we need to add the Document type in header. So following workaround will work.

<apex:outputText
escape="false"
value="{!'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'}"/>
<html>
    <head>
        <title>test</title>
    </head>
    <body>test</body>
</html>
</apex:page>

Read more in detail in thread – http://boards.developerforce.com/t5/Visualforce-Development/Changing-doctype-of-a-Visualforce-Page/td-p/82397/page/2


92. Onchange event does not work with <apex:actionsupport> in IE9. How to resolve this error?
Ans: If we hide the Header on Visualforce page then it creates lots of problem in IE9. I think there are few java-script library loaded by Header of Salesforce which makes IE9 compatible. So the best solution is to enable the Headre by using “showHeader=true” in Apex page.
Read more in detail in below thread URL : http://boards.developerforce.com/t5/Apex-Code-Development/IE9-requires-header-in-VF-Page/td-p/402997


93. If IE9 is not working with your custom visualforce page then how to tell your visualforce code to run in IE8 compatibility mode?
Ans:
Add following metatag to pages:

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

94. It may happen that above tips will not work as lots of time the page header already sent. then how to achieve same result using Apex?
Ans:
Add below line of code in Apex (Constructor)

Apexpages.currentPage().getHeaders().put('X-UA-Compatible', 'IE=8');

Read more tips and tricks to solve IE9 issue in Salesforce here.


95. How to display the formatted number / date in Visualforce ? Which component should be used?
Ans : Use component “<apex:outputText>”.
Example : Format the number into currency.

<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>

Read in Detail , here


96. You want to display the Encrypted field on Visualforce and you are using component apex:outputText. Will it work for Encrypted fields?
Ans : Encrypted custom fields that are embedded in the <apex:outputText> component display in clear text. The <apex:outputText> component doesn’t respect the View Encrypted Data permission for users. To prevent showing sensitive information to unauthorized users, use the <apex:outputField> tag instead.


Below Questions related to Group by clause in SOQL

97. Will below query work? Explain.

SELECT COUNT(Id), Name, Address__c FROM Opportunity GROUP BY Name

Ans :
Above query will throw an error.
Explanation : In Group by clause the columns selected must be either used in Group by clause or in aggregate functions. The Name field is neither used in aggregate methods and in group by clause and hence will result in error “Malformed Query”.

Read more here in detail – Group by Documentation


98. Explain difference in COUNT() and COUNT(fieldname) in SOQL.
Ans :

COUNT()

  • COUNT() must be the only element in the SELECT list.
  • You can use COUNT() with a LIMIT clause.
  • You can’t use COUNT() with an ORDER BY clause. Use COUNT(fieldName) instead.
  • You can’t use COUNT() with a GROUP BY clause for API version 19.0 and later. Use COUNT(fieldName) instead.

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.

Read here in more detail about COUNT() and COUNT(fieldname)


99. How to write the “Where” clause in SOQL when GroupBy is used for aggregate functions?
Ans : We cannot use the “Where” clause with GroupBy for aggregate functions like SUM() instead we will need to use the “Having Clause“.
Example : Get all the opportunity where more than one record exists with same name and name contains “ABC”.

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

Read more about Having clause


100. Lets 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?
Ans :

On load event, write the javascript code to autofocus any other field or any other non-visible component.
Example :

<span id="focusDistraction"></span>
<script type="text/javascript">
	/* prevent autopup of the date inputfield by the default focus behavoir */
	window.onload=function() {
	document.getElementById('focusDistraction').focus();
	}
</script>

Related posts

  • puneet

    hi jitendra i want to call external mssql server databse on my visual force page and show the data hows it possible pls tell me if any example then it will be more better …plss

    • JitendraZaa

      Hi Puneet, only way to achieve this in VF is to create webservice for your MySQL using language like Java or PHP and consume in Salesforce.

  • puneet

    thanx for your advise actualy i m newer on it do you have any example with code so i can see and feel more comfort .if you have then pls send it to me my email id is 1986.puneet@gmail.com.

  • suresh

    We can use where clause with Group By..
    99 answer need to be changed

    • JitendraZaa

      Thanks Suresh for pointing out. Question updated

  • sfdc30

    Thank you very much for the 91 answer