You need to sign in to do that
Don't have an account?
magsy1.3942130065717605E12
System.LimitException: Too many DML rows: 10001
Hi
I am getting this error when I try to update my Site.
Following is the trigger.
trigger SiteTrigger on Site__c (after insert, after update, before insert, before update, before delete) {
/**
* Calculate Latitude and Longitude of Sites after its inserted.
* Send Sites to all the customers that are approved by the respective Parent Partner
**/
if(Trigger.isAfter && Trigger.isInsert){
Utility_Trigger.SiteAI_UpdateLatLng_SendSitesToCustomer(Trigger.new);
}
/**
* copy details of Sub Contractor Site to a Partner Site, for a Sub-COntractor owned Site
**/
if(Trigger.isBefore && trigger.isInsert){
Utility_Trigger.Site_BI_CopySCSiteDetails(Trigger.new);
Utility_Trigger.Site_BI_verifyDuplicateSubTierSites(Trigger.new);
}
/**
* copy details of Sub Contractor Site to a Partner Site, for a Sub-COntractor owned Site
**/
// Siddharth: this trigger is not being used, hence commenting it out to improve code coverage.
/* if(Trigger.isBefore && trigger.isUpdate){
Utility_Trigger.Site_BU_CopySCSiteDetails(Trigger.old, Trigger.new);
} */
/**
* Calculate Latitude and Longitude of Sites if its address is updated
* Update composite Keys of SAs & PPSAs on update of Site
**/
if(Trigger.isAfter && Trigger.isUpdate){
Utility_Trigger.Site_AU_UpdateLatLng(Trigger.new, Trigger.old);
Utility_Trigger.Site_AU_updateSA_CK(Trigger.old, Trigger.new);
//Utility_Trigger.Site_AU_SendSCAndSCSToCustomerOrg(Trigger.old, Trigger.new);
}
if(Trigger.isBefore && Trigger.isDelete){
Utility_Trigger.Site_BD_NotifyForUsedSites(Trigger.oldMap);
}
}
Below is the method in Utility Trigger
public static void Site_AU_UpdateLatLng(List<Site__c> sitesNew, List<Site__c> sitesOld){
List<Site__c> sitesToUpdate = new List<Site__c>();
Set<Id> siteIds = new Set<Id>();
for(Integer i = 0; i < sitesNew.size(); i++){
Site__c a_site = sitesNew[i];
if( a_site.Full_Address__c != sitesOld[i].Full_Address__c
|| a_site.Country__c != sitesOld[i].Country__c){
sitesToUpdate.add(a_site);
}
}
for(Site__c a_site : sitesToUpdate){
siteIds.add(a_site.id);
}
if(siteIds.size()>0){
Utility_General.updateSiteLatLng(siteIds, UserInfo.getUserId());
}
}
I am getting this error when I try to update my Site.
Following is the trigger.
trigger SiteTrigger on Site__c (after insert, after update, before insert, before update, before delete) {
/**
* Calculate Latitude and Longitude of Sites after its inserted.
* Send Sites to all the customers that are approved by the respective Parent Partner
**/
if(Trigger.isAfter && Trigger.isInsert){
Utility_Trigger.SiteAI_UpdateLatLng_SendSitesToCustomer(Trigger.new);
}
/**
* copy details of Sub Contractor Site to a Partner Site, for a Sub-COntractor owned Site
**/
if(Trigger.isBefore && trigger.isInsert){
Utility_Trigger.Site_BI_CopySCSiteDetails(Trigger.new);
Utility_Trigger.Site_BI_verifyDuplicateSubTierSites(Trigger.new);
}
/**
* copy details of Sub Contractor Site to a Partner Site, for a Sub-COntractor owned Site
**/
// Siddharth: this trigger is not being used, hence commenting it out to improve code coverage.
/* if(Trigger.isBefore && trigger.isUpdate){
Utility_Trigger.Site_BU_CopySCSiteDetails(Trigger.old, Trigger.new);
} */
/**
* Calculate Latitude and Longitude of Sites if its address is updated
* Update composite Keys of SAs & PPSAs on update of Site
**/
if(Trigger.isAfter && Trigger.isUpdate){
Utility_Trigger.Site_AU_UpdateLatLng(Trigger.new, Trigger.old);
Utility_Trigger.Site_AU_updateSA_CK(Trigger.old, Trigger.new);
//Utility_Trigger.Site_AU_SendSCAndSCSToCustomerOrg(Trigger.old, Trigger.new);
}
if(Trigger.isBefore && Trigger.isDelete){
Utility_Trigger.Site_BD_NotifyForUsedSites(Trigger.oldMap);
}
}
Below is the method in Utility Trigger
public static void Site_AU_UpdateLatLng(List<Site__c> sitesNew, List<Site__c> sitesOld){
List<Site__c> sitesToUpdate = new List<Site__c>();
Set<Id> siteIds = new Set<Id>();
for(Integer i = 0; i < sitesNew.size(); i++){
Site__c a_site = sitesNew[i];
if( a_site.Full_Address__c != sitesOld[i].Full_Address__c
|| a_site.Country__c != sitesOld[i].Country__c){
sitesToUpdate.add(a_site);
}
}
for(Site__c a_site : sitesToUpdate){
siteIds.add(a_site.id);
}
if(siteIds.size()>0){
Utility_General.updateSiteLatLng(siteIds, UserInfo.getUserId());
}
}
http://www.oyecode.com/2011/10/how-to-use-batch-apex-in-salesforce.html
Thanks for the reply. I am restricted and cannot create a new batch apex . Here is the code snippet:
For ur reference wen i try to update ppsas, this in turn update ppsas in PP_AU_updatePPSA_CK. Here the composite key doesnt get updated since the number of partner part for the same exceeds the limit.
/**
* update composite Keys of PPSA on update of PP Names
* @param oldPPs - List of old PPs
* @param newPPs - List of new PPs
* @ return void
**/
public static void PP_AU_updatePPSA_CK(List<Partner_Part__c> oldPPs, List<Partner_Part__c> newPPs){
Set<Id> ppIds = new Set<Id>();
for(Integer i = 0 ; i < oldPPs.size() ; i++){
if(oldPPs[i].Name != null && !oldPPs[i].Name.equalsIgnoreCase(newPPs[i].Name)){
ppIds.add(newPPs[i].Id);
}
}
List<Partner_Part_Activity__c> ppsas = new List<Partner_Part_Activity__c>();
for(Partner_Part_Activity__c aPPSA : [ select Partner_Part__r.Name,
Site_Activity__r.Composite_Key__c,
Composite_Key__c
from Partner_Part_Activity__c
where Partner_Part__c in: ppIds]){
aPPSA.Composite_Key__c = aPPSA.Partner_Part__r.Name + aPPSA.Site_Activity__r.Composite_Key__c;
ppsas.add(aPPSA);
}
if(ppsas.size() > 0){
Database.update(ppsas);
}
}
/**
* update composite Keys of PPSA on update of PP Names
* @param oldPPs - List of new SAs
* @param newPPs - List of new SAs
* @ return void
**/
public static void SA_AU_updateSA_CK(List<Site_Activity__c> oldSAs, List<Site_Activity__c> newSAs){
Set<Id> saIds = new Set<Id>();
for(Integer i = 0 ; i < oldSAs.size() ; i++){
if(oldSAs[i].Name != null && !oldSAs[i].Name.equalsIgnoreCase(newSAs[i].Name)){
saIds.add(newSAs[i].Id);
}
}
List<Partner_Part_Activity__c> ppsas = new List<Partner_Part_Activity__c>();
for(Partner_Part_Activity__c aPPSA : [ select Partner_Part__r.Name,
Site_Activity__r.Composite_Key__c,
Composite_Key__c
from Partner_Part_Activity__c
where Partner_Part__c in: saIds]){
aPPSA.Composite_Key__c = aPPSA.Partner_Part__r.Name + aPPSA.Site_Activity__r.Composite_Key__c;
ppsas.add(aPPSA);
}
if(ppsas.size() > 0){
Database.update(ppsas);
}
}
public static void SendSCAndSCStoCustomerOrg(List<Site__c> siteList){
Map<Id, Set<Id>> subConId_connectionIds = new Map<Id, Set<Id>>();
Map<Id, Set<Id>> subConSiteId_connectionIds = new Map<Id, Set<Id>>();
Map<Id, Set<Id>> pId_subConIds =new Map<Id,Set<Id>>();
Map<Id, Set<Id>> pId_subConSiteIds =new Map<Id,Set<Id>>();
Set<Id> subConIds = new Set<Id>();
Set<Id> partnerIds = new Set<Id>();
Set<Id> siteIds = new Set<Id>();
for(Site__c site : siteList){
siteIds.add(site.id);
}
for(Site__c site : [Select id, Partner__c, Sub_Tier_Site_Id__c,
Sub_Tier_Site__c,
Sub_Tier_Site__r.Partner__c
from Site__c where Id IN :siteIds ]){
if(site.Sub_Tier_Site__c!=null){
partnerIds.add(site.Partner__c);
subConIds.add(site.Sub_Tier_Site__r.Partner__c);
if(!pId_subConIds.containsKey(site.Partner__c)){
pId_subConIds.put(site.Partner__c,new Set<Id>());
}
pId_subConIds.get(site.Partner__c).add(site.Sub_Tier_Site__r.Partner__c);
if(!pId_subConSiteIds.containsKey(site.Partner__c)){
pId_subConSiteIds.put(site.Partner__c,new Set<Id>());
}
pId_subConSiteIds.get(site.Partner__c).add(site.Sub_Tier_Site__c);
}
}
for(PartnerNetworkRecordConnection pnrc : [Select LocalRecordId,
ConnectionId
from PartnerNetworkRecordConnection
where LocalRecordId IN : partnerIds
and status = 'Sent']){
if(pId_subConIds.containsKey(pnrc.LocalRecordId)) {
for(Id subConId : pId_subConIds.get(pnrc.LocalRecordId)) {
if(!subConId_connectionIds.containsKey(subConId)){
subConId_connectionIds.put(subConId,new Set<Id>());
}
subConId_connectionIds.get(subConId).add(pnrc.ConnectionId);
}
}
if(pId_subConSiteIds.containsKey(pnrc.LocalRecordId)) {
for(Id subConSiteId : pId_subConSiteIds.get(pnrc.LocalRecordId)) {
if(!subConSiteId_connectionIds.containsKey(subConSiteId)){
subConSiteId_connectionIds.put(subConSiteId,new Set<Id>());
}
subConSiteId_connectionIds.get(subConSiteId).add(pnrc.ConnectionId);
}
}
}
Set<PartnerNetworkRecordConnection> subConsToSend = new Set<PartnerNetworkRecordConnection>();
for(Id sunConId : subConId_connectionIds.keySet()){
for(Id connectionId : subConId_connectionIds.get(sunConId)){
subConsToSend.add(new PartnerNetworkRecordConnection(ConnectionId = connectionId,
LocalRecordId = sunConId,
SendEmails = FALSE ));
}
}
Set<PartnerNetworkRecordConnection> subConSitesToSend = new Set<PartnerNetworkRecordConnection>();
for(Id subConSiteId : subConSiteId_connectionIds.keySet()){
for(Id connectionId : subConSiteId_connectionIds.get(subConSiteId)){
subConSitesToSend.add(new PartnerNetworkRecordConnection(ConnectionId = connectionId,
LocalRecordId = subConSiteId,
SendEmails = FALSE ));
}
}
if(subConsToSend.size() > 0){
List<PartnerNetworkRecordConnection> subConsToSendList = new List<PartnerNetworkRecordConnection>();
subConsToSendList.addAll(subConsToSend);
Database.insert(subConsToSendList,false);
}
if(subConSitesToSend.size() > 0){
List<PartnerNetworkRecordConnection> subConSitesToSendList = new List<PartnerNetworkRecordConnection>();
subConSitesToSendList.addAll(subConSitesToSend);
Database.insert(subConSitesToSendList,false);
}
}
/**
* update composite Keys of SAs & PPSAs on update of Site
* @param oldPPs - List of new Sites
* @param newPPs - List of new Sites
* @ return void
**/
public static void Site_AU_updateSA_CK(List<Site__c> oldSites, List<Site__c> newSites){
Set<Id> siteIds = new Set<Id>();
for(Integer i = 0 ; i < oldSites.size() ; i++){
if(oldSites[i].Name != null && !oldSites[i].Name.equalsIgnoreCase(newSites[i].Name)){
siteIds.add(newSites[i].Id);
}
}
List<Site_Activity__c> sas = new List<Site_Activity__c>();
for(Site_Activity__c aSA : [ select Activity__c,
Site__r.Name,
Site__r.Partner__r.Name,
Alternate_Site__r.Name,
Composite_Key__c
from Site_Activity__c
where Site__c in: siteIds]){
if(aSA.Alternate_Site__r.Name ==null || aSA.Alternate_Site__r.Name=='')
aSA.Composite_Key__c = aSA.Activity__c + aSA.Site__r.Name;
else
aSA.Composite_Key__c = aSA.Activity__c + aSA.Site__r.Name + aSA.Alternate_Site__r.Name;
sas.add(aSA);
}
if(sas.size() > 0){
Database.update(sas);
}
List<Partner_Part_Activity__c> ppsas = new List<Partner_Part_Activity__c>();
for(Partner_Part_Activity__c aPPSA : [ select Partner_Part__r.Name,
Site_Activity__r.Composite_Key__c,
Composite_Key__c
from Partner_Part_Activity__c
where Site_Activity__r.Site__c in: siteIds]){
aPPSA.Composite_Key__c = aPPSA.Partner_Part__r.Name + aPPSA.Site_Activity__r.Composite_Key__c;
ppsas.add(aPPSA);
}
if(ppsas.size() > 0){
Database.update(ppsas);
}
List<Site__c> siteToShare = new List<Site__c>();
for(Integer i=0 ; i < newSites.size() ; i++){
if(newSites.get(i).Sub_Tier_Site__c != oldSites.get(i).Sub_Tier_Site__c){
siteToShare.add(newSites.get(i));
}
}
if(siteToShare.size() > 0) {
SendSCAndSCStoCustomerOrg(siteToShare);
}
}