Monday, 1 August 2011

Apex Scheduler

Apex Scheduler
To invoke Apex classes to run at specific times we use Apex Scheduler
Steps to implement Schedulable Apex
1.       Implement Schedulable Interface for the class

E.g.:        global class scheduledMerge implements Schedulable{
// Schedulable Class 
                                                //Schedulable Method Mandatory for each Interface
global void execute(SchedulableContext SC) {
//Class which has to be scheduled
mergeNumbers M = new mergeNumbers();
}
}
The Schedulable interface contains one method that must be implemented, execute.
global void execute(SchedulableContext sc){}
SchedulableContext object is used to keep track of the scheduled job once it's scheduled.
The SchedulableContext method getTriggerId returns the Id of the CronTrigger object associated with this scheduled job as a string. Use this method to track the progress of the scheduled job.
2.      To Implement the above class in step 1 we need to use System.Schedule Method
The following example uses the System.Schedule method to implement the above class.

scheduledMerge m = new scheduledMerge();// Creating object of the Schedulable
                                                                                                Class
String sch = '20 30 8 10 2 ?';// Format of when and at what time the process is
                                                                scheduled

system.schedule('Merge Job', sch, m); // Implementing the Schedule Process

The System.Schedule method takes three arguments: a name for the job, an expression used to represent the time and date the job is scheduled to run, and the name of the class. This expression has the following syntax:
Seconds Minutes Hours Day_of_month Month Day_of_week optional_year
The following are the valid values for the above expression:
Name               Values                          Special Characters
Seconds               0–59                             None
Minutes                 0–59                            None
Hours                    0–23                            , - * /
Day_of_month    1–31                              ,- * ? / L W
Month                    1–12 or the following:    , - * /
 JAN – DEC Any Month

Day_of_week      1–7 or the following:      , - * ? / L #
SUN-SAT Any Day

optional_year      null or 1970–2099              , - * /

The special characters are defined as follows:
• , —Delimits values. For example, use JAN, MAR, APR to specify more than one month.
• - —Specifies a range. For example, use JAN-MAR to specify more than one month.
• * —Specifies all values. For example, if Month is specified as *, the job is scheduled for every
month.
• ? —Specifies no specific value. This is only available for Day_of_month and Day_of_week, and
                is generally used when specifying a value for one and not the other.
• / —Specifies increments. The number before the slash specifies when the intervals should
                begin, and the number after the slash is the interval amount. For example, if you specify
                1/5 for Day_of_month, the Apex class runs every fifth day of the month, starting on the
                first of the month.
• L —Specifies the end of a range (last). This is only available for Day_of_month and
                Day_of_week.When used withDay of month, L always means the last day of the month,
                such as January 31, February 28 for leap years, and so on.When used with Day_of_week
                by itself, it always means 7 or SAT.When used with a Day_of_week value, it means the
                last of that type of day in the month. For example, if you specify 2L, you are specifying
                the last Monday of the month. Do not use a range of values with L as the results may be
                unexpected.
• W —Specifies the nearest weekday (Monday-Friday) of the given day. This is only available for
                Day_of_month. For example, if you specify 20W, and the 20th is a Saturday, the class
                runs on the 19th. If you specify 1W, and the first is aSaturday, the class does not run in
                the previous month, but on the third, which is the following Monday.
• # —Specifies the nth day of the month, in the format weekday#day_of_month. This is only
                available for Day_of_week. The number before the # specifies weekday (SUN-SAT). The
                number after the # specifies the day of the month. Forexample, specifying 2#2 means the
                class runs on the second Monday of every month.
The following are some examples of how to use the expression.
Expression Description
0 0 13 * * ?                          Class runs every day at 1 P.M.
0 0 22 ? * 6L                        Class runs the last Friday of every month at 10 P.M.
0 0 10 ? * MON-FRI          Class runs Monday through Friday at 10 A.M.
0 0 20 * * ? 2010                Class runs every day at 8 P.M. during the year 2010.
3.       Create a Test class and Check if it is working properly or not
4.       To check whether the job is Scheduled or not GOTO SetupàAdministration Setup à Monitoring àScheduled Jobs
You can find all the Scheduled jobs here and there start and next run details.
//For Reference check salesforce_apex_language_reference_18.0.pdf – Apex Scheduler

