Hello) I need to create a trigger that will record the number of reviews and the average rating from custom object (Review__c) in the corresponding fields on other custom object (Job_Applications__c). The trigger works, but throws an exception when testing to insert a large number of records (LimitException: Too many SOQL queries: 101). I understand this is because of my query in a loop. How can I pull SOQL-query out of the loop? trigger ReviewSetRatingTrigger on Review__c (after insert, after update) { List&lt;Job_Application__c&gt; updList = new List&lt;Job_Application__c&gt;();  List&lt;Review__c&gt; newList = new List&lt;Review__c&gt;([     SELECT Id, Rate__c, Job_Application__r.Id, Job_Application__r.Reviews_Count__c, Job_Application__r.Average_Rate__c     FROM Review__c     WHERE Id IN : Trigger.new ]);  for(Review__c rev : newList) {     List&lt;Review__c&gt; tempList = new List&lt;Review__c&gt;([ //Find reviews count and their summ         SELECT Rate__c         FROM Review__c          WHERE Job_Application__r.Id =: rev.Job_Application__r.Id     ]);     Integer revCount = 0;     Decimal rateSum = 0;     for(Review__c upd : tempList) {         revCount++;         rateSum += upd.Rate__c;     }      if(rev.Job_Application__r.Average_Rate__c == null) {         rev.Job_Application__r.Average_Rate__c = rev.Rate__c;         rev.Job_Application__r.Reviews_Count__c = 1;     } else {         rev.Job_Application__r.Average_Rate__c = rateSum / revCount;         rev.Job_Application__r.Reviews_Count__c = (Trigger.isInsert)? rev.Job_Application__r.Reviews_Count__c + 1 : tempList.size();     }         updList.add(rev.Job_Application__r);      System.debug(rev.Job_Application__r); }   update updList;  }
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, navigate to the  tag. This question and answer is owned by the community! If you can improve it and make it more useful, you're welcome to edit it. I have a collection of records, like a List&lt;sObject&gt; or the Trigger.new context variable. I need to query other records that are related to these records either directly or indirectly, and I want to use the related data to make further updates. When I write a query in a loop, like for (Account a : Trigger.new) {     Account parent = [SELECT Name FROM Account WHERE Id = :a.ParentId];     // ... }  I keep hitting Salesforce query limits, and I know this is not best practice. What can I do to avoid this problem and bulkify my code?
Is $A\triangle B := A\cup B-A\cap B $ a suitable definition for the symmetric difference of two sets $A$ and $B?$ Or is $A\triangle B := (A-B) \cup (B-A) $ only allowed? I'm taking an electronic circuit analysis class, and I was asked to give the color of the 3rd band of a 1MΩ resistor. My answer was blue, thinking it could be black-brown-blue (01 * 1MΩ), but the automated quiz said the correct answer was green (brown-black-green).  So I did some research, thinking there were just multiple correct answers, and I read in a few places that the first band on a resistor is never black (0). Why is this? Does a black first band have some other meaning? It would really help me remember it if I knew the history or reasoning behind it.  This question has been answered. For further reading on zero-ohm resistors mentioned in the answers and comments here, I found these questions and answers helpful: Copy and set-mark in Bash as in Emacs? I would like to be able to copy and paste text in the command line in Bash using the same keyboard bindings that Emacs uses by default (i.e. using C-space for set-mark, M-w to copy text, C-y, M-y to paste it, etc.).  The  says that Bash comes with some of these key bindings set up by default.   For example, yanking (C-y) works by default on my terminal. However, I can't get the set-mark and copy commands to work, and they don't seem to be bound to any keys by default.  Usually, the way a user can define her own key bindings is to add them to .inputrc. So I looked and found the following bash functions in the documentation that I presume can help me define the Emacs-like behavior that I want (i.e. set-mark with C-space and copy with M-w).  copy-region-as-kill ()      Copy the text in the region to the   kill buffer, so it can be yanked right   away. By default, this command is   unbound.   and    set-mark (C-@)      Set the mark to the point. If a   numeric argument is supplied, the mark   is set to that position.   If I understand correctly, the above means that copy-region-as-kill is not bound to any keyboard sequence by default, while set-mark is bound to C-@ by default.   I tried C-@ on my terminal, but I don't think it runs set-mark because I don't see any text highlighted when I move my cursor. In any case, I tried adding  keyboard bindings (M-w and C-) to the functions  copy-region-as-kill and set-mark above in my .inputrc and then reloading it with C-x C-r, but this didn't work. I know that my other entries in .inputrc work because I have other user-defined keybindings defined in it.  Is there anything I am doing wrong? Am I missing anything? Need hint: Determine whether the series $\sum_{n=1}^{\infty}(\frac{n}{n+1})^{n^2}$ is convergent or divergent. When a body lies on the surface of the Earth it is under the influence of gravity. The force on the body due to gravity causes it to exert a force on the ground and the normal reaction acts in the opposite direction causing the resultant force on the body to be zero.  However, how can the body exert a force on the ground when it does not have any acceleration? Since force equals mass times acceleration how does a body without acceleration experience a force? I'm looking for a good, consistent and easy way to do a report of sudoers permissions for every user and group on the system. For users, I want the report to include permissions granted via group membership. I recently dismissed Dogmeat in favor of Codsworth, and I'm fairly sure I sent him to Sanctuary Hills. However, I've had a fairly detailed look around the place and I haven't found him yet. Does anyone know where he is? How to reduce fireflies in Cycles? I often use Cycles' built in Glass BSDF shader to achieve realistic refraction effects, but in many cases, it seems that Cycles' glass caustics creates an unfortunately large number of fireflies (pixels that are abnormally bright relative to their surroundings). In some models of mine, even when I render for 3000 or more samples/pixel, my final image is still covered in fireflies. While I can improve this in many cases by increasing the total amount of light available in the scene, this loses a lot of the potency of the refractive effects I'm looking for, especially in scenes with low light levels.  So my question is, how can I reduce the amount of fireflies while using Cycles' caustics without sacrificing the quality of the refractive effects?  Note: I am aware that Cycles' caustics will perform much better once Cycles has full support for bidirectional path-tracing, but it looks unlikely that that will become , unfortunately. Provide two arguments to one option using getopts In below code when I give option r then getopts requires one arguments:  while getopts ":hr::l:" opt; do     case $opt in         r ) echo "Run Numbers - argument = $OPTARG " ;;         l ) echo "Latency range - argument = $OPTARG" ;;         h ) helptext             graceful_exit ;;         * ) usage             clean_up             exit 1     esac done   But I need to pass two arguments after -r option, instead of one. Is there an easy way to do this? GCD of two numbers divided by their greatest common divisor is 1 Where do the X-Men get all their money/funding? Charles Xavier's father was a "wealthy nuclear scientist". In the beginning, Charles personally bankrolled the Xavier Institute/X-Men using his family's money.   This included, but was not limited to things like upgrading the mansion to house the training levels, providing a helicopter (the predecessor to the Blackbird jet), providing and replacing uniforms, providing health care for injured students, and rebuilding/repairing the mansion and parts of the Danger Room  repeatedly.  These have all been recurring costs. The mansion has been damaged or outright destroyed a ridiculous number of times. X-Men can't get into a fight without someone's uniform getting damaged.   In one of the more recent stories (I believe it was an early issue of Wolverine &amp; The X-Men), a comment is made about how the X-Men are pretty much bankrupt.  Where has all this money come from over all these years?   Xavier may have had a large war chest to start with, but no other income has ever been mentioned to my knowledge. Student's tuition could account for some of it, but there's no way that's going to fund everything. I understand how Insight and Perception can be used passively: for the DM to determine if an enemy Deception or Stealth attempt is successful without alerting the players that someone is deceiving or sneaking.    But the Observant feat in the Player's Handbook states:      [...] You have a +5 bonus to your passive Wisdom (Perception) and passive Intelligence (Investigation) scores.     So in what situation would a DM be rolling something against the player's Investigation without letting them know? I’m using tikz-cd for diagrams, and have a medium-sized diagram that I want to re-use several times.  However, when I try using a definition like:  \newcommand{\myarrow}{$\begin{tikzcd} A \ar{r} &amp; B \end{tikzcd}$   I get an error:  ERROR: Package pgfbasematrix Error: Single ampersand used with wrong catcode.   Is it possible to put a tikz-cd diagram into a defined command somehow? Duplication formula for gamma function Using the  for $\Gamma(x)$ and $\Gamma\Big(x + \frac12\Big)$, how can I prove the ? This is problem $10.7.3$ in the book , by Boros and Moll.  Any help is highly appreciated. I got the brand new Custodian badge today for reviewing posts. Inspired by that, I reviewed some more suggested edits. Now I ran into a limit:     You have no more suggested edit votes today; come back in x hours.   How is that limit calculated? I made 61 reviews today which seems to be some calculated limit.  I searched for an answer on meta but found nothing helpful. How was the Cloak of Invisibility Created? “Airplane Mode” in OS X. Alternative command for `rfkill`? Mac OS X doesn't recognize rfkill from its terminal, and I am looking for an alternative command that has similar functionality (toggling "Airplane Mode").  NOTE: I don't wish to open an .app to toggle. I'd like to execute the command from command line or within script in Bash (or equivalents).    By "Airplane Mode", I meant to borrow the term from iOS support page . I would like to disable all incoming/outgoing network communications from my system. Regex exec only returning first match Travelling as unmarried couple in Dubai When I'm sneaking around, I can move more slowly and quietly by holding shift.   But walking this way is really slow. I would like to move a little bit faster, but not full speed.    On a console I imagine you have much finer control over how fast you move with the joysticks. Is there any way to accomplish this on the PC (without an external joystick)?  Perhaps there is a console command or config file setting that will change the % speed modifier that holding down shift uses?