I have written this APEX class to use as a controller on a VFP. I need to write a TEST class for this. Can someone help with the test class for the below code ? Thank-you (The use case is to auto associate leads to the campaigns on the press of a button using VFP on campaign detail page)   public class CampaignLeads { public List&lt;AddLeads&gt; addFewLeads{get; set;} public List&lt;CampaignMember&gt; campMems ; public List&lt;Id&gt; ids; public Campaign camp; public CampaignLeads(ApexPages.StandardController sc) { ids = new List&lt;Id&gt;(); camp = new Campaign(); addFewLeads = new List&lt;AddLeads&gt;();  for(Lead lead: [SELECT Id, LastName FROM Lead WHERE Id NOT IN (SELECT LeadId FROM CampaignMember WHERE CampaignId =: ApexPages.currentPage().getParameters().get('id')) LIMIT 50 ]) { AddLeads objAddLeads = new AddLeads(lead); addFewLeads.add(objAddLeads); } campMems = new List&lt;CampaignMember&gt;(); }  public void insertLead() { Campaign camp = new Campaign(); System.Debug('FewLeads : ' + addFewLeads); List&lt;Campaign&gt; campList = [SELECT Id FROM Campaign WHERE Id =: ApexPages.currentPage().getParameters().get('id')]; System.Debug('Campign Id : ' + campList); if(addFewLeads.size() &gt; 0 &amp;&amp; campList.size() &gt; 0 ) { camp = campList[0]; for(AddLeads addLead : addFewLeads) { if(addLead.selected == true) { CampaignMember campMem = new CampaignMember(); campMem.CampaignId = camp.Id; campMem.LeadId = addLead.lead1.Id; campMems.add(campMem); } } } if(campMems.size() &gt; 0) { insert campMems; } }  public class AddLeads { public Lead lead1{get; set;} public Boolean selected{get; set;} public AddLeads(Lead wrpLead) { lead1 = wrpLead; selected = false; } } }  this is the VFP used: &lt;apex:page standardController=&quot;Campaign&quot; extensions=&quot;CampaignLeads&quot; &gt;     &lt;apex:form id=&quot;formID&quot;&gt;         &lt;apex:pageBlock &gt;     &lt;apex:pageBlockButtons &gt;             &lt;apex:commandButton value=&quot;Associate&quot; reRender=&quot;formID&quot; action=&quot;{!insertLead}&quot; oncomplete=&quot;CampaignPage()&quot; /&gt;     &lt;/apex:pageBlockButtons&gt; &lt;apex:pageBlockTable value=&quot;{!addFewLeads}&quot; var=&quot;le&quot; columns=&quot;4&quot;&gt;         &lt;apex:column headerValue=&quot;Select&quot;&gt;             &lt;apex:inputCheckbox value=&quot;{!le.selected}&quot;/&gt;         &lt;/apex:column&gt; &lt;apex:column value=&quot;{!le.lead1.LastName}&quot;&gt; &lt;/apex:column&gt; &lt;/apex:pageBlockTable&gt;         &lt;/apex:pageBlock&gt;     &lt;/apex:form&gt; &lt;script&gt; function CampaignPage() { window.top.location='/{!Campaign.Id}'; } &lt;/script&gt; &lt;/apex:page&gt;
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.
How do you prevent an ENTER key press from submitting a form in a web-based application? The choice of measurement basis on one half of an entangled state affects the other half. Can this be used to communicate faster than light? It is often stated, particularly in popular physics articles and videos, that if one measures a particle A that is entangled with some other particle B, then this measurement will immediately affect the state of the entangled partner.  For example, if Alice and Bob share an entangled pair of electrons and Alice measures her spin in the $x$ direction, then Bob's spin will also end up spinning in that direction, and similarly if she measures in the $z$ direction. Moreover, the effect will be instantaneous, regardless of the spatial distance between the two particles, which seems at odds with special relativity.  Can I use a scheme like this to communicate faster than light? Proof a set cannot contain its own powerset - Russell's Paradox Multiplicative group $(\mathbb R^*, ×)$ is group but $(\mathbb R, ×)$ is not group, why? $\mathbb R^*$ refers to $\mathbb R$ without zero.  Please explain the statement "$\mathbb R$  is not a group under multiplication, it is a group under addition." in the . Basically:   Why is multiplicative group $(\mathbb R^*, ×)$ a group? Why is $(\mathbb R, ×)$ not group? Why are $(\mathbb R^*, +)$ and $(\mathbb R, +)$ groups? I'm using Dataloader to Upsert a Child Account to Parent Account using an external ID.  When the Upsert is complete, the Child overwrites the parent, it's not not connecting the Child Account to the Parent Account.  ((See Answer Below)) Show that $a^2 \bmod b = (a \bmod b)^2 \bmod b$ Show that  $$a^2 \mathrm{\ mod \ } b = (a \mathrm{\ mod \ } b)^2 \mathrm{\ mod\ } b$$ for $ a, b \in \mathbb{Z}^+ $.  this was derived from an Informatics olympiad question. Math mode accents In my long document I, sadly, have to use several accents to denote different kinds of symbols. Currently, I use primes ($x'$), hat, tilde, and overline. In addition I use two colored symbols (red colored tilde and blue $\prescript\ulcorner$), as I need further distinguishment.  Now I'd like to have no colors in my document, while I still have at least six different ways to differentiate certain symbols.  Which alternatives could I use that are easy to recognize and 'stand out', while they are different to prime/hat/tilde/overline?  EDIT: The reader should be able to see the kind of accent used even if the symbol in question is in a sub-script (possibly even a sub-sub-script). What is the adjective to describe someone who views or represents someone/something as a stereotype? What I want to know is whether there is an adjective within the same word family as "stereotype" for that.  So, if it exists, it would be something like "stereotypist" or "stereotyping".  I know that "stereotypist" exists as a noun and "stereotyping" exists as a present participle but I wonder whether either (or both) of them has/have also been used in literature as an adjective. Can I choose which damage type my Sneak Attack does if my weapon does multiple types? How to identify cells in Column A that contain any of the values in Column B First off, I'm not that advanced of an Excel user. I'm certain Excel can do what I'm about to ask, but I've yet to find a way in any of my attempts or searches.  My question is very similar to  except that A) the answers there didn't work for me, and B) even if it did, it's not quite the correct output I need.   Basically, I have 2 columns. Column A contains URLs (16388 rows). Column B contains URL slugs (202 rows).   I want to search to see if any of the values in column B are contained within any of the values of Column A. If they are, I want to return the value TRUE in column C.   From what I've read, VLOOKUP ought to work for this, but for the life of me I can't get it to work. I also tried in the answers in the link above that use COUNTIF and MATCH, but in both of those cases, all I got were FALSE returns, when I know that there are values in Column B that are contained in a URL in Column A.   Does that make sense?  EDIT: Both answers are providing results (thank you!), but I suspect I may not have asked the question correctly. In both of the answers, I'm getting TRUE results, but it looks like the TRUE is correlating to the slug in Column B rather than the URL in Column A. Let me put it this way:  I'll move the slugs from Column B to C so that B can be used for the TRUE responses. What I want the fomula to do is:   Look at URL in A1 Are any of the values in Column C contained within the URL in A1? If yes, then return TRUE in B1. If FALSE, leave it blank.    So I will be able to see which of the URLs contain the slugs I am searching for. I apologize for not being clearer in my original ask (though I feel like it's only a slight tweak from the answers I've already been given.) Do I need Intel Smart Response when installing Ubuntu? CSS two divs next to each other I want to put two &lt;div&gt;s next to each other. The right &lt;div&gt; is about 200px; and the left &lt;div&gt; must fill up the rest of the screen width? How can I do this? PDF video Embedding Problem match first column of file a with paragraphs of file b I have 2 files. The first, fileA looks like  TCONS_00000066  XLOC_000030     -       u       q1:XLOC_000030|TCONS_00000066|0|0.000000|0.000000|0.000000|0.000000|- TCONS_00000130  XLOC_000057     -       u       q1:XLOC_000057|TCONS_00000130|0|0.000000|0.000000|0.000000|0.000000|- TCONS_00000395  XLOC_000206     -       u       q1:XLOC_000204|TCONS_00000393|0|0.000000|0.000000|0.000000|0.000000|-   FileB looks like:  &gt;TCONS_00000001 gene=XLOC_000001 AGATGAGCTGGTGGGGATGCTCTAAGAGAACGAGAGAAGCACAGAGCAGATAAACCACACCCACAGGCAC CACCGTCCTTGTTGGTAATGAAGAAGACGAGACGACGACTTCCCCACTAGGAAACACGACGGAGGCGGAG ATGATCGACGGCGGAGAGAGCTACAGAAACATCGATGCCTCCTGTCCAATCCCCCCATCCCATTCGGTAG TTGGATTGAAGACTACCGAATAAGAGAAGCAGGCAGGCAGACAAACCCTTGAACCAAGGAGTCCTCGCTG AGGAAGCTTTGGATCCACGACGCAGCTATGGCCTCCCCGCCCACCAGGCCGCCAGCCACAACCAGCTGAC TAGGTCGCATGCATCATCAGATTTCAATCTCCCTTCGTTCCCTGTCCCTAATCCAATACCAATAGGGAGC AATCAGCTGCTCCTCGACGGCGAGGGAGATGTCGTCGGCCGCGGGCCAAGACAACGGAGATACCGCTGGG GACTACATCAAGTGGATGTGCGGCGCCGGTGGCCGTGCGGGCGGCGCCATGGCCAACCTCCAGCGCGGCG TTGGCTCCCTCGTCCGTGACATTGGCGACCCCTGCCTCAACCCATCCCCCGTTAAGGGGAGCAAAATGCT CAAACCGGAAAAATGGCACACATGTTTTGATAATGATGGAAAGGTCATAGGTTTCCGTAAAGCCCTAAAA TTCATTGTCTTAGGGGGTGTGGATCCCACTATTCGAGCTGAAGTTTGGGAATTTCTTCTTGGCTGCTATG CCTTGAGTAGTACCTCAGAGTATAGGAGGAAACTAAGAGCTGTTAGAAGGGAAAAATATCAAATTTTAGT TAGACAGTGCCAGAGCATGCACCCAAGCATTGGTACAGGTGAGCTTGCTTACGCTGTTGGATCAAAGCTA   Now, fileA contains selected transcript numbers in the first column and fileB contains sequences of all transcripts. I want to scan fileB for the first column of fileA and print the trailing sequences of matching transcripts along with the transcript number. How do I capture the moon and its surrounding context? I wanted to photograph the full moon against a beautiful deep blue sky. I ended up with blown-out highlights of the moon:    So I switched to spot metering and captured the moon, losing the blue sky in the process:    I want a single photo that shows both the moon and the surrounding context (in this case, the blue sky). Doing an exposure fusion in Photomatix Essentials did not help:    Nor did HDR fusion (again in Photomatix):    Notice that the detail in the moon was lost in both cases, and the sky was also messed up in both cases: exposure fusion lost the beautiful blue color, while HDR created more texture than was actually present in the sky. I toggled Photomatix's option to remove ghosts, but that didn't help, either.  How do I photograph the moon together with its surrounding context (in this case, the blue sky, but in other cases, a tree, buildings, etc) without blowing highlights or shadows? I'm using a Sony NEX-5R, with the longest focal length lens I have, and with manual focus when needed.  Thinking I should fuse the photos manually, I tried opening the images as layers in Acorn, with the darker photo on top and with opacity set to 50%, and tried all 15 - 20 blending modes (normal, dodge, lighter, darker, multiply and so on), but none of them seemed to work. I'm afraid I don't know enough to use layers effectively. What blending mode and opacity and order of layers should I use for this task?  I don't have Photoshop, but do have Lightroom 5, Acorn and Nik Collection.  (In case you are about to recommend software, please note my requirements: I use a Mac, I would be willing to pay $20-30, and I don't want to use command-line software.) What is the meaning of the density of a distribution at a point? I know how to use PDFs to calculate probabilities, but I don't think I understand them. For example, at $X=0$ the PDF of the standard normal distribution is $\approx 0.4$. Does this have any useful meaning? What theorems can I use to prove this? How precisely do I need to post close to 7:00 (somewhere) to get hero of time? Difference between >> and >>> in verilog? How many files can a windows folder contain?  This question is asked  but then the question text pollutes the question with issues of "rules of thumb"  So to be clear, this question is: How many files can a windows folder contain?