Anonymous Block
An anonymous block is an Apex script that does not get stored in the metadata, but that can be compiled and executed.
Compilation and Execution can be done using the Following:
1.       System Log console
2.       Force.com IDE
3.       The executeAnonymous Force.comWeb Services API call:
ExecuteAnonymousResult executeAnonymous(String code)

Note the following about the content of an anonymous block (for executeAnonymous, the code String):
• Can include user-defined methods and exceptions.
• User-defined methods cannot include the keyword static.
• You do not have to manually commit any database changes.
• If your Apex script completes successfully, any database changes are automatically committed. If your
   Apex script does not complete successfully, any changes made to the database are rolled back.
• Unlike classes and triggers, anonymous blocks execute as the current user and can fail to compile if the
   script violates the user's object- and field-level permissions.
• Do not have a scope other than local. For example, though it is legal to use the global access modifier,
    it has no meaning. The scope of the method is limited to the anonymous block.
executeanonymous() : Executes a block of Apex

Syntax:
ExecuteAnonymousResult[] = binding.executeanonymous(string apexcode);

The executeanonymous() call returns information about whether or not the compile and run of the code was successful.

The ExcuteAnonymousResult has the properties which tells us that if there is a compilation error then at which column number, line and what type of exception has occurred. If Success then it results true.

Implementation Details in Force.Com IDE:
1.       Create a webservice class which has to be executed anonymously.


Example:
global class LocationSample{ 
    webService static boolean getLocation(string strLocation){
    boolean oppExistInCw = false;
   
    //query Location__c Custom Object to search for related Address
         Location__c loc=[Select Name, city__c, country__c,
         Street_Address__c from Location__c where Name=:strLocation];
     if(loc!=null) {
        //update Postal Field
        loc.Postal_Code__c = '500036';
        update loc;
        oppExistInCw = true;
        return oppExistInCw;
     }else{
        return oppExistInCw;
     }   
    }
}
2.       Once Webservice class has been created then goto ExecuteAnonymous block

3.       Once it is successful then the changes will be committed as per your code.

Salesforce401Question & Answers

  1. In the statement below, controller refers to what type of controller? Select the one correct answer. <apex:page controller="AccountController">
    1. Standard Controller
    2. Custom Controller
    3. Controller Extension
    4. Specific Controller
  2. Which of the following represent correct syntax to display first name from global variable user? Select the one correct answer.
    1. {User.FirstName}
    2. {!User.FirstName}
    3. $User.FirstName
    4. {!$User.FirstName}
  3. Which of these is not a standard profile? Select the one correct answer.
    1. Developer
    2. Contract Manager
    3. Read only
    4. Solution Manager
  4. Name the language Force.com uses to support full-text search in objects. Select the one correct answer.
    1. SQL
    2. VisualForce
    3. SOQL
    4. SOSL
  5. Before a code can be deployed on production what percentage of test coverage must be achieved. Select the one correct answer.
    1. 25%
    2. 50%
    3. 75%
    4. 100%
  6. In Salesforce what is the maximum number of fields that can be added to an object? Select the one correct answer.
    1. There is no such limit on the number of fields
    2. 100
    3. 200
    4. 500
  7. How many characters are there in the Salesforce case-insensitive id field of an object? Select the one correct answer.
    1. id field is not mandatory
    2. The field length is customizable
    3. This depends on the version of Salesforce
    4. 18
  8. Name the prefix used by standard VisualForce markup tags. Select the one correct answer.
    1. vf
    2. apex
    3. c
    4. s

  1. Which of the following cannot be included in a VisualForce page? Select the one correct answer.
    1. Java
    2. JavaScript
    3. HTML
    4. Flash
  2. To create a new VisualForce page HelloWorld in developer mode, which URL should be appended to server address? Select the one correct answer.
    1. /HelloWorld
    2. /vf/HelloWorld
    3. /apex/HelloWorld
    4. /home/HelloWorld
  3. What is the maximum size of a VisualForce page? Select the one correct answer.
    1. 1 MB
    2. 5 MB
    3. 15 MB
    4. There is no limit on the size of a VisualForce page
  4. What is the number of components that can be added to a dashboard? Select the one correct answer.
    1. 20
    2. 25
    3. 50
    4. 100
  5. Which of these represent the correct syntax for custom controllers? Select the one correct answer.
    1. <apex:page controller="MyController">
    2. <apex:page standardController="MyController">
    3. <apex:page customController="MyController">
    4. <apex:page privateController="MyController">
  6. Which is the first step when creating reports? Select the one correct answer.
    1. Select report name
    2. Select object on which report needs to be generated
    3. Select type of report
    4. Select columns to be displayed
  7. Which of these is not a valid report type. Select the one correct answer.
    1. Summary
    2. Matrix
    3. Tabular
    4. Detailed
  8. Which report type is used to group rows of data and show their subtotals. Select the one correct answer.
    1. Summary
    2. Matrix
    3. Tabular
    4. Detailed
  9. Which report type is used to group rows and columns of data and show their subtotals. Select the one correct answer.
    1. Summary
    2. Matrix
    3. Tabular
    4. Detailed
  10. Which report type does not allow generation of charts? Select the one correct answer.
    1. Summary
    2. Matrix
    3. Tabular
    4. Detailed
  11. Which of these are valid data type in Force.com development platform. Select the two correct answers.
    1. Percent
    2. URL
    3. Choicebox
    4. Long
    5. Decimal
  12. When designing an application, a developer needs to make a field editable to all profiles. In field level security what settiings should be used in this situation. Select the one correct answer.
    1. Disable Visible and Read-Only
    2. Disable Visible but Enable Read-Only
    3. Enable Visible but Disable Read-Only
    4. Enable Visible and Read-Only
  13. Which report type does not support analytical snapshot? Select the one correct answer.
    1. Summary
    2. Matrix
    3. Tabular
    4. Detailed
  14. A customer has requested a user interface where list view of four objects can be accessed together with frequent navigation across them. Which feature of Force.com platform can be used to support this requirement? Select the one correct answer.
    1. Console
    2. Dashboards
    3. Analytical Snapshot
    4. Packages
    5. Layout template
  15. In a recruitment application, a dashboard component needs to be built that will display total number of positions. Which dashboard component can be used to implement this feature? Select the one correct answer.
    1. Gauge
    2. Metric
    3. Table
    4. Chart
    5. VisualForce page
  16. Universal Recruiters will like to hire ten employees in two months. In a recruitment application, a dashboard component needs to be built that will display progress towards achieving this goal of hiring of ten employees. Which dashboard component can be used to implement this feature? Select the one correct answer.
    1. Gauge
    2. Metric
    3. Table
    4. Chart
    5. VisualForce page
  17. Universal Recruiters uses an external system for keeping track of exits from the organization. The CEO of the organization will like to view information about exits in the Salesforce application that Universal Recruiters uses. Which dashboard component can be used to implement this feature? Select the one correct answer.
    1. Gauge
    2. Metric
    3. Table
    4. Chart
    5. VisualForce page
  18. Universal Recruiters uses Force.com as its recruitment platform. The Sales VP of Universal Recruiters will like a report that will display progress in recruitment across six months. Which reporting component can be used to implement this feature? Select the one correct answer.
    1. Summary
    2. Matrix
    3. Tabular
    4. Analytic Snapshot
  19. Which two features are supported by Salesforce in developer mode? Select the one correct answer.
    1. Developer mode allows a default user interface to be created for objects.
    2. Developer mode provides a debugger that is used to perform step by step execution.
    3. Developer mode allows developers to create dashboards from reports.
    4. Developer mode allows split screen where user can view Visual Force editor and user interface together
    5. Developer mode allows developers to create new pages by just entering the page name.
  20. Universal Recruiters wants to make access to records in such a way that all managers should be able to access records that are accessible to their team members. Which feature of Force.com's security should be used to implement this requirement. Select the one correct answer.
    1. Object level access to profiles
    2. Field level access to profiles
    3. Organization wide defaults
    4. Role hierarchy
    5. Sharing rules
    6. Manual sharing
  21. Universal Recruiters need to ensure that the Social Security Number and Phone Numbers follow a specific pattern. Which function can be used to implement this functionality. Select the one correct answer.
    1. REGEX
    2. EXPRMATCH
    3. ISNUMBER
    4. PRIORVALUE
    5. VLOOKUP
  22. Universal Recruiters have an object that they use to store all US zip codes and corresponding states. They want to ensure that the zip code and state specified by users are correct. Which function could be used to implement this feature? Select the one correct answer.
    1. REGEX
    2. EXPRMATCH
    3. ISNUMBER
    4. PRIORVALUE
    5. VLOOKUP
  23. Which of these functions is available in formulae field. Select the one correct answer.
    1. ISCHANGED
    2. ISNEW
    3. REGEXC
    4. IF
    5. VLOOKUP
    6. All of these functions are available in a formula field
  24. A Force.com developer needs to execute Apex code snippet and check the resource usage. Which feature of the platform can be used to support this requirement. Select the one correct answer.
    1. Debug Log
    2. System Log
    3. Setup Audit Trail
    4. Field level security
  25. A user at Universal Container has reported an issue with respect to approval process. You need to analyze this issue by reviewing the debug messages that get generated for this particular users. Which feature of the platform can be used to support this requirement. Select the one correct answer.
    1. Debug Log
    2. System Log
    3. Setup Audit Trail
    4. Field level security
  26. While debugging an issue you realize that the field type of an object has changed. You need to find out more details about this change. Which feature of the platform can be used to support this requirement. Select the one correct answer.
    1. Debug Log
    2. System Log
    3. Setup Audit Trail
    4. Field level security
  27. In Universal Recruiter application a developer realizes that the Salary field of an employee is set up to an incorrect value. The developer needs to find out who has set this new value to Salary field. Which feature of the platform can be used to support this requirement. Select the one correct answer.
    1. Debug Log
    2. System Log
    3. Setup Audit Trail
    4. Field level security
  28. Which of the following is correct about custom fields in Salesforce. Select one correct answer.
    1. If a field is set as required it must be entered in the Salesforce generated pages, however it may not be specified when entering information via Force.com API
    2. A required field is always present in an edit page
    3. A unique field is always present in an edit page
    4. A unique field increases report and SOQL performance
  29. Fields of the which of the following type is not allowed to be set as external ids. Select one correct answer.
    1. Date
    2. Number
    3. eMail
    4. Text
  30. The number of master detail relationship that an object can have are
    1. 1
    2. 2
    3. 25
    4. 300
  31. The number of Lookup relationship that an object can have are
    1. 1
    2. 2
    3. 25
    4. 300
  32. Which of these is true about the Lookup Relationship. Select one correct answer.
    1. Parent is not a required field and may be omitted.
    2. Deleting an object deletes its children.
    3. Roll-up summary field can be used to perform basic operations over all children of a parent record.
    4. Security access of the child record is dependent upon the parent record.
  33. Which of the following cannot be used to build a complete Custom Tab. Select one correct answer.
    1. Display an external web page
    2. Display data using a VisualForce page
    3. Show data from a custom object using the native user interface
    4. Display the approval process using an Apex page
  34. Which of the following is not supported by Enhanced Page Layout editor. Select the one correct answer.
    1. Change the field name
    2. Add blank spaces
    3. Make a field required or read-only
    4. Add a new section
    5. Add a new custom field
  35. Which of the following is true about Roll-up summary fields? Select one correct answer.
    1. Roll-up summary can only be set on the parent of a Master-Detail or Lookup relationship.
    2. Roll-up summary can be used to compute SUM,MIN,MAX,AVG over a set of records
    3. The results of the roll-up summary is displayed on the child in a master-detail relationship.
    4. Roll-up summary fields are read only.
  36. Which of the following is true about Validation Rules? Select two correct answers.
    1. Validation rules are executed when the user clicks on the Save button.
    2. Validation rules are not applicable when the data is stored using the API.
    3. If the error condition evaluates to true, then an error message is generated and the record is not saved.
    4. Validation rules are applied only when a new record is created, and not when an existing record is edited.
  37. Which of the following is not a valid return type of a custom formula. Select one correct answer.
    1. Date
    2. Decimal
    3. Text
    4. Array
  38. Which of the following is not a part of a Force.com app. Select one correct answer.
    1. Notes
    2. Tab
    3. Links
    4. Forms
  39. An organization needs to create a public website that displays data from Salesforce.com organization without user registration. Select one correct answer.
    1. Apex
    2. Triggers
    3. Salesforce Knowledgebase
    4. Force.com sites
    5. Formula
Answers
  1. B. controller attribute is used for Custom Controller
  2. D. {!$User.FirstName} is the correct syntax to access first name.
  3. A. There is no developer standard profile.
  4. D. Salesforce Object Search Language
  5. C. The code must get a test coverage of 75% before it can be deployed.


  6. D. There can be a maximum of 500 fields in custom objects.
  7. D. object id field can be 15 character case-sensitive or 18 character case-insensitive.
  8. B. The prefix apex is used for standard VisualForce markup tags.
  9. A. It is not possible to include Java code in VisualForce page.
  10. VisualForce page address appears like /apex/HelloWorld.


  11. C. VisualForce pages must be upto 15 MB.
  12. A. A dashboard can have upto 20 components.
  13. A.
  14. B. The first step when creating reports is select the object type.
  15. D. Salesforce does not have a report type named Detailed.


  16. A.
  17. B.
  18. C.
  19. A, B. Percent and URL are valid data types in Salesforce.
  20. C. To make a field editable, enable Visible but disable Read-Only.


  21. B. Matric report cannot be used to generate Analytical snapshot.
  22. A. Console tab allows easy navigation across multiple object types.
  23. B. Metric dashboard type is used to display
  24. A. A gauge is used to display progress towards a goal.
  25. E. VisualForce pages can be used to draw dashboard components that extract data from another source.


  26. D. Analytic Snapshot feature of Salesforce is used to perform trend analysis over a period of time.
  27. D, E. Last two statements about developer mode are correct.
  28. D. Role Hierarchy feature of Force.com platform can be used to implement this functionality.
  29. A. REGEX function is used to check a text field matches the regular expression.
  30. E. VLOOKUP is used to return the value for a unique key in an object.


  31. D. IF function is available in the formula field. Other functions are not available in the formula field.
  32. B. System Log can be used to run code snippets.
  33. A. Debug Log can be used to view the debug/error messages generated for a particular user.
  34. C. Setup Audit Trail can be used to track changes made in the configuration.
  35. D. Field History Tracking can be used to find out changes in field values.


  36. B. A field set as required must always be present in the edit page.
  37. A. Fields of type external id can be defined as Text, Number or Email.
  38. B. An object can have maximum of 2 Master detail relationship
  39. C. An object can have maximum of 25 Lookup relationship
  40. A. Parent is not a required field in Lookup relationship


  41. D. Custom tabs can be used to display a VisualForce page, data from an external page, data from a custom object.
  42. E. Enhanced Page Layout editor cannot be used to create new fields.
  43. D. Only option D is correct. Rollup summary field can only be applied in Master-detail. Hence A is incorrect. AVG is not supported in Rollup summary fields.Rollup Summary is defined at the parent level of a Master-Detail relationship.
  44. A and C. Validation rules are applicable when the record is saved using the API, hence the option B is incorrect. Validation rules are applied every time the record is saved, hence D is incorrect.
  45. D. Array is not a valid return type of custom formula.


  46. A. Key element of a Salesforce app are Tab, Links and Forms.
  47. D. Force.com sites is used to build public facing sites.
  48. 1.  ID's are identical in :
  49. A. Production, full copy sandbox, developer
  50. B. Production and full copy sandbox only
  51. C. Production , developer
  52. 2.  If you want to look at trends in a report which report would you use:
  53. A. Matrix
  54. B. Summary
  55. 3.  If you want the a list of positions what dashboard would you use:
  56. A. metric
  57. B. table
  58. C. chart
  59. D. gauge
  60. 4.  how many master detail relationships can you have on an object:
  61. A. 4
  62. B. 2
  63. C. 1
  64. D. 3
  65. 5.  What would you use an apex trigger for...
  66. A. have a zip code object and in the city and state of the
  67. candidate position to check the zip code table and see if that
  68. city exist in the state
  69. B. create new record, have it update a field
  70. 6.  What is a Mini page layout or related list?
  71. 7.  Know everything about an external id.
  72. 8.  Know the ins and out of the search component on the side bar
  73. 9. What versions have apex and vf both active:
  74. 10. For the user object what can you do in the page layout:
  75. A. custom link
  76. B. inline vf page
  77. C. custom button
  78. D. custom field 
  79.  
  80. 11. A CEO does not want to log into salesforce.com but would
  81. like see the dashboards.
  82. How would one accomplish this? How would one set this up?
  83. 12. When one wants to lock the records:
  84. A. is this process automated
  85. B. One needs to choose this option when doing an approval process.
  86. 13. Profiles and what do they give access to?
  87. 14. Sharing and revoking grant access
  88. 15. The import wizard and user object
  89. 16. Force.com metadata api
  90. 17. What represents the view in MVC
  91. 18. Organization wide defaults
  92. 19. Public read/write, public read only
  93. 20. If the approval process sents out 3 emails simultaneously to managers.
  94. What is the next step in the approval process and how does it get to
  95. the next step?
  96. 21. Parent child relationship
  97. 22. Many many replationship
  98. 23. Manager wants to give access to data reporting to his team
  99. what access is required for this to happen:
  100. A. reports, dashboard folder
  101. B. reports dashboard user running
  102. 24. Encryted field not good for :
  103. 25. Workflow rules
  104. 26. Today()-Datevalue(CreatedDate)
  105. 27. For approval process what groups can you have:
  106. A. profiles
  107. B. roles and subordicates
  108. C. active team members
  109. 28. Org wide defaults / hierarchy turned off
  110. 29. Page Layout can you add inline vf
  111. 30. Record types
  112. 31. Is there such a thing called minipagelayout
  113. 32. Who can change the owner of a record
  114. 33. How does a developer test out the time trigger workflow rule
  115. does he do it through:
  116. A. debug log.
  117. B. sign in as the developer name, create new record,
  118. go to the time trigger queue
  119. 34. Creating a lookup relationship
  120. 35. What are the three actions for a workflow process the beggining steps
  121. 36. Do you give permissions to submit for approval button,
  122. Or is it added on automatically?
  123. 37. Dataloader: 50,000 more records at a time. True or False
  124. 38. Developer used dataloader and try to load into sandbox
  125. but had an issue had authentication issue
  126. What could it be:
  127. A. Password encryption
  128. B. Chk username
  129. C. chk endpoint
  130. 39. What is a Declarative interface?
  131. 40. What is localize and internationalize?
  132. 41. What does out of the box salesforce give you?
  133. A. data warehouse
  134. B. approval process
  135. C. workflow rules
  136. D. validation rules
  137. 42. Know this page.Inside out.
  138. 43. Apex Dataloader and Import wizard through salesforce.com
  139. For Apex Dataloader Go Into:
  140. Setup|Administrative Setup|Data Management| DataLoader (See Below)
     http://forceprepare.com/developermock.html