Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have a SOQL in a loop.</p> <pre><code>for (Bids__c bid : recentBids){ String recentProfileName = [SELECT Profile.Name FROM User Where Id = :bid.CreatedById LIMIT 1].Profile.Name; String bidId = profilePrefixMap.get(recentProfileName); bid.Bid_unique_label__c = ((bidId == null) ? defaultPrefix : bidId); } upsert recentBids; </code></pre> <p>This is a performance killer and in fact I'm surprised the limit is 100 queries, used to be no more than 20 queries in a trigger context. A quick fix for your problem would be to use relationship queries with the "dot notation". This will eliminate the need to make the query in a loop.</p> <pre><code>List&lt;Bids__c&gt; recentBids = [SELECT Id, CreatedBy.Profile.Name, Bid_unique_label__c FROM Bids__c WHERE Bid_unique_label__c = NULL]; for (Bids__c bid : recentBids){ String recentProfileName = bid.CreatedBy.Profile.Name; String bidId = profilePrefixMap.get(recentProfileName); bid.Bid_unique_label__c = ((bidId == null) ? defaultPrefix : bidId); } upsert recentBids; </code></pre> <p>This code still has some problems. </p> <ol> <li>You might hit a limit of no more than 10K rows inserted/updated in single transaction (you should at least add LIMIT clause). </li> <li>You're mixing work on data that's in the context of the trigger with data fixes on some unrelated stuff. You shouldn't "piggyback" because users won't understand why they see an error coming from data they didn't touch. </li> <li>Not to mention the fact that "last modified by" is now worthless in your system.</li> </ol> <p>If it's one time activity to clean up your bad data (fix unique labels) - consider running a data fix and removing this code. If it's really a recurring situation - write a batch job. </p> <p>Or investigate if you can write a workflow rule to generate the unique keys, looks like it's be doable and config beats coding a solution.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload