- muhammadb1.3970135761364219E12
- NEWBIE
- 10 Points
- Member since 2014
-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
2Questions
-
7Replies
Account Trigger error - Too many SOQL queries: 101
Hi,
I have a trigger on Account which just update one field in all the related contacts. If the account is of type "Member" then the trigger updates a field in contact called "Relationship_Category_r__c" to "Member-staff" and if the Account type changes to "Member-past" then the contact field updates to "Member-past"
The trigger below is working fine if the number of contacts in any account is in between 50 - 80. However, it stops working when it exceed more than that. I can't give the exact number but its not working with our account which has around 116 contacts.
I am copying the code below for reference and any advise would be highly appreciated
trigger Update_related_Contacts_On_Account_fieldchange on Account (after update) {
set<id> ids=new set<id>();
for(Account acc:trigger.new){
ids.add(acc.id);
}
map<id,List<contact>> acc_con_maps=new map<id,List<contact>>();
List<Account> accts=new List<Account>([select id,(select id,Relationship_Category_r__c from contacts) from Account where id=:ids]);
For(Account accts1:accts){
acc_con_maps.put(accts1.id,accts1.contacts);
}
list<contact> constoupdate=new list<contact>();
for(Account acc1:trigger.new){
if(acc_con_maps.containsKey(acc1.Id)&&acc_con_maps.get(acc1.id)!=null){
if(acc1.Type=='Member'){
for(contact con:acc_con_maps.get(acc1.Id)){
if(con.Relationship_Category_r__c !='Member'){
con.Relationship_Category_r__c ='Member - Staff';
constoupdate.add(con);
}
}
}
else if(acc1.type=='Member - Past'){
for(contact con1:acc_con_maps.get(acc1.Id)){
if(con1.Relationship_Category_r__c !='Member - Past'){
con1.Relationship_Category_r__c ='Member - Past';
constoupdate.add(con1);
}
}
}
}
}
update constoupdate;
}
I have a trigger on Account which just update one field in all the related contacts. If the account is of type "Member" then the trigger updates a field in contact called "Relationship_Category_r__c" to "Member-staff" and if the Account type changes to "Member-past" then the contact field updates to "Member-past"
The trigger below is working fine if the number of contacts in any account is in between 50 - 80. However, it stops working when it exceed more than that. I can't give the exact number but its not working with our account which has around 116 contacts.
I am copying the code below for reference and any advise would be highly appreciated
trigger Update_related_Contacts_On_Account_fieldchange on Account (after update) {
set<id> ids=new set<id>();
for(Account acc:trigger.new){
ids.add(acc.id);
}
map<id,List<contact>> acc_con_maps=new map<id,List<contact>>();
List<Account> accts=new List<Account>([select id,(select id,Relationship_Category_r__c from contacts) from Account where id=:ids]);
For(Account accts1:accts){
acc_con_maps.put(accts1.id,accts1.contacts);
}
list<contact> constoupdate=new list<contact>();
for(Account acc1:trigger.new){
if(acc_con_maps.containsKey(acc1.Id)&&acc_con_maps.get(acc1.id)!=null){
if(acc1.Type=='Member'){
for(contact con:acc_con_maps.get(acc1.Id)){
if(con.Relationship_Category_r__c !='Member'){
con.Relationship_Category_r__c ='Member - Staff';
constoupdate.add(con);
}
}
}
else if(acc1.type=='Member - Past'){
for(contact con1:acc_con_maps.get(acc1.Id)){
if(con1.Relationship_Category_r__c !='Member - Past'){
con1.Relationship_Category_r__c ='Member - Past';
constoupdate.add(con1);
}
}
}
}
}
update constoupdate;
}
-
- muhammadb1.3970135761364219E12
- May 20, 2014
- Like
- 0
- Continue reading or reply
Account Trigger that update all contacts - Too many SOQL queries: 101
Hi,
I have a trigger that runs after updating any account and it actually just updates a field (Relationship_category_r__c) in all the related contacts after few conditions.
Condition1: If we update the account type to "Member"
Condition2: If the contact doesn't have "Member" already in the (Relationship_category_r__c) field
ACTION: Update the contact Relationship_Category_r__c field to "Member - staff"
Condition2: If we update the account type to "Member - past"
ACTION: Update all the contacts Relationship_Category_r__c field to "Member - past"
The trigger works absolutely find when the account has less than 25 to 50 contacts but it generates an error when we have an account more than 55 or so contacts
ERROR: Apex trigger UpdateAllContacts caused an unexpected exception, contact your administrator: UpdateAllContacts: System.LimitException: Too many SOQL queries: 101
======================================= TRIGGER ==============================
trigger UpdateAllContacts on Account (after update) {
for(Account acc : Trigger.New){
List<Contact> listCon = [Select id, Relationship_Category_r__c from Contact where AccountId =: acc.id];
for(Contact con : listCon)
{
if (acc.Type=='Member'){
if(con.Relationship_Category_r__c != 'Member'){
con.Relationship_Category_r__c = 'Member - staff';
}
}
else if (acc.Type=='Member - past'){
con.Relationship_Category_r__c = 'Member - past';
}
}
try {
update listCon;
}
catch (DmlException e) {}
}
}
Any help will be greatly appreciated
Thanks
I have a trigger that runs after updating any account and it actually just updates a field (Relationship_category_r__c) in all the related contacts after few conditions.
Condition1: If we update the account type to "Member"
Condition2: If the contact doesn't have "Member" already in the (Relationship_category_r__c) field
ACTION: Update the contact Relationship_Category_r__c field to "Member - staff"
Condition2: If we update the account type to "Member - past"
ACTION: Update all the contacts Relationship_Category_r__c field to "Member - past"
The trigger works absolutely find when the account has less than 25 to 50 contacts but it generates an error when we have an account more than 55 or so contacts
ERROR: Apex trigger UpdateAllContacts caused an unexpected exception, contact your administrator: UpdateAllContacts: System.LimitException: Too many SOQL queries: 101
======================================= TRIGGER ==============================
trigger UpdateAllContacts on Account (after update) {
for(Account acc : Trigger.New){
List<Contact> listCon = [Select id, Relationship_Category_r__c from Contact where AccountId =: acc.id];
for(Contact con : listCon)
{
if (acc.Type=='Member'){
if(con.Relationship_Category_r__c != 'Member'){
con.Relationship_Category_r__c = 'Member - staff';
}
}
else if (acc.Type=='Member - past'){
con.Relationship_Category_r__c = 'Member - past';
}
}
try {
update listCon;
}
catch (DmlException e) {}
}
}
Any help will be greatly appreciated
Thanks
-
- muhammadb1.3970135761364219E12
- April 09, 2014
- Like
- 0
- Continue reading or reply
Account Trigger error - Too many SOQL queries: 101
Hi,
I have a trigger on Account which just update one field in all the related contacts. If the account is of type "Member" then the trigger updates a field in contact called "Relationship_Category_r__c" to "Member-staff" and if the Account type changes to "Member-past" then the contact field updates to "Member-past"
The trigger below is working fine if the number of contacts in any account is in between 50 - 80. However, it stops working when it exceed more than that. I can't give the exact number but its not working with our account which has around 116 contacts.
I am copying the code below for reference and any advise would be highly appreciated
trigger Update_related_Contacts_On_Account_fieldchange on Account (after update) {
set<id> ids=new set<id>();
for(Account acc:trigger.new){
ids.add(acc.id);
}
map<id,List<contact>> acc_con_maps=new map<id,List<contact>>();
List<Account> accts=new List<Account>([select id,(select id,Relationship_Category_r__c from contacts) from Account where id=:ids]);
For(Account accts1:accts){
acc_con_maps.put(accts1.id,accts1.contacts);
}
list<contact> constoupdate=new list<contact>();
for(Account acc1:trigger.new){
if(acc_con_maps.containsKey(acc1.Id)&&acc_con_maps.get(acc1.id)!=null){
if(acc1.Type=='Member'){
for(contact con:acc_con_maps.get(acc1.Id)){
if(con.Relationship_Category_r__c !='Member'){
con.Relationship_Category_r__c ='Member - Staff';
constoupdate.add(con);
}
}
}
else if(acc1.type=='Member - Past'){
for(contact con1:acc_con_maps.get(acc1.Id)){
if(con1.Relationship_Category_r__c !='Member - Past'){
con1.Relationship_Category_r__c ='Member - Past';
constoupdate.add(con1);
}
}
}
}
}
update constoupdate;
}
I have a trigger on Account which just update one field in all the related contacts. If the account is of type "Member" then the trigger updates a field in contact called "Relationship_Category_r__c" to "Member-staff" and if the Account type changes to "Member-past" then the contact field updates to "Member-past"
The trigger below is working fine if the number of contacts in any account is in between 50 - 80. However, it stops working when it exceed more than that. I can't give the exact number but its not working with our account which has around 116 contacts.
I am copying the code below for reference and any advise would be highly appreciated
trigger Update_related_Contacts_On_Account_fieldchange on Account (after update) {
set<id> ids=new set<id>();
for(Account acc:trigger.new){
ids.add(acc.id);
}
map<id,List<contact>> acc_con_maps=new map<id,List<contact>>();
List<Account> accts=new List<Account>([select id,(select id,Relationship_Category_r__c from contacts) from Account where id=:ids]);
For(Account accts1:accts){
acc_con_maps.put(accts1.id,accts1.contacts);
}
list<contact> constoupdate=new list<contact>();
for(Account acc1:trigger.new){
if(acc_con_maps.containsKey(acc1.Id)&&acc_con_maps.get(acc1.id)!=null){
if(acc1.Type=='Member'){
for(contact con:acc_con_maps.get(acc1.Id)){
if(con.Relationship_Category_r__c !='Member'){
con.Relationship_Category_r__c ='Member - Staff';
constoupdate.add(con);
}
}
}
else if(acc1.type=='Member - Past'){
for(contact con1:acc_con_maps.get(acc1.Id)){
if(con1.Relationship_Category_r__c !='Member - Past'){
con1.Relationship_Category_r__c ='Member - Past';
constoupdate.add(con1);
}
}
}
}
}
update constoupdate;
}
- muhammadb1.3970135761364219E12
- May 20, 2014
- Like
- 0
- Continue reading or reply
Account Trigger that update all contacts - Too many SOQL queries: 101
Hi,
I have a trigger that runs after updating any account and it actually just updates a field (Relationship_category_r__c) in all the related contacts after few conditions.
Condition1: If we update the account type to "Member"
Condition2: If the contact doesn't have "Member" already in the (Relationship_category_r__c) field
ACTION: Update the contact Relationship_Category_r__c field to "Member - staff"
Condition2: If we update the account type to "Member - past"
ACTION: Update all the contacts Relationship_Category_r__c field to "Member - past"
The trigger works absolutely find when the account has less than 25 to 50 contacts but it generates an error when we have an account more than 55 or so contacts
ERROR: Apex trigger UpdateAllContacts caused an unexpected exception, contact your administrator: UpdateAllContacts: System.LimitException: Too many SOQL queries: 101
======================================= TRIGGER ==============================
trigger UpdateAllContacts on Account (after update) {
for(Account acc : Trigger.New){
List<Contact> listCon = [Select id, Relationship_Category_r__c from Contact where AccountId =: acc.id];
for(Contact con : listCon)
{
if (acc.Type=='Member'){
if(con.Relationship_Category_r__c != 'Member'){
con.Relationship_Category_r__c = 'Member - staff';
}
}
else if (acc.Type=='Member - past'){
con.Relationship_Category_r__c = 'Member - past';
}
}
try {
update listCon;
}
catch (DmlException e) {}
}
}
Any help will be greatly appreciated
Thanks
I have a trigger that runs after updating any account and it actually just updates a field (Relationship_category_r__c) in all the related contacts after few conditions.
Condition1: If we update the account type to "Member"
Condition2: If the contact doesn't have "Member" already in the (Relationship_category_r__c) field
ACTION: Update the contact Relationship_Category_r__c field to "Member - staff"
Condition2: If we update the account type to "Member - past"
ACTION: Update all the contacts Relationship_Category_r__c field to "Member - past"
The trigger works absolutely find when the account has less than 25 to 50 contacts but it generates an error when we have an account more than 55 or so contacts
ERROR: Apex trigger UpdateAllContacts caused an unexpected exception, contact your administrator: UpdateAllContacts: System.LimitException: Too many SOQL queries: 101
======================================= TRIGGER ==============================
trigger UpdateAllContacts on Account (after update) {
for(Account acc : Trigger.New){
List<Contact> listCon = [Select id, Relationship_Category_r__c from Contact where AccountId =: acc.id];
for(Contact con : listCon)
{
if (acc.Type=='Member'){
if(con.Relationship_Category_r__c != 'Member'){
con.Relationship_Category_r__c = 'Member - staff';
}
}
else if (acc.Type=='Member - past'){
con.Relationship_Category_r__c = 'Member - past';
}
}
try {
update listCon;
}
catch (DmlException e) {}
}
}
Any help will be greatly appreciated
Thanks
- muhammadb1.3970135761364219E12
- April 09, 2014
- Like
- 0
- Continue reading or reply