{"id":3042,"date":"2012-09-13T13:29:24","date_gmt":"2012-09-13T07:59:24","guid":{"rendered":"http:\/\/JitendraZaa.com\/blog\/?p=3042"},"modified":"2015-12-04T17:48:39","modified_gmt":"2015-12-04T17:48:39","slug":"salesforce-interview-question-part-12","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-interview-question-part-12\/","title":{"rendered":"Salesforce Interview Question &#8211; Part 12"},"content":{"rendered":"<div class=\"intrinsic-container\"><iframe loading=\"lazy\" src=\"https:\/\/jitendrazaa.com\/blog\/SFDCInterviewList.php?num=12\" width=\"300\" height=\"150\" allowfullscreen=\"allowfullscreen\"> <\/iframe><\/div>\n<p><strong>111 : How to get the Recordtype Id using Dynamic Apex?<\/strong><br \/>\n<strong>Ans:<\/strong><br \/>\nNormally 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.<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nMap&lt;String, Schema.SObjectType&gt; m  = Schema.getGlobalDescribe() ;\r\nSchema.SObjectType s = m.get('API_Name_Of_SObject') ;\r\nSchema.DescribeSObjectResult cfrSchema = s.getDescribe() ;\r\nMap&lt;String,Schema.RecordTypeInfo&gt; RecordTypeInfo = cfrSchema.getRecordTypeInfosByName();\r\nId rtId = RecordTypeInfo.get('Record Type Name').getRecordTypeId();\r\n<\/pre>\n<p>or<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nSchema.SObjectType.Object_API_Name__c.getRecordTypeInfosByName().get('recordtype name').getRecordTypeId()\r\n<\/pre>\n<hr \/>\n<p><strong>112 : Write Apex code which will take the RecordID as input and on the basis of that it will print the Object name and field names of sObject.<\/strong><br \/>\n<strong> Ans:<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nList&lt;Schema.SObjectType&gt; gd = Schema.getGlobalDescribe().Values();\r\nMap&lt;String,String&gt; objectMap = new Map&lt;String,String&gt;();\r\nfor(Schema.SObjectType f : gd)\r\n{\r\n     objectMap.put(f.getDescribe().getKeyPrefix(), f.getDescribe().getName());\r\n}\r\n\r\nString sampleId ='00390000003LIVw';\r\nString prefix =  sampleId.substring(0,3);\r\nString objectName = objectMap.get(prefix);\r\nSystem.debug('** SObject Name ** '+objectName);\r\n\r\nMap&lt;String, Schema.SObjectField&gt; desResult = Schema.getGlobalDescribe().get(objectName).getDescribe().Fields.getMap();\r\nList&lt;String&gt; fieldList = new List&lt;String&gt;();\r\nfieldList.addAll(desResult.keySet());\r\nfor(integer i =0;i&lt;fieldList.size();i++)\r\n{\r\n    System.debug('** Field Name ** '+fieldList&#x5B;i]);\r\n}\r\n<\/pre>\n<hr \/>\n<p><strong>113. Consider a scenario where you have created a Visualforce page and Controller. You want to restrict the controller action for users which are logged in using &#8220;Grant Login Access&#8221;. How to acheive this?<\/strong><\/p>\n<p><strong>Ans:<\/strong><\/p>\n<p>When System admin logged in on the behalf of any other user. On upper right corner message is displayed that user is logged-in on behalf of some other user. In Visualforce page we can search for the element with class name present or not? If the element with that Class name exist means logged-in user is not a actual user.<\/p>\n<hr \/>\n<p><strong>114. How to get &#8220;https&#8221; link instead of &#8220;http&#8221; for Visualforce page using URLFOR() in Email Template ?<\/strong><br \/>\n<strong> Ans:<\/strong> When you create the Link using URLFOR() in Email Template, it creates link in &#8220;http&#8221; format instead of &#8220;https&#8221; and thus causes end user to logged into salesforce again.<\/p>\n<p>So instead of<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;a href='{!URLFOR('\/apex\/SomePage', null, &#x5B;id=Some_Object__c.Id,retURL=&quot;\/apex\/SomeOtherPage&quot;])}'&gt;Go to SomePage here!&lt;\/a&gt;\r\n<\/pre>\n<p>We can use something like :<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;a href='{!SUBSTITUTE(URLFOR('\/apex\/SomePage', null, &#x5B;id=Some_Object__c.Id,retURL=&quot;\/apex\/SomeOtherPage&quot;]),'http:','https:')}'&gt;Go to SomePage here!&lt;\/a&gt;\r\n<\/pre>\n<hr \/>\n<p><!--more--><br \/>\n<strong>115. What is the best way to check whether organization have PersonAccount enable or not using Apex?<\/strong><br \/>\n<strong> Ans:<\/strong><\/p>\n<p><strong>Method 1:<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\/\/ Test to see if person accounts are enabled.\r\npublic Boolean personAccountsEnabled()\r\n{\r\n    try\r\n    {\r\n        \/\/ Try to use the isPersonAccount field.\r\n        sObject testObject = new Account();\r\n        testObject.get( 'isPersonAccount' );\r\n        \/\/ If we got here without an exception, return true.\r\n        return true;\r\n    }\r\n    catch( Exception ex )\r\n    {\r\n        \/\/ An exception was generated trying to access the isPersonAccount field\r\n        \/\/ so person accounts aren't enabled; return false.\r\n        return false;\r\n    }\r\n}\r\n<\/pre>\n<p><strong>Method 2:<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\/\/ Check to see if person accounts are enabled.\r\npublic Boolean personAccountsEnabled()\r\n{\r\n    \/\/ Describe the Account object to get a map of all fields\r\n    \/\/ then check to see if the map contains the field 'isPersonAccount'\r\n    return Schema.sObjectType.Account.fields.getMap().containsKey( 'isPersonAccount' );\r\n}\r\n<\/pre>\n<hr \/>\n<p><strong>116 : When you get the error &#8220;Non-selective query against large object type&#8221;? how to resolve it?<\/strong><br \/>\n<strong> Ans :<\/strong> Whenever an object has greater than 100K records any query on that object must be &#8220;selective&#8221;. For a query to be selective it must have enough indexed filters (where clauses) so that less than 10% of the records (in our example 10K) are returned before applying the limit statement.<\/p>\n<hr \/>\n<p><strong>117 : How to get the debug log of Connection user in salesforce to salesforce Integration?<\/strong><br \/>\n<strong> Ans :<\/strong> When configuring Debug Logs, you cannot choose a Salesforce to Salesforce Connection User from the User Lookup, but there is a workaround to<\/p>\n<p>achieve this.<\/p>\n<p>To begin capturing Debug Logs for a Connection User open the following URL in your browser:<\/p>\n<blockquote><p>https:\/\/XXX.salesforce.com\/p\/setup\/layout\/AddApexDebugLogUser?retURL=%2Fsetup%2Fui%2FlistApexTraces.apexp&amp;UserLookupInput_lkid=YYYYYYYYYYYYYY<br \/>\n&amp;UserLookupInput=Connection%20User<\/p><\/blockquote>\n<p>Replace XXX with your salesforce instance, UserLookupInput_lkid is the ID of the Connection User and UserLookupInput is the User name. You can find<\/p>\n<p>the user ID of the connection user, by inspecting the CreatedById for a record created by this user. (eg. via eclipse or Force.com explorer)<\/p>\n<p>Courtesy : <a title=\"Debug log for Salesforce to Salesforce\" href=\"http:\/\/screenfields.nl\/blog\/2012\/08\/09\/debugging-salesforce-2-salesforce\/\" rel=\"nofollow\">http:\/\/screenfields.nl\/blog\/2012\/08\/09\/debugging-salesforce-2-salesforce\/<\/a><\/p>\n<hr \/>\n<p><strong>118 : In Controller extension, you are getting the error &#8220;SObject row was retrieved via SOQL without querying the requested field&#8221; while accessing the field of parent Custom Object or standard Object for which the Controller extension was written. How to resolve that?<\/strong><br \/>\n<strong> Ans :<\/strong> In Constructor of the Controller extension, only Id of Custom Object is supplied. We need to query all the required field explicitly in order to use in remaining part of the code.<\/p>\n<hr \/>\n<p><strong>119: Using Apex how you can determine that user is in Sandbox or production?<\/strong><br \/>\n<strong> Ans :<\/strong> <a title=\"Determine that user is in production or sandbox using Apex in Salesforce\" href=\"http:\/\/www.michaelforce.org\/recipeView?id=a0Ga000000Ekp65EAB\" rel=\"nofollow\">read this URL for answer<\/a><\/p>\n<hr \/>\n<p><strong>120: Can you use aggregate expressions inside inner query?<br \/>\nExplanation &#8211; Can you use Group by clause inside inner query in SOQL?<br \/>\nExample : Something like :<\/strong><\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\n SELECT Id, Name,(SELECT Count(Id),Name FROM Contacts Group By Name Having count(Id) &gt; 1 ) FROM Account\r\n<\/pre>\n<p><strong>Ans: <\/strong>\u00a0No. only root queries support aggregate expressions. Return type is List&lt;AggregateResult&gt; for above\u00a0query However the root result expects List&lt;Account&gt; and there is no syntax or provision available in Salesforce to specify that child results are of type &#8220;<strong>AggregateResult<\/strong>&#8220;.<\/p>\n<div class=\"intrinsic-container\"><iframe loading=\"lazy\" src=\"https:\/\/jitendrazaa.com\/blog\/SFDCInterviewList.php?num=12\" width=\"300\" height=\"150\" allowfullscreen=\"allowfullscreen\"> <\/iframe><\/div>\n","protected":false},"excerpt":{"rendered":"<p>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. Map&lt;String, Schema.SObjectType&gt; m = Schema.getGlobalDescribe() ; Schema.SObjectType s = m.get(&#8216;API_Name_Of_SObject&#8217;) ; Schema.DescribeSObjectResult cfrSchema = s.getDescribe() [&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_post_was_ever_published":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":""},"categories":[9],"tags":[337,331,336],"class_list":["post-3042","post","type-post","status-publish","format-standard","hentry","category-salesforce","tag-apex","tag-salesforce","tag-visualforce"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"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":3042,"position":0},"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":3278,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/visualforce\/using-fieldset-with-visualforce-and-apex\/","url_meta":{"origin":3042,"position":1},"title":"Using FieldSet with Visualforce and Apex","author":"Jitendra","date":"May 3, 2013","format":false,"excerpt":"One of the disadvantages comes up with Custom Page or Overriding New or Edit button with Visualforce page is its \"Maintenance\"\u009d, if New Filed is Added or needed to remove field we have to modify our code every time. However, Thanks to Salesforce that we have \"Field Set\"\u009d. With the\u2026","rel":"","context":"In &quot;Apex&quot;","block_context":{"text":"Apex","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/apex\/"},"img":{"alt_text":"Create Field Set in Salesforce","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/05\/Create-Field-Set-in-Salesforce.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/05\/Create-Field-Set-in-Salesforce.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/05\/Create-Field-Set-in-Salesforce.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":3025,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-interview-questions-part-11\/","url_meta":{"origin":3042,"position":2},"title":"Salesforce Interview Questions \u2013 Part 11","author":"Jitendra","date":"August 19, 2012","format":false,"excerpt":"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 \"Database.DMLOptions\"\u009d class. Set the \"useDefaultRule\"\u009d property of \"assignmentRuleHeader\"\u009d to True. Finally call a native method on your Lead\u2026","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"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=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2012\/08\/Pagination-in-SOQL-using-keyword-Offset.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2012\/08\/Pagination-in-SOQL-using-keyword-Offset.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":2797,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/creating-trigger-on-attachment-in-salesforce\/","url_meta":{"origin":3042,"position":3},"title":"Creating Trigger on Attachment in Salesforce","author":"Jitendra","date":"March 28, 2012","format":false,"excerpt":"Example and tutorial on creating the trigger for attachment in salesforce which will not allow to upload the file in opportunity if file contains some predefined text","rel":"","context":"In &quot;Apex&quot;","block_context":{"text":"Apex","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/apex\/"},"img":{"alt_text":"Before insert Trigger on Attachment using eclipse in Salesforce","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2012\/03\/Before-insert-Trigger-on-Attachment-Salesforce.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2012\/03\/Before-insert-Trigger-on-Attachment-Salesforce.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2012\/03\/Before-insert-Trigger-on-Attachment-Salesforce.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":3598,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/listview-filter-in-apex-with-paging-and-navigation\/","url_meta":{"origin":3042,"position":4},"title":"How to access ListView in Apex | Using StandardSetController for Pagination","author":"Jitendra","date":"November 8, 2013","format":false,"excerpt":"There are scenario in project lifecycle where developer creates SOQL or Dynamic SOQL to return expected result. Also if requirement changes they go back and change existing code to reflect updated SOQL. If you are good developer and avoid to change Apex code at most you will save your SOQL\u2026","rel":"","context":"In &quot;Apex&quot;","block_context":{"text":"Apex","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/apex\/"},"img":{"alt_text":"Use ListView in Visualforce with Paging and Navigation","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/11\/Use-ListView-in-Visualforce-with-Paging-and-Navigation.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/11\/Use-ListView-in-Visualforce-with-Paging-and-Navigation.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/11\/Use-ListView-in-Visualforce-with-Paging-and-Navigation.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":3773,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-faq-part-19\/","url_meta":{"origin":3042,"position":5},"title":"Salesforce interview questions &#8211; Part 19","author":"Jitendra","date":"December 16, 2014","format":false,"excerpt":"Salesforce interview questions for developers and admins around Apex, Visualforce, getting Salesforce object name on basis of Id, Apex API limits","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\/3042","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=3042"}],"version-history":[{"count":5,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/3042\/revisions"}],"predecessor-version":[{"id":5069,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/3042\/revisions\/5069"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=3042"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=3042"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=3042"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}