I'm trying to write a test for this and I can't get anything under line 6 (for) to test. trigger createPriceBookEntry on Product2 (after insert) {          List&lt;priceBookEntry&gt; priceBookEntryList= new List&lt;priceBookEntry&gt;();          String pricebkId= [SELECT id from Pricebook2 where isStandard=true][0].Id;     for(Product2 prod: trigger.new){         priceBookEntry priceBkEntry= new priceBookEntry();         priceBkEntry.Product2Id= prod.Id;         priceBkEntry.Pricebook2Id= pricebkId;         priceBkEntry.IsActive= True;         priceBkEntry.UnitPrice= 1; // Dummy Value         priceBkEntry.UseStandardPrice= False;         priceBookEntryList.add(priceBkEntry);     }     if(priceBookEntryList.size()&gt;0){         insert priceBookEntryList;     } }  How would I go about testing this? I can insert a product but not sure how I'd be able to deploy this.
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 is code coverage obtained and calculated? How do I increase my coverage?  Why can't I cover these lines? Why isn't the body of my loop or conditional statement covered?
Command-line-friendly full-text indexing? Is there such a thing as a full-text indexing engine, that can be queried from the command line and ideally wouldn't require using a gui at all ?  I'm especially interested in indexing my ebooks and papers, so that's a mixture of pdf, epub and a few djvu. (Open)Office docs would be nice, but much lower on my list. I was trying to install Teamviewer, but I was getting a dependency error. I tried to install the required packages, but with no luck.  I'm getting this error:  Unpacking teamviewer (from teamviewer_linux_x64.deb) ... dpkg: dependency problems prevent configuration of teamviewer:  teamviewer depends on lib32asound2; however:   Package lib32asound2 is not installed.  teamviewer depends on lib32z1; however:   Package lib32z1 is not installed.  teamviewer depends on ia32-libs; however:   Package ia32-libs is not installed.  dpkg: error processing teamviewer (--install):  dependency problems - leaving unconfigured Errors were encountered while processing:  teamviewer   I tried   sudo apt-get -f install   Getting   Package ia32-libs is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source However the following packages replace it:   lib32z1 lib32ncurses5 lib32bz2-1.0  Package lib32asound2 is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source  E: Package 'lib32asound2' has no installation candidate E: Package 'ia32-libs' has no installation candidate   I can't even get to the   sudo dpkg -i teamviewer_linux_x64.deb   If I force installation  sudo dpkg --force-depends -i teamviewer_linux_x64.deb   Although it's "Setting up Temviewer" it gives me this:    How can I fix this problem? Debug a java application without starting the JVM with debug arguments Normally to attach a debuger to a running jvm you would need start the jvm with arguments such as the following:  &gt; java -Xdebug -Xrunjdwp:transport=dt_socket,address=1000,server=y,suspend=n   Now if I want to debug a process that wasn't started in debug mode, what can I do?  This situation arrises when a production system (i.e. started without debug args) exhibits a 'random' (I use the term loosely) bug. So I can't restart the jvm with the appropriate arguments, because nobody knows how to reproduce the bug again. Is it impossible to attach to the JVM in this situation?  Just to clarify it is not possible to use tools like jdb to attach to already running JVMs unless they were started in debug mode  from the JVM man page     Another way to use jdb is by attaching it to a Java VM that is   already running. A VM that is to be   debugged with jdb must be started with   the following options: Can I take clear night sky photographs with my smartphone? is it possible to take clear night sky shots with stars/ planets visible from Redmi Note 4? what settings do I use? when I try to take it just comes black, unless on full moon day with HDR, though stars like Orion's belt won't get captured. Would using a telescope make celestial objects much clear to capture? How to find the roots of $x^4 +1$ I'm trying to find the roots of $x^4+1$. I've already found in this site solutions for polynomials like this $x^n+a$, where $a$ is a negative term. I don't remember how to solve an equation when $a$ is a positive term as the equation above.  Thanks On what site can I ask questions related to copyright? I want to make a summary of a book and use it to earn money. However, I don't know whether it's legal or not.  Which Stack Exchange site can I ask this question on? Homebrew putty installation does not make the putty command recognisable I would like to instal  with use of Homebrew. I'm performing the following command:  brew install putty   which gives the seemingly correct output:  ==&gt; Downloading https://homebrew.bintray.com/bottles/putty-0.67.el_capitan.bottle.tar.gz Already downloaded: /Users/thisuser/Library/Caches/Homebrew/putty-0.67.el_capitan.bottle.tar.gz ==&gt; Pouring putty-0.67.el_capitan.bottle.tar.gz 🍺  /usr/local/Cellar/putty/0.67: 11 files, 1.5M   However, the putty command is not recognised:  thisuser-541/41:~$ putty -bash: putty: command not found Android - Read Only File System IOException Any good tutorials for learning how to post-process images? I don't really know where to start with post-processing my images. I normally just straighten, crop and sharpen. Do people know of any good resources on the internet for getting a grip with Photoshop and similar tools? How to make excel automatically fill a value in a cell of a sheet when another corresponding cell of another sheet is filled the same value? What is the difference between an int and an Integer in Java and C#? How to remove the switch user account option in Unity 2D? We are looking for a way to permanently remove the Switch User Account function from our install of Ubuntu Unity. Note, this function appears when you right or left click on the user name in the upper right-hand corner. It then displays a list of 5-10 users that have logged in along with the option to Switch User Account. We know that we can do this by defaulting to gnome, but we would like the option of using Unity as well, but without the Switch User Account option.  We have already tried dconf-editor, gsettings and several other options to remove the users name list, Switch User Account option from appearing in the drop-down list. We know this can be done for one user at a time, but we are wanting to do this for all users on roughly 160 workstations.  Some options that we have already tried are:       This is a visual of what we are trying to remove: Why is LaTeX3 taking so long to come out? I feel as though I have been hearing about the LaTeX3 project for a very long time.   Why is it taking so long for it to come into fruition? Are there major technical difficulties, or is it purely a lack of developers that is causing a bottleneck? How to prove that 2017 divides $1^{2017}+2^{2017}+\dots+2017^{2017}$? How can I prove that $2017 \mid 1^{2017}+2^{2017}+\dots+2017^{2017}$? I tried proving it with the use of modulo, however it was to no avail. Afterwards, I  tried researching, for possible theorems, that may help, but that bore no fruit, either. Can you guys please help me proving it, as I am stuck? Thanking you in advance. Theorem style with name as argument Is there some way to get a theorem type which will make a theorem with the name passed as a parameter? In other words, is there a way to define "named" such that   \begin{named}[NAME] text \end{named}   will print   "NAME: text"?  I tried using the definition \newtheorem*{named}{}, but that results in   "(NAME): text", which is quite different from what I am trying to do.  I know that I could also create a new instance of \newtheorem for each named theorem I want to use, but that is clunky and inconvenient. Is there a better way? Error: j_id0:j_id1:j_id28:j_id30: Validation Error: Value is required I've been studying the postulates of QM and seeing how to derive important ideas from them. One thing that I haven't been able to derive from them, however, is the identity of the momentum operator.  For simplicity, I'm only thinking about no relativistic effects, no spin, no time-dependent potentials, and one spatial dimension. Also I'm assuming the position operator is simply multiplication by $x$, as in, I'm in position space. So the Hamiltonian operator is  $ H = -\frac{\hbar^2}{2m}\nabla^2+V$.  I know that the momentum operator is $p = -i\hbar \frac{\partial}{\partial x}$.  But how do I get there from the postulates? I know that it makes sense, as it results in the Ehrenfest Theorem, the De Broglie wavelength hypothesis, the Heisenberg Uncertainty Principle (for $x$ and $p$), the momentum operator being the generator of the translation operator, and possibly many other desirable theorems, and correlations with classical momentum.  But none of these are postulates (at least, not in the various formalisms I encountered), so you can't derive $p = -i\hbar \frac{\partial}{\partial x}$ from them. Rather, they are consequences of it. You need to know the operator beforehand to see that they are correct. Yes, this is just semantics, but that is the core issue for me:  Regardless of how much sense it makes, is the identity $p = -i\hbar \frac{\partial}{\partial x}$ (under the assumptions I made) a Postulate, meaning that you can't derive it from other postulates, or can it in fact be obtained from them? And in the latter case, could you show me how?  Note: I know that there are many different and equivalent sets of postulates for QM. But in none that I saw did they name it as a postulate nor properly derived it. Don't automatically edit the post to insert "possible duplicate" links When a question is closed as a duplicate, its body is edited to auto-insert the link to that duplicate. I think there are a couple problems with that:   If the question is reopened, the auto-generated insert isn't automatically removed. It allows the poster (or anyone else) to roll back the post and protest the closure by reverting the automatic edit.    I propose that the links to the duplicate(s) are moved into a separate "header" field above the post instead of being edited into the body of the question. That way it could be removed or hidden if the question is reopened and it could not be edited or reverted without reopening the question.   There is some potential for loss of functionality there, since right now it is possible to edit the post to either include additional related links or remove obsolete/incorrect ones. That could be addressed by making the "duplicate field" editable at a certain reputation level (10k?) and enabling others to suggest edits for it that'd go through the usual approval/rejection process.  Thoughts? Foreign key constraints failures Given the following tables:  CREATE TABLE `longdescs` (   `comment_id` int(11) NOT NULL AUTO_INCREMENT,   `bug_id` mediumint(9) NOT NULL,   `who` mediumint(9) NOT NULL,   `bug_when` datetime NOT NULL,   `work_time` decimal(7,2) NOT NULL DEFAULT '0.00',   `thetext` mediumtext NOT NULL,   `isprivate` tinyint(4) NOT NULL DEFAULT '0',   `already_wrapped` tinyint(4) NOT NULL DEFAULT '0',   `type` smallint(6) NOT NULL DEFAULT '0',   `extra_data` varchar(255) DEFAULT NULL,   PRIMARY KEY (`comment_id`),   KEY `longdescs_bug_id_idx` (`bug_id`),   KEY `longdescs_who_idx` (`who`,`bug_id`),   KEY `longdescs_bug_when_idx` (`bug_when`),   KEY `comment_id` (`comment_id`),   CONSTRAINT `fk_longdescs_bug_id_bugs_bug_id` FOREIGN KEY (`bug_id`) REFERENCES `bugs` (`bug_id`) ON DELETE CASCADE ON UPDATE CASCADE,   CONSTRAINT `fk_longdescs_who_profiles_userid` FOREIGN KEY (`who`) REFERENCES `profiles` (`userid`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=82727 DEFAULT CHARSET=utf8  CREATE TABLE `trace` (   `id` mediumint(9) NOT NULL AUTO_INCREMENT,   `comment_id` mediumint(9) NOT NULL,   `type` varchar(255) NOT NULL,   `short_hash` char(22) DEFAULT NULL,   `stack_hash` char(22) DEFAULT NULL,   `trace_text` mediumtext NOT NULL,   `quality` double NOT NULL,   PRIMARY KEY (`id`),   UNIQUE KEY `trace_comment_id_idx` (`comment_id`),   KEY `trace_short_hash_idx` (`short_hash`),   KEY `trace_stack_hash_idx` (`stack_hash`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8  ALTER TABLE trace ADD CONSTRAINT `fk_trace_comment_id_longdescs_comment_id` FOREIGN KEY (`comment_id`) REFERENCES `longdescs`(`comment_id`) ON UPDATE CASCADE ON DELETE CASCADE; ERROR 1005 (HY000): Can't create table 'bugs4.#sql-4bb_6f1d' (errno: 150)   MariaDB [bugs4]> show warnings;  | Level  | Code | Message | | Warning |  150 | Create table 'bugs4/#sql-4bb_6f1d' with foreign key     constraint failed. There is no index in the referenced table where the referenced columns appear as the first columns.  | | Error   | 1005 | Can't create table 'bugs4.#sql-4bb_6f1d' (errno: 150)                                                                                                                       |   Any idea why I get that error? FYI I looked it up and it appears that it was a bug but not anymore. I have 16GB RAM. Do I need 32GB swap?