I am new to Salesforce development. I am not sure how to write the Test class for this Rest Service I created @RestResource(urlMapping='/sdf/lead/*') global with sharing class LEAD_Controller {   public class LeadWrapper {     public string firstName;     public string lastName;     public string email;     public string company;     public string phone;   }   public class ErrorJSON {     public string errorCode;     public string message;   }    private static String getErrorMessage(string errorCode, string message) {     ErrorJSON res = new ErrorJSON();      res.errorCode = errorCode;     res.message = message;      return JSON.serialize(res);   }    @HttpPost   global static void createLead() {     RestResponse res = RestContext.response;      res.headers.put('Content-Type', 'application/json');     try {       List&lt;LeadWrapper&gt; leadListFromRequest = (List&lt;LeadWrapper&gt;) System.JSON.deserialize(         RestContext.request.requestBody.toString(),         List&lt;LeadWrapper&gt;.class       );        List&lt;Lead&gt; leadList = new List&lt;Lead&gt;();       for (LeadWrapper r : leadListFromRequest) {         Lead l = new Lead();         l.FirstName = r.firstName != null ? r.firstName : '';         l.Lastname = r.lastName != null ? r.lastName : '';         l.Email = r.email != null ? r.email : '';         l.Company =           (r.firstName != null ? r.firstName : '') +           ' ' +           (r.lastName != null ? r.lastName : '');          leadList.add(l);       }        insert leadList;        res.statusCode = 204;     } catch (Exception e) {       res.responseBody = Blob.valueOf(e.getMessage());       res.statusCode = 500;     }   }    public class getLeadWrapper {     public string firstName;     public string lastName;     public string company;     public string email;     }    @HttpGet   global static void searchLeadById() {     RestRequest req = RestContext.request;     RestResponse response = RestContext.response;     String queryStringId = req.params.get('Id');     System.debug(queryStringId);     response.headers.put('Content-Type', 'application/json');     Map&lt;String, Object&gt; mapToSerialize = new Map&lt;String, Object&gt;();     try {       if (queryStringId == null || queryStringId == '') {         response.responseBody = Blob.valueOf('Bad request');         response.statusCode = 400;       } else if (queryStringId != null) {         List&lt;Lead&gt; searchLead = [           SELECT             Id,             FirstName,             LastName,             Company,             Email,                       FROM Lead           WHERE Id = :queryStringId         ];         Integer searchLeadResponse = searchLead.size();          if (searchLeadResponse == 0) {           response.responseBody = Blob.valueOf('Bad request');           response.statusCode = 404;         } else {           for (Lead ld : searchLead) {             getLeadWrapper contWrapper = new getLeadWrapper();             contWrapper.firstname = ld.FirstName;             contWrapper.lastName = ld.LastName;             contWrapper.company = ld.Company;             contWrapper.email = ld.Email;             contWrapper.utmCampaign = ld.UTM_Campaign__c;             contWrapper.programCode = ld.UTM_Campaign__c;             mapToSerialize.put(ld.Id, contWrapper);             response.responseBody = Blob.valueOf(               JSON.serialize(mapToSerialize)             );             response.statusCode = 200;           }         }       }     } catch (Exception e) {       response.responseBody = Blob.valueOf(e.getMessage());       response.statusCode = 500;     }   } }
How do I write an Apex unit test? This is a canonical question and answer developed by the community to help address common questions. If you've been directed here, or your question has been closed as a duplicate, please look through the resources here and use them to shape more specific questions. To browse all canonical questions and answers, including more unit test resources, navigate to the  tag.  This canonical question is intended to address several classes of common questions by providing a quick summary and links to comprehensive resources:   How do I start writing my first unit test?  How do I unit test this code?  I need help writing this unit test.   Salesforce Stack Exchange looks for detailed, specific questions that the community can help you with, and can't write tests on your behalf. We feel that working with the resources below can help you get started, and we encourage you to make an attempt to write your test and return to SFSE with your specific questions when you encounter challenges you can't resolve.
Does the use of words such as 'fail', 'wrong', 'incorrect' and 'invalid' have a sufficiently negative impact on a users frame of mind to warrant the prohibition of their inclusion in the error messages generated by typical web forms?  i.e. Should we rephrase examples like these to just use positive words?  'date entered incorrectly'  or  'failed to complete registration, please see below for invalid field entries'  (PS, the examples are there to show use of the words in an error message, not to serve as examples of error messages I would use or things that need correcting in answers, I'm not looking for advice on how to write form error messages, but for information about the effect of certain words on a users frame of mind) Is a variable/arbitrary element a precisely defined mathematical object? Reference book on measure theory I post this question with some personal specifications. I hope it does not overlap with old posted questions.  Recently I strongly feel that I have to review the knowledge of measure theory for the sake of starting my thesis.  I am not totally new with measure theory, since I have taken and past one course at the graduate level. Unfortunately, because the lecturer was not so good at teaching, I followed the course by self-study. Now I feel that all the knowledge has gone after the exam and still don’t have a clear overview on the structure of measure theory. And here come my specified requirements for a reference book.   I wish the book elaborates the proofs, since I will read it on my own again, sadly. And this is the most important criterion for the book. I wish the book covers most of the topics in measure theory. Although the topic of my thesis is on stochastic integration, I do want to review measure theory at a more general level, which means it could emphasize on both aspects of analysis and probability. If such a condition cannot be achieved, I'd like to more focus on probability. I wish the book could deal with convergences and uniform integrability carefully, as Chung’s probability book.    My expectation is after thorough reading, I could have strong background to start a thesis on stochastic integration at an analytic level.  Sorry for such a tedious question.  P.S: the textbook I used is Schilling’s book: measures, integrals and martingales. It is a pretty good textbook, but misprints really ruin the fun of reading. Is there a limit to a total number of months a holder of UK multiple entry visitor visa can spend in UK per calendar year? I have a question.  I have been given this proof: "For any $n$ in the integers where $n&gt;2$, show there are at least $2$ elements in $U(n)$ that satisfy $x^2=1$."  I have gone through and actually proved this, (that the numbers are $1$ and $n-1$) but i didn't' know how to prove that $n-1$ is in fact in the set $U(n)$. Is it because two consecutive numbers are always relatively prime? At this moment there are 4 meta-site questions on the HNQ list:    (World Building Meta)  (Meta StackOverflow)  (Workplace Meta)  (Mathematica Meta)   When I first saw it, I only saw the SO Moderator question, so I assumed that this was a one-off special thing for the election; but now we've got four questions crept in. Was this an intentional change, or a bug? How to prove the set $S$ is closed under the binary operation $a*b=a+b+kab$? Let $k$ be any nonzero real number and let $S$ be all real numbers except ${-1\over k}$. Let $a,b \in S$. Define * on S by $a*b=a+b+kab$. Prove that $S$ is closed under *.  All I can think to do is set $a*b$ equal to ${-1\over k}$, but I don't know where to go from there. Is that the extent of the proof? I've just executed a long-running process from the bash prompt. In hindsight, I wish I'd run time on it, or noted down the time at which I kicked it off.  Is there any way of getting this information retrospectively? The .bash_history doesn't seem to include timestamps.  In my particular case it's Mac OS X, but I'm interested in general Unix/Linux solutions.  To clarify, the process has now completed, and I'd prefer not to run it again unless absolutely necessary! Which sort algorithm works best on mostly sorted data? Working with objects created with Activator.CreateInstance Identify an unknown IP in our network I have a network containing 20 clients. I assigned IP range 10.0.0.1 to 10.0.0.20 to them. When I do an IP scanning I see someone using 10.0.0.131 in VMware. How can I find out which IP is this IP bridged with? i.e How can I find out which system has 2 IP? (i.e the other IP of this system)  Update:  My system IP in the network is 10.0.0.81:    Output of the IP scanner show someone using 10.0.0.131 in VMware:    And the result of tracert command show nothing between us:  C:\Users&gt;tracert -j 10.0.0.131 10.0.0.81  Tracing route to ghasemi3.it.com [10.0.0.81] over a maximum of 30 hops:    1    &lt;1 ms    &lt;1 ms    &lt;1 ms  ghasemi3.it.com [10.0.0.81]  Trace complete. C:\Users&gt; Today, we had a math class, where we had to show, that $a_{100} &gt; 14$ for  $$a_0 = 1;\qquad a_{n+1} = a_n + a_n^{-1}$$  Apart from this task, I asked myself: Is there a closed form for this sequence? Since I didn't find an answer by myself, can somebody tell me, whether such a closed form exists, and if yes what it is? Filtering points in GeoServer layer Can I open Microsoft Word and Excel files? Can I open Microsoft Word and Excel files with Ubuntu? How do I connect to a MSSQL database using Perl's DBI module in Windows? How to create a database directory structure for MySQL? I was following this tutorial:    So far, I installed mysql-server mysql-client libmysqlclient-dev, and I was suppose to tell MySQL to create its database directory structure where it will store its information using sudo mysql_install_db.  $ sudo mysql_install_db  [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize [ERROR]   The data directory needs to be specified.   I thought running mysqld --initialize would solve the issue:  $ mysqld --initialize   mysqld: Can't create directory '/var/lib/mysql/' (Errcode: 17 - File exists) [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). [ERROR] Aborting   How do I tell MySQL to create its database directory structure where it will store its information? Looking for the actual reason of refraction explained precisely without analogies After reviewing ...  I'd like to make an argument for answers that have attained more votes than an accepted answer always be ranked above when answers are being sorted by votes (the default)...     Someone visiting this (older) question expecting a relevant answer would be assuming the big green check mark means that it is the correct answer today when in fact it's the correct answer when the question was originally asked.  Allowing votes to override the asker's time bound response, it allows the best answers to remain at the top and evolve with our ever changing field without requiring the asker to maintain their questions.  This would be a step in the direction of the site's ethos in my opinion, trusting the community to determine the best answer to place at the top for prospective visitors. What is a good use case for static import of methods? Just got a review comment that my static import of the method was not a good idea. The static import was of a method from a DA class, which has mostly static methods. So in middle of the business logic I had a da activity that apparently seemed to belong to the current class:  import static some.package.DA.*; class BusinessObject {   void someMethod() {     ....     save(this);   } }    The reviewer was not keen that I change the code and I didn't but I do kind of agree with him. One reason given for not static-importing was it was confusing where the method was defined, it wasn't in the current class and not in any superclass so it too some time to identify its definition (the web based review system does not have clickable links like IDE :-) I don't really think this matters, static-imports are still quite new and soon we will all get used to locating them.  But the other reason, the one I agree with, is that an unqualified method call seems to belong to current object and should not jump contexts. But if it really did belong, it would make sense to extend that super class.  So, when does it make sense to static import methods? When have you done it? Did/do you like the way the unqualified calls look?  EDIT: The popular opinion seems to be that static-import methods if nobody is going to confuse them as methods of the current class. For example methods from java.lang.Math and java.awt.Color. But if abs and getAlpha are not ambiguous I don't see why readEmployee is. As in lot of programming choices, I think this too is a personal preference thing.   Thanks for your response guys, I am closing the question. I sadly haven't been able to answer this questions using Google. In beamer, I'd like to make the default font for the entire title page, as well as frame titles, to be the default font from the old  (example ).