{"id":3325,"date":"2013-10-10T06:15:04","date_gmt":"2013-10-10T00:45:04","guid":{"rendered":"http:\/\/JitendraZaa.com\/blog\/?p=3325"},"modified":"2015-02-09T01:36:18","modified_gmt":"2015-02-09T01:36:18","slug":"apex-visualforce-data-loader-and-soql-interview-question-part-17","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/apex-visualforce-data-loader-and-soql-interview-question-part-17\/","title":{"rendered":"Apex, Visualforce, Data Loader and SOQL Interview Question \u2013 Part 17"},"content":{"rendered":"<div class=\"intrinsic-container\"><iframe loading=\"lazy\" src=\"https:\/\/jitendrazaa.com\/blog\/SFDCInterviewList.php?num=17\" width=\"300\" height=\"150\" allowfullscreen=\"allowfullscreen\"> <\/iframe><\/div>\n<p style=\"text-align: justify;\"><strong>161 : Sometimes while deleting record it gives error &#8220;Object cannot be Deleted&#8221;. What is the reason for this kind of error ?<\/strong><br \/>\n<strong> Ans :<\/strong><br \/>\nThis is generic error message prompted by Salesforce many times, which is not well informative. To get informative message, we can try to delete same record in <strong>&#8220;Developer Console&#8221;<\/strong>. In Developer Console Debug log, we will get exact error message.<br \/>\n<strong>Example :<\/strong> Lets say there is one record which is parent of more than 2000 records and grand parent of 5000 records. In such scenario from developer console it gives error something like <span style=\"text-decoration: underline;\">&#8220;record cannot be deleted because it has many associated objects&#8221;<\/span> However in User Interface, it will just display that <span style=\"text-decoration: underline;\">&#8220;Object cannot be deleted.<\/span>&#8220;<\/p>\n<hr \/>\n<p style=\"text-align: justify;\"><strong>162 : Why are Visualforce pages served from a different domain?<\/strong><br \/>\n<strong> Ans :<\/strong><br \/>\nIf we see carefully, all our Visualforce pages are served like &#8220;c.YOURSERVER.visual.force.com\/apex\/YOURPAGENAME&#8221; ,<br \/>\nAnd because of this most of time we run into <span style=\"text-decoration: underline;\">Same-Origin Policy error<\/span> in Javascripyt if we try to access parent page from Iframe. Following reason is explained by one of the evangelist of Salesforce:<\/p>\n<p style=\"text-align: justify;\">&#8220;The move to separate domains has one very specific purpose: leverage the browser security model (same domain policy) to protect our customers and the salesforce.com service from cross site scripting and cross site request forgery attacks.<\/p>\n<p style=\"text-align: justify;\">Moving to the serving pages from separate domains is a critical component of our ongoing commitment to insure the highest level of security and availability for everyone.<\/p>\n<p style=\"text-align: justify;\">In the world where everything is served from the same domain any custom page that you visit had full access to any other page in your org and also any page served from salesforce.com itself. This included potentially malicious code that was installed as part of a force.com package.&#8221;<!--more--><\/p>\n<hr \/>\n<p><strong>163 : In below code snippet , What is your observation and what is going wrong ?<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\ntrigger TestBeforeDelete on Lead (before Delete) {\r\n\r\n        for(Lead l : Trigger.Old)\r\n        {\r\n            l.addError('error');\r\n        }\r\n\r\n        String msgBody = 'Test Email';\r\n        String Subject = 'Test from Cogni Force on Lead';\r\n        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();\r\n        String&#x5B;] toAddresses = new String&#x5B;] {'abc@gmail.com'};\r\n        mail.setToAddresses(toAddresses);\r\n        mail.setReplyTo('abc@gmail.com');\r\n        mail.setSenderDisplayName('Cogniforce Test Simulator');\r\n        mail.setSubject(Subject);\r\n        mail.setPlainTextBody(msgBody);\r\n        mail.setHTMLBody(msgBody);\r\n        Messaging.sendEmail(new Messaging.SingleEmailMessage&#x5B;] { mail });\r\n}\r\n<\/pre>\n<p><strong>Ans :<\/strong><br \/>\nIt will not send any email. Because &#8220;adderror&#8221; prevents all transactions from committing including emails.<\/p>\n<hr \/>\n<p><strong>164. Can we mass delete reports using Apex (Anonymous Apex) ?<\/strong><br \/>\n<strong> Ans :<\/strong><br \/>\nSalesforce has not exposed any API for Reports. So best way is :<\/p>\n<ol>\n<li>Move all reports needs to delete in new folder.<\/li>\n<li>Inform everyone that reports will be deleted after some time may be 30 days.<\/li>\n<li>Import your reports folder in Eclipse including all reports to be deleted and then delete the the reports folder in eclipse. It will delete all the reports at once.<\/li>\n<\/ol>\n<hr \/>\n<p><strong>165. While creating Dynamic SOQL, which involves Datetime gives &#8221; no viable alternative at character &#8216;&lt;EOF&gt;&#8217; &#8221; error.<br \/>\nOR<br \/>\nvalue of filter criterion for field &#8216;CreatedDate&#8217; must be of type dateTime and should not be enclosed in quotes<br \/>\nOR<br \/>\nHow to use Datetime in Dynamic SOQL Query in Salesforce ?<br \/>\n<\/strong><br \/>\n<strong> Ans :<\/strong><br \/>\nThis error is because of wrong construction of Dynamic Query with Datetime. following code snippet will give idea on how to construct dynamic query for Datetime ?<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\/\/format the datetime to make it Dynamic Soql ready\r\nString formatedDt = cutOffDateTime.format('yyyy-MM-dd'T'HH:mm:ss'Z'');\r\nString sql = 'SELECT  a.Id  FROM  Agents_Answer__c a    WHERE  a.Agents_Test_Result__r.Agent_Name__r.IsActive__c = false AND  LastModifiedDate &lt; '+ formatedDt ;\r\n<\/pre>\n<p>Where, &#8220;cutOffDateTime&#8221; is variable of datetime type.<\/p>\n<hr \/>\n<p><strong>166. How you can use Datetime field as a criteria in SOQL Query ?<br \/>\nAns : <\/strong><br \/>\nWe cannot use Datetime as condition in Where Clause in between single Quotes.<br \/>\nYou can do something like this ,<\/p>\n<blockquote><p>WHERE CreatedDate &gt; 2005-10-08T00:00:00Z<\/p><\/blockquote>\n<p>Or, you can also use Date Literals like<\/p>\n<blockquote><p>WHERE CreatedDate &gt; YESTERDAY<\/p><\/blockquote>\n<p><a title=\"Salesforce SOQL Date time Literal\" href=\"http:\/\/www.salesforce.com\/us\/developer\/docs\/soql_sosl\/Content\/sforce_api_calls_soql_select_dateformats.htm\" target=\"_blank\">For more information on date formats and more literal values, check this URL.<\/a><\/p>\n<hr \/>\n<p style=\"text-align: justify;\"><strong>167. After Data Export using DataLoader, Some time it appears that data is on New Line (Carriage Return) when we open CSV file in Microsoft Excel. For example , Address Data separated on different lines. How can we override this problem ?<\/strong><br \/>\n<strong> Ans<\/strong> :<br \/>\nExcel does all sorts of &#8220;useful&#8221; things when it opens a CSV file. It will re-format dates, strip leading zeros, corrupt record IDs (if you have them in your report), and as explained it will also break line. Best way as per my experience till date is, <strong>Upload document to Google Drive<\/strong>. Export document back from Google drive as Excel.<\/p>\n<p style=\"text-align: justify;\">Please post comment in this article if you know any other working way.<\/p>\n<hr \/>\n<p style=\"text-align: justify;\"><strong>168. How do you import Converted Lead into Salesforce from Legacy System ?<\/strong><br \/>\n<strong> Ans :<\/strong><br \/>\nFields we need for importing converted leads are &#8220;<strong>ISCONVERTED<\/strong>&#8221; , &#8220;<strong>CONVERTEDCONTACTID<\/strong>&#8221; , &#8220;<strong>CONVERTEDOPPORTUNITYID<\/strong>&#8221; and &#8220;<strong>CONVERTEDACCOUNTID<\/strong>&#8220;.<br \/>\n<strong>Step 1 :<\/strong> As above fields are not editable, we have to contact Salesforce Support to enable Audit fields. Enabling Audit fields means we can edit few Readonly fields like created date and above lead fields.<br \/>\n<strong>Step 2 :<\/strong> Import Account, Contact and Opportunity from Legacy system to Salesforce.<br \/>\n<strong>Step 3 :<\/strong> If you imported account, contact and opportunity in Step 2, Salesforce automatically generates Unique ID. We need that unique Id to insert Converted Lead. So Export Account, Contact and Opportunity, which is inserted in Step 2 from legacy System.<br \/>\n<strong>Step 4 :<\/strong> Create CSV File with All lead information with ISCONVERTED=TRUE and CONVERTEDCONTACTID, CONVERTEDOPPORTUNITYID, CONVERTEDACCOUNTID. CONVERTEDCONTACTID, CONVERTEDOPPORTUNITYID and CONVERTEDACCOUNTID\u00a0should correspond to Ids generated by Salesforce for Contact, Opportunity and Account which will be related to converted lead.<br \/>\n<strong>Step 5 :<\/strong>\u00a0Once CSV is properly created with all required Data, Insert it using DataLoader.<\/p>\n<p style=\"text-align: justify;\"><strong>Note :<\/strong> We cannot convert existing lead using this process. Leads must be inserted with these four fields. If you try to update lead it will not give you option to edit above fields.<\/p>\n<hr \/>\n<p><strong>169. How to setup Field Level Security (FLS) for Person Account Fields.<\/strong><br \/>\n<strong> OR<\/strong><br \/>\n<strong> Why I am not able to find list of Person Account fields in Field Level Security (FLS) settings when navigated to fields on Account Object.<\/strong><br \/>\n<strong> Ans :<\/strong><\/p>\n<p style=\"text-align: justify;\">Field Level Security (FLS) of Person Account fields ar controlled by Contact Fields. So, if you want to setup FLS of Person Account Fields navigate to fields of Contact and it will be reflected on Person Account.<\/p>\n<hr \/>\n<p style=\"text-align: justify;\"><strong>170. In Partner Community, external user is having appropriate OWD and Profile Settings for Opportunity or consider any other Object. However they are getting insufficient\u00a0privilege\u00a0access, what might be cause of this error ?<\/strong><br \/>\n<strong> Ans :<\/strong><\/p>\n<ul>\n<li style=\"text-align: justify;\">Check External User has all FLS for fields used in Report Filters<\/li>\n<li style=\"text-align: justify;\">After Winter 14, If Community enabled, there will be two kind of OWD. External and Internal means what information should be visible to internal and external users. Also , there will be new setting named &#8220;<strong>Standard Report Visibility<\/strong>&#8220;. If it is checked user can see reports based on Standard report type even though they don&#8217;t have proper OWD and may expose sensitive information about internal user to external users (for example : Internal users role). If external user is getting an error whole running the report this setting may be one of the cause.<\/li>\n<\/ul>\n<div class=\"intrinsic-container\"><iframe loading=\"lazy\" src=\"https:\/\/jitendrazaa.com\/blog\/SFDCInterviewList.php?num=17\" width=\"300\" height=\"150\" allowfullscreen=\"allowfullscreen\"> <\/iframe><\/div>\n","protected":false},"excerpt":{"rendered":"<p>161 : Sometimes while deleting record it gives error &#8220;Object cannot be Deleted&#8221;. 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 record in &#8220;Developer Console&#8221;. In [&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":[20,9],"tags":[337,60,72,86,99,102,110,124,154,169,331,185,189,220],"class_list":["post-3325","post","type-post","status-publish","format-standard","hentry","category-apex","category-salesforce","tag-apex","tag-community","tag-dataloader","tag-eclipse","tag-field-level-security","tag-fls","tag-google-docs","tag-interview-questions","tag-person-account","tag-report","tag-salesforce","tag-soql","tag-standard-report-visibility","tag-winter-14"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":2681,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-interview-questions-part-5\/","url_meta":{"origin":3325,"position":0},"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":3411,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/apex-interview-question-salesforce-part-16\/","url_meta":{"origin":3325,"position":1},"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":[]},{"id":1305,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-interview-questions-part-3\/","url_meta":{"origin":3325,"position":2},"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":2835,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-apex-code-talk-important-questions-and-answers\/","url_meta":{"origin":3325,"position":3},"title":"Salesforce Apex Code talk &#8211; Important Questions and Answers","author":"Jitendra","date":"May 3, 2012","format":false,"excerpt":"Salesforce Apex Code talk on - 24-April-2012 , Important Interview Questions","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":5515,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/batch-apex-first-error-apex-cpu-time-limit-exceeded\/","url_meta":{"origin":3325,"position":4},"title":"Batch Apex &#8211; First error: Apex CPU time limit exceeded","author":"Jitendra","date":"June 1, 2016","format":false,"excerpt":"Lessons learned while fixing error in Batch Apex , First error: Apex CPU time limit exceeded","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":3325,"position":5},"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":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/3325","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=3325"}],"version-history":[{"count":3,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/3325\/revisions"}],"predecessor-version":[{"id":4236,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/3325\/revisions\/4236"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=3325"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=3325"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=3325"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}