Salesforce interview questions – Most frequently used Apex and visualforce code used by Salesforce developers like “How to query and abort scheduled job using Apex”, “Defining VF page as HTML5”, “Visualforce page as JSON” , “Handling colon in element Id for Jquery” , “Chatter using Apex” and many more.
1 | < apex:page sidebar = "false" standardStylesheets = "false" showHeader = "false" > |
202. Declare Visualforce page as HTML5.
1 | < apex:page docType = "html-5.0" /> |
1 | < apex:page controller = "ControllerName" contentType = "application/x-JavaScript; charset=utf-8" showHeader = "false" standardStylesheets = "false" sidebar = "false" > |
1 | < apex:stylesheet value = "{!URLFOR($Resource.style_resources, 'styles.css')}" /> |
Relative path in CSS from static resource, You can use relative paths in files in static resource archives to refer to other content within the archive.
1 | table { background-image: img/testimage.gif } |
Image tag:
1 | < apex:image url = "{!$Resource.TestImage}" width = "50" height = "50" /> |
or
1 | < apex:image url = "{!URLFOR($Resource.TestZip, 'images/Bluehills.jpg')}" width = "50" height = "50" /> |
Include Javascript in Visualforce from Static resource
1 | < apex:image url = "{!$Resource.TestImage}" width = "50" height = "50" /> |
Refer static resource path from Aprx Controller
1 | global class MyController { |
2 | public String getImageName() { |
1 | < apex:page renderAs = "pdf" controller = "MyController" > |
2 | < apex:variable var = "imageVar" value = "{!imageName}" /> |
3 | < apex:image url = "{!URLFOR($Resource.myZipFile, imageVar)}" /> |
205. How to get element id of Visualforce components to be used in Javascript ?
1 | {!$Component.Parent1.Parent2.fieldId} |
206. Autogenerated Salesforce Id consist of colon, how to handle it in JQuery ?
1 | var ele = $( '[id="abc:xyz"]' ); |
207. How to return Map result from SOQL query in Apex.
1 | Map< ID , Contact> m = new Map< ID , Contact>([SELECT Id, LastName FROM Contact]); |
208. How to query and abort scheduled job using Apex.
While updating class on Sandboxes, chances are high that it is being used in any scheduler, so below code will abort all scheduled job. If there are 150+ scheduled job, then you might want to use below code again and again in developer console until all jobs are removed from system.
2 | List<CronTrigger> abort_job = [SELECT Id FROM CronTrigger WHERE State != 'Deleted' limit 150 ]; |
3 | for (CronTrigger t : abort_job) { |
209. How to use standard Salesforce REST API from Visualforce page ?Befor any Ajax call, make sure to add ‘Bearer’ token in header. If using JQuery use below code snippet. For more information
read this post.
3 | beforeSend: function (xhr) |
5 | xhr.setRequestHeader( "Authorization" , 'Bearer {!$API.Session_ID}' ); |
8 | headers : { 'Content-Type' : 'application/json; charset=utf-8' }, |
13 | .done(function( data ) { |
16 | .fail(function(xhr,textstatus,error){ |
210. How to create Chatter post from Apex.
2 | FeedItem post = new FeedItem(); |
4 | post.Body = 'Enter post text here' ; |
8 | FeedItem post = new FeedItem(); |
10 | post.Body = 'Enter post text here' ; |
15 | FeedItem post = new FeedItem(); |
17 | post.Body = 'Enter post text here' ; |
18 | post.ContentData = base64EncodedFileData; |
19 | post.ContentFileName = 'sample.pdf' ; |
No comments:
Post a Comment