{"id":3025,"date":"2012-08-19T14:05:45","date_gmt":"2012-08-19T08:35:45","guid":{"rendered":"http:\/\/JitendraZaa.com\/blog\/?p=3025"},"modified":"2015-02-26T04:21:40","modified_gmt":"2015-02-26T04:21:40","slug":"salesforce-interview-questions-part-11","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-interview-questions-part-11\/","title":{"rendered":"Salesforce Interview Questions \u2013 Part 11"},"content":{"rendered":"<div class=\"intrinsic-container\"><iframe loading=\"lazy\" src=\"https:\/\/jitendrazaa.com\/blog\/SFDCInterviewList.php?num=11\" width=\"300\" height=\"150\" allowfullscreen=\"allowfullscreen\"> <\/iframe><\/div>\n<p><strong>101. How to force lead assignment rule via Apex while updating or adding the Lead?<\/strong><br \/>\n<strong> Ans :<\/strong> To enforce Assignment Rules in Apex you will need to perform following steps:<\/p>\n<ol>\n<li>Instantiate the &#8220;Database.DMLOptions&#8221;\u009d class.<\/li>\n<li>Set the &#8220;useDefaultRule&#8221;\u009d property of &#8220;assignmentRuleHeader&#8221;\u009d to True.<\/li>\n<li>Finally call a native method on your Lead called &#8220;setOptions&#8221;\u009d, with the Database.DMLOptions instance as the argument.<\/li>\n<\/ol>\n<p><strong> Example:<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\/\/ to turn ON the Assignment Rules in Apex\r\nDatabase.DMLOptions dmlOptn = new Database.DMLOptions();\r\ndmlOptn.assignmentRuleHeader.useDefaultRule = true;\r\nleadObj.setOptions(dmlOptn);\r\n<\/pre>\n<hr \/>\n<p><strong>102. How to implement the pagination in SOQL ?<\/strong><\/p>\n<p><strong>Ans:<\/strong><br \/>\nIn spring 12, Salesforce has come up with ability of SOQL to get records from position &#8220;X&#8221;\u009d instead of position &#8220;1&#8221;\u009d every time to help creating pagination feature.<\/p>\n<figure id=\"attachment_3046\" aria-describedby=\"caption-attachment-3046\" style=\"width: 628px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2012\/08\/Pagination-in-SOQL-using-keyword-Offset.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-3046\" title=\"Pagination in SOQL using keyword Offset\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2012\/08\/Pagination-in-SOQL-using-keyword-Offset.png?resize=628%2C390&#038;ssl=1\" alt=\"Pagination in SOQL using keyword Offset\" width=\"628\" height=\"390\" \/><\/a><figcaption id=\"caption-attachment-3046\" class=\"wp-caption-text\">Pagination in SOQL using keyword Offset<\/figcaption><\/figure>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nSelect Id, Name from Lead LIMIT 5 OFFSET 2\r\n<\/pre>\n<p>Above query will return 5 Lead records starting from record number 10 (5&#215;2).<\/p>\n<p><a title=\"Pagination in SOQL - Salesforce\" href=\"http:\/\/blogs.developerforce.com\/developer-relations\/2012\/01\/soql-offset-in-spring-12.html\" rel=\"nofollow\">Read more here about SOQL pagination<!--more--><\/a><\/p>\n<hr \/>\n<p><strong>103. Access custom controller-defined enum in custom component ?<br \/>\nAns :<\/strong><\/p>\n<p>We cannot reference the enum directly since the enum itself is not visible to the page and you can&#8217;t make it a property.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>Apex class:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nglobal with sharing class My_Controller {\r\n  public Case currCase {get; set; }\r\n  public enum StatusValue {RED, YELLOW, GREEN}\r\n\r\n  public StatusValues getColorStatus() {\r\n    return StatusValue.RED;  \/\/demo code - just return red\r\n  }\r\n}\r\n<\/pre>\n<p>Visualforce page:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;apex:image url='stopsign.png' rendered=&quot;{!colorStatus == StatusValue.RED}&quot; \/&gt;\r\n<\/pre>\n<p>Above code snippet will throw error something like &#8220;<strong>Save Error: Unknown property <\/strong>&#8216;My_Controller.statusValue'&#8221;\u009d<\/p>\n<p><strong>Resolution:<\/strong><br \/>\nAdd below method in Apex Controller:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic String currentStatusValue { get{ return getColorStatus().name(); }}\r\n<\/pre>\n<p>and change Visualforce code to<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;apex:image url='stopsign.png' rendered=&quot;{!currentStatusValue == 'RED'}&quot; \/&gt;\r\n<\/pre>\n<p><a title=\"Enum in Visualforce\" href=\"http:\/\/salesforce.stackexchange.com\/questions\/133\/access-custom-controller-defined-enum-in-custom-component\" target=\"_blank\" rel=\"nofollow\">The same question was raised in this thread of stackExchange<\/a><\/p>\n<hr \/>\n<p><strong>104. How to generate the random string or random password using Apex?<br \/>\nAns:<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nInteger len = 10;\r\nBlob blobKey = crypto.generateAesKey(128);\r\nString key = EncodingUtil.convertToHex(blobKey);\r\nString pwd = key.substring(0,len);\r\n<\/pre>\n<hr \/>\n<p style=\"text-align: justify;\"><strong>105. What is dynamic binding in salesforce?<br \/>\nAns:<\/strong><br \/>\nDynamic Visualforce bindings are a way of writing generic Visualforce pages that display information about records without necessarily knowing which fields to show. In other words, fields on the page are determined at run time, rather than compile time. This allows a developer to design a single page that renders differently for various audiences, based on their permissions or preferences. Dynamic bindings are useful for Visualforce pages included in managed packages since they allow for the presentation of data specific to each subscriber with very little coding.<\/p>\n<p><strong>Example 1: <\/strong><br \/>\nAccess the Account name from Contact.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n{!myContact&#x5B;'Account']&#x5B;fieldname]}\r\n<\/pre>\n<p><strong>Example 2:<\/strong><\/p>\n<p>Consider Data type in Apex<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic Map&lt;String, List&lt;Account&gt;&gt; accountsMap {get; set;}\r\n<\/pre>\n<p>Visualforce page:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;apex:variable value=&quot;A&quot; var=&quot;selectedKey&quot; \/&gt;\r\n&lt;apex:pageBlockTable value=&quot;{!accountsMap&#x5B;selectedKey]}&quot; var=&quot;acc&quot;&gt;\r\n   &lt;apex:column value=&quot;{!acc.name}&quot;\/&gt;\r\n   &lt;apex:column value=&quot;{!acc.BillingStreet}&quot;\/&gt;\r\n   &lt;apex:column value=&quot;{!acc.BillingCity}&quot;\/&gt;\r\n   &lt;apex:column value=&quot;{!acc.BillingPostalCode}&quot;\/&gt;\r\n&lt;\/apex:pageBlockTable&gt;\r\n<\/pre>\n<p><a title=\"Dynamic binding in Visualforce - Salesforce\" href=\"http:\/\/bobbuzzard.blogspot.in\/2011\/03\/visualforce-dynamic-map-bindings.html\" rel=\"nofollow\">Read more about Visualforce dynamic binding on bob buzzard&#8217;s blog<\/a><\/p>\n<hr \/>\n<p><strong>106. How to convert lead using Apex?<br \/>\nAns:<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nLead myLead = new Lead(LastName = 'Foo', Company='Foo Bar');\r\ninsert myLead;\r\n\r\nDatabase.LeadConvert lc = new database.LeadConvert();\r\nlc.setLeadId(myLead.id);\r\n\r\nLeadStatus convertStatus = &#x5B;SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];\r\nlc.setConvertedStatus(convertStatus.MasterLabel);\r\n\r\nDatabase.LeadConvertResult lcr = Database.convertLead(lc);\r\nSystem.assert(lcr.isSuccess());\r\n<\/pre>\n<hr \/>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\"><strong>108. How can you determine that email is actually sent or not from the salesforce?<br \/>\nAns:<\/strong><br \/>\nThere is an Email log that you could use. It&#8217;s available in the setup menu under Monitoring.<\/p>\n<p style=\"text-align: justify;\">It&#8217;s only for the past 30 days and you would have to manually check it.<\/p>\n<p style=\"text-align: justify;\">From the email log page: &#8220;Email logs describe all emails sent through salesforce.com and can be used to help identify the status of an email delivery. Email logs are CSV files that provide information such as the email address of each email sender and its recipient, the date and time each email was sent, and any error code associated with each email. Logs are only available for the past 30 days.&#8221;<\/p>\n<hr \/>\n<p><strong>109. In salesforce which fields are indexed automatically?<br \/>\nAns : <\/strong><br \/>\nThe following fields are indexed by default:<\/p>\n<ul>\n<li>primary keys (Id, Name and Owner fields),<\/li>\n<li>foreign keys (lookup or master-detail relationship fields),<\/li>\n<li>audit dates (such as LastModifiedDate),<\/li>\n<li>Custom fields marked as External ID or Unique.<\/li>\n<\/ul>\n<p><a title=\"Salesforce indexing\" href=\"http:\/\/www.salesforce.com\/us\/developer\/docs\/apexcode\/Content\/langCon_apex_SOQL_VLSQ.htm\" rel=\"nofollow\">Read more on indexing from Salesforce Documentation<\/a><\/p>\n<hr \/>\n<p><strong>110 : Give any scenario when you cannot change the currency field type to numeric type.<br \/>\nAns :<\/strong> When the field is used either in Apex class or trigger.<\/p>\n<div class=\"intrinsic-container\"><iframe loading=\"lazy\" src=\"https:\/\/jitendrazaa.com\/blog\/SFDCInterviewList.php?num=11\" width=\"300\" height=\"150\" allowfullscreen=\"allowfullscreen\"> <\/iframe><\/div>\n","protected":false},"excerpt":{"rendered":"<p>101. How to force lead assignment rule via Apex while updating or adding the Lead? Ans : To enforce Assignment Rules in Apex you will need to perform following steps: Instantiate the &#8220;Database.DMLOptions&#8221;\u009d class. Set the &#8220;useDefaultRule&#8221;\u009d property of &#8220;assignmentRuleHeader&#8221;\u009d to True. Finally call a native method on your Lead called &#8220;setOptions&#8221;\u009d, with the Database.DMLOptions [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[9],"tags":[124,139,331],"class_list":["post-3025","post","type-post","status-publish","format-standard","hentry","category-salesforce","tag-interview-questions","tag-lead","tag-salesforce"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":1305,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-interview-questions-part-3\/","url_meta":{"origin":3025,"position":0},"title":"Salesforce Interview Questions \u2013 Part 3","author":"Jitendra","date":"October 12, 2010","format":false,"excerpt":"Most Frequently Asked interview questions of Apex, Visual force, SOQL in Salesforce.com SFDC","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3325,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/apex-visualforce-data-loader-and-soql-interview-question-part-17\/","url_meta":{"origin":3025,"position":1},"title":"Apex, Visualforce, Data Loader and SOQL Interview Question \u2013 Part 17","author":"Jitendra","date":"October 10, 2013","format":false,"excerpt":"161 : Sometimes while deleting record it gives error \"Object cannot be Deleted\". What is the reason for this kind of error ? Ans : This is generic error message prompted by Salesforce many times, which is not well informative. To get informative message, we can try to delete same\u2026","rel":"","context":"In &quot;Apex&quot;","block_context":{"text":"Apex","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/apex\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2501,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/very-useful-tips-and-tricks-of-the-apex-salesforce-interview-questions-part-4\/","url_meta":{"origin":3025,"position":2},"title":"Latest Salesforce Interview Questions &#8211; Part 4 &#8211; Related to Dynamic Apex","author":"Jitendra","date":"November 27, 2011","format":false,"excerpt":"Most Frequently Asked interview questions of Apex, Dynamic Apex, SOSL, Visualforce, SOQL in Salesforce.com SFDC","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2681,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-interview-questions-part-5\/","url_meta":{"origin":3025,"position":3},"title":"Salesforce Interview Questions &#8211; Part 5","author":"Jitendra","date":"January 24, 2012","format":false,"excerpt":"Basic concepts and Interview Questions of salesforce, Visualforce, Apex and SOQL","rel":"","context":"In &quot;Apex&quot;","block_context":{"text":"Apex","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/apex\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3042,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-interview-question-part-12\/","url_meta":{"origin":3025,"position":4},"title":"Salesforce Interview Question &#8211; Part 12","author":"Jitendra","date":"September 13, 2012","format":false,"excerpt":"111 : How to get the Recordtype Id using Dynamic Apex? Ans: Normally to get the RecordtypeId for any sObject we use SOQL and it will count against your limit. So below method will bypass the need of SOQL Query. [java] Map<String, Schema.SObjectType> m = Schema.getGlobalDescribe() ; Schema.SObjectType s =\u2026","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3411,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/apex-interview-question-salesforce-part-16\/","url_meta":{"origin":3025,"position":5},"title":"Apex Interview Question \u2013 Salesforce &#8211; Part 16","author":"Jitendra","date":"July 28, 2013","format":false,"excerpt":"151. Give Sample Code Snippet of Apex that that will show that how Parent and Child record can be inserted in Single Statement ? Ans : It can be done with help of External Id. [java] Date dt = Date.today().addDays(7); Opportunity newOpportunity = new Opportunity(Name = 'shivasoft', StageName = 'Prospecting',\u2026","rel":"","context":"In &quot;Apex&quot;","block_context":{"text":"Apex","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/apex\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/3025","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=3025"}],"version-history":[{"count":4,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/3025\/revisions"}],"predecessor-version":[{"id":4273,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/3025\/revisions\/4273"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=3025"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=3025"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=3025"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}