Mar 14, 2016

Lab Coat Challenge 8: Scripting Scripts


Salesforce Devs, we have a Lab Coat Challenge for you challenge your ability to utilize queries and DMLs. Review the challenge, take a look at the starter code, and then give it your best attempt. If you come up with the right answer, you will earn a Lab Coat Badge.


Overview


Today’s challenge is related with queries and DMLs.

Challenge


There are two orgs. Org A has 10 Accounts that need to find their way into Org B. Org B has no accounts.  Neither org allows you to use Data Loading tools (Data Loader, Workbench, etc).  Both orgs allow you to run Apex. Write an Apex script that outputs an Apex script that will run on Org B and create those 10 Account records.

Starter Code  





Lab Coat Challenge 7: Merge Text




Salesforce Devs, we have a Lab Coat Challenge for you that will test your mental ability. Review the challenge, take a look at the starter code, and then give it your best attempt. If you come up with the right answer, you will earn a Lab Coat Badge. We'll share your success on Twitter!


Overview 


Today’s challenge has to do with merging text.

Challenge


Hi {!FirstName},

We hope you enjoy {!Number__c}.  Show us your {!ChallengeSkillset__c} chops!

Hang on..., that’s not a typo or a merge fail. It’s the gist of this Lab Coat Challenge. You’re developing a way to construct a dynamic query that includes all of the placeholders in a given piece of text. Your objective is to take in a string of text, with one or more merge fields, pluck out the fields, and build your query string out.

For example, for the above sample, your query string would need to pull in the FirstName field (IE:  SELECT Id, FirstName, ChallengeNumber__c, ChallengeSkillset__c…).


Starter Code


You must use the following code and can only add to the code provided below.






Lab Coat Challenge 6: Quick Mode



Hey there dev's and dev's-to-be! We have a 'Quick' Lab Coat Challenge for you. Review the challenge, take a look at the starter code, and then give it your best shot. Get the right answer and earn your Lab Coat Badge.


Overview


Today’s challenge has to do with finding the mode of a given set of integers


Challenge

Using the smallest amount of code (least statements - no run on lines of multiple statements!), determine what the “mode” (most frequent number) of a set of integers is. For more information on mode go to: http://www.mathgoodies.com/lessons/vol8/mode.html.  For this challenge, if the solution is multimodal (having more than one mode), choose the lowest number of the results (IE:  If 2, 3, and 10 are modes for a set of integers, the solution will be 2).


Starter Code

You must use the following code and can only add to the code provided below.


/*  LAB COAT CHALLENGE: What is the minimum amount of lines
   needed in order to find the mode of the following list
   of integers? */

//  lists of integers to be used in the asserts
list<Integer> numbers1 = new list<Integer> {2,5,1,2,7,1,2,6,4,6,2,3,8,9};
list<Integer> numbers2 = new list<Integer> {2,5,1,6,7,8,1,5};
list<Integer> numbers3 = new list<Integer> {5,4,7,1,7,2,3,5,4};
list<Integer> numbers4 = new list<Integer> {5,4,7,2,1,7,1,2,5,4};

//  Test your code
system.assertEquals(mode(numbers1), new set<Integer> {2});
system.assertEquals(mode(numbers2), new set<Integer> {1,5});
system.assertEquals(mode(numbers3), new set<Integer> {4,5,7});
system.assertEquals(mode(numbers4), new set<Integer>());

//  YOUR CHANGES START BELOW

//   Implement the following method
set<Integer> mode(list<Integer> listOfIntegersToTest) {
   set<Integer> returnValues = new set<Integer>();

   // Your code here

   return returnValues;

}