• Deb Flores
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies

Hi all,

 

If anyone could offer some advice I'd really appreciate it.  My trigger is getting the following error: 

Apex script unhandled trigger exception by user/organization: 00540000000rfc7/00D300000000WHR

UpdateAssetNames: execution of BeforeUpdate

Caused by: System.Exception: Too many SOQL queries: 21

Trigger.UpdateAssetNames: line 20, column 20

The trigger updates associated Assets when an Account Name is updated.  I thought I'd set it up to process the records in bulk, but evidently I'm doing something wrong:

 

trigger UpdateAssetNames on Account (before update) {

 

// Assemble Accounts with new Names

 

Map<Id, Account> acctsWithNewNames = new Map<Id, Account>();

 

// Trigger.new - list of the Accounts

// Loop iterates over the list, and adds any that have new

// names to the acctsWithNewNames map.

 

for (Integer i = 0; i < Trigger.new.size(); i++) { if ( (Trigger.old[i].Name != Trigger.new[i].Name)) {

 

acctsWithNewNames.put(Trigger.old[i].id, Trigger.new[i]);

}

}

 

List<Asset> updatedAssets = new List<Asset>();

 

for (Asset a : [SELECT id, accountId, Name FROM asset WHERE accountId in :acctsWithNewNames.keySet()]) {

 

Account parentAccount = acctsWithNewNames.get(a.accountId);a.Name = parentAccount.Name;

 

updatedAssets.add(a);

}

update updatedAssets;

}

 Many thanks in advance!

 

Deb

Hi , 

I am writing single email message to code to send emails. I am dynamically constructing toAddresses to send emails. The code is working fine and sending email to toAddresses and setTargetobjectid. 

I don't want to send email to setTargetobjectId. is there any way to stop sending email to setTargetobjectid?

Thanks
Siva.

Hi all,

 

If anyone could offer some advice I'd really appreciate it.  My trigger is getting the following error: 

Apex script unhandled trigger exception by user/organization: 00540000000rfc7/00D300000000WHR

UpdateAssetNames: execution of BeforeUpdate

Caused by: System.Exception: Too many SOQL queries: 21

Trigger.UpdateAssetNames: line 20, column 20

The trigger updates associated Assets when an Account Name is updated.  I thought I'd set it up to process the records in bulk, but evidently I'm doing something wrong:

 

trigger UpdateAssetNames on Account (before update) {

 

// Assemble Accounts with new Names

 

Map<Id, Account> acctsWithNewNames = new Map<Id, Account>();

 

// Trigger.new - list of the Accounts

// Loop iterates over the list, and adds any that have new

// names to the acctsWithNewNames map.

 

for (Integer i = 0; i < Trigger.new.size(); i++) { if ( (Trigger.old[i].Name != Trigger.new[i].Name)) {

 

acctsWithNewNames.put(Trigger.old[i].id, Trigger.new[i]);

}

}

 

List<Asset> updatedAssets = new List<Asset>();

 

for (Asset a : [SELECT id, accountId, Name FROM asset WHERE accountId in :acctsWithNewNames.keySet()]) {

 

Account parentAccount = acctsWithNewNames.get(a.accountId);a.Name = parentAccount.Name;

 

updatedAssets.add(a);

}

update updatedAssets;

}

 Many thanks in advance!

 

Deb