{"id":2835,"date":"2012-05-03T11:40:49","date_gmt":"2012-05-03T06:10:49","guid":{"rendered":"http:\/\/JitendraZaa.com\/blog\/?p=2835"},"modified":"2012-05-03T11:40:49","modified_gmt":"2012-05-03T06:10:49","slug":"salesforce-apex-code-talk-important-questions-and-answers","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-apex-code-talk-important-questions-and-answers\/","title":{"rendered":"Salesforce Apex Code talk &#8211; Important Questions and Answers"},"content":{"rendered":"<p>Hello everyone,<br \/>\nOn 24th April 2012, There was Apex code chat conducted by the Salesforce. So i thought to share important question and answers of that chat. <a title=\"Salesforce Chat\" href=\"http:\/\/wiki.developerforce.com\/page\/CodeTalk:_Apex_(2012-Apr)\" rel=\"nofollow\">You can read complete chat here<\/a>.<\/p>\n<hr \/>\n<p>Here are some of the (edited) highlights from this episode&#8217;s chat transcript.<\/p>\n<p><strong>Question:<\/strong> Is there a way in Apex to send an email and replace the default from email address (no-reply@salesforce.com)?<br \/>\n<strong>Ans:<\/strong> Yes, using either the setSenderDisplayName or setOrgWideEmailAddressID methods on the SingleEmailMessage or MassEmailMessage classes.<\/p>\n<hr \/>\n<p><strong>Question:<\/strong>\u00a0Which fields are accessible in a Trigger.new record without performing a SOQL query? For example if my trigger is on the Contact object, are fields on the parent Account object (like Account Description) accessible without performing an explicit SOQL query?<br \/>\n<strong>Ans:<\/strong>\u00a0You can use Trigger.new to access all non-null fields of the object on which the trigger is defined. You have to perform an explicit SOQL query to access any fields on associated parent or child records. For example, if the trigger is defined on Contact, you can only access the Id of the parent Account record (via AccountId) in Trigger.new. You&#8217;d need to perform a separate SOQL query to access any other field on the parent Acccount record (e.g. Description, Industry etc.).<!--more--><\/p>\n<hr \/>\n<p><strong>Question:<\/strong>\u00a0Does Apex support JavaDoc style documentation?<br \/>\n<strong>Ans:<\/strong>Apex does not natively support generating JavaDoc style documentation. However, the Force.com developer community has created an open-source tool to support this. <a title=\"Salesforce JavaDoc Style\" href=\"http:\/\/techsahre.blogspot.com\/2011\/01\/apexdoc-salesforce-code-documentation.html\" rel=\"nofollow\">More details can be found here<\/a>.<\/p>\n<hr \/>\n<p><strong>Question:<\/strong>\u00a0Is there any advantage to having just one &#8220;master&#8221; trigger per object, or should we have separate triggers for each functional requirement?<br \/>\n<strong>Ans:<\/strong>There is no hard or fast rule in the one vs many triggers per object debate. A lot depends on the specific use case and how you prefer to organize your code. Having a single &#8216;master&#8217; trigger per object can help enforce order of code execution. Having all code in a single trigger can also be an appealing way to organize code. However, having separate triggers enforce different business requirements may increase code maintainability for some.<\/p>\n<hr \/>\n<p><strong>Question:<\/strong>\u00a0How can I return random records in a SOQL query (e.g for testing purposes)?<br \/>\n<strong>Ans:<\/strong>\u00a0The easy option would be to perform a SOQL query without a WITH or ORDER BY clause. A more advanced option would be to use a combination of SOQL OFFSET and Math.random() as described<a title=\"StackOverflow Thread\" href=\"http:\/\/stackoverflow.com\/questions\/4408814\/how-do-i-request-a-single-random-row-from-a-force-com-database-in-soql\/10302018#10302018\" rel=\"nofollow\"> in this Stackoverflow thread<\/a>.<\/p>\n<hr \/>\n<p><strong>Question:<\/strong>\u00a0\u00a0Can we use Facebook credentials to log into a Customer Portal?<br \/>\n<strong>Ans:<\/strong>Yes &#8211; using the new Authentication Providers feature in Spring &#8217;12. For more details, <a title=\"Webinar Video\" href=\"http:\/\/wiki.developerforce.com\/page\/Webinar:Social_Sign-On_with_Authentication_Providers_(2012-Apr)\" rel=\"nofollow\">check out this webinar recording<\/a>.<\/p>\n<hr \/>\n<p><strong>Question:<\/strong>\u00a0\u00a0Can we integrate Google Calender with the Salesforce Calender?<br \/>\n<strong>Ans:<\/strong>You can use<a title=\"Google Toolkit\" href=\"http:\/\/code.google.com\/p\/apex-google-data\/\" rel=\"nofollow\"> this Google Data toolkit<\/a> to implement a custom integration between Google Calendar and Salesforce.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Salesforce Apex Code talk on &#8211; 24-April-2012 , Important Interview Questions<\/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":[20,24,9,18],"tags":[331],"class_list":["post-2835","post","type-post","status-publish","format-standard","hentry","category-apex","category-force-com","category-salesforce","category-visualforce","tag-salesforce"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":3278,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/visualforce\/using-fieldset-with-visualforce-and-apex\/","url_meta":{"origin":2835,"position":0},"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":3042,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-interview-question-part-12\/","url_meta":{"origin":2835,"position":1},"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. or 112 : Write Apex code which will take the\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":3325,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/apex-visualforce-data-loader-and-soql-interview-question-part-17\/","url_meta":{"origin":2835,"position":2},"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":2835,"position":3},"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":3598,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/listview-filter-in-apex-with-paging-and-navigation\/","url_meta":{"origin":2835,"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":3025,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-interview-questions-part-11\/","url_meta":{"origin":2835,"position":5},"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":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/2835","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=2835"}],"version-history":[{"count":0,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/2835\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=2835"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=2835"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=2835"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}