You need to sign in to do that
Don't have an account?
sagar patil 13
Internal server error due to trigger
An error has occurred while processing your request. The salesforce.com support team has been notified of the problem. If you believe you have additional information that may be of help in reproducing or correcting the error, please contact Salesforce Support. Please indicate the URL of the page you were requesting, any error id shown on this page as well as any other related information. We apologize for the inconvenience.
Thank you again for your patience and assistance. And thanks for using salesforce.com!
Error ID: 1836710115-341721 (1204153959)
Above error is occurred while updating.
But Error has been gone when I inactive the trigger
Below is my trigger code
Helper class
public class UpdateAction
{
List<Case> newCaseListToUpdate;
List<Case> oldCaseList;
List<ID> productIdList;//List Collection for product obj.ID
List<ID > srTypeIdList;//List Collection for srtype obj.ID
List<ID> srSubTyeIdList;//List Collection for srsubtype obj.ID
Map<String,Case_Configuration__c> caseConfigIdsWithCaseStage;
Map<Case,ID> caseStepsOfcases;
public UpdateAction(List<Case> newCaseListToUpdate,List<Case> oldCaseList)
{
this.newCaseListToUpdate=newCaseListToUpdate;
this.oldCaseList=oldCaseList;
}
public Boolean isProductSRTypeOrSRSubTypeUpdated()
{
if(initUpdatedListOfProductSrTypeAndSRSubType()==true)
return true;
return false;
}
private Boolean initUpdatedListOfProductSrTypeAndSRSubType()
{
productIdList=new List<ID>();
srTypeIdList=new List<ID>();
srSubTyeIdList=new List<ID>();
Boolean isNewDataFound=false;
for(Integer i=0;i<newCaseListToUpdate.size();i++)
{
Case newCase=newCaseListToUpdate[i];
if(newCase.Product__c != oldCaseList[i].Product__c
|| newCase.SR_Type__c != oldCaseList[i].SR_Type__c
|| newCase.SR_Sub_Type__c != oldCaseList[i].SR_Sub_Type__c)
{
productIdList.add(newCase.Product__c );
srTypeIdList.add(newCase.SR_Type__c );
srSubTyeIdList.add(newCase.SR_Sub_Type__c );
isNewDataFound=true;
}
}
return isNewDataFound;
}
public void setCaseConfigAndCurrStage()
{
// initCaseConfigMap();
caseConfigIdsWithCaseStage=CaseConfigurationOperation.getCaseStageOfCaseConfig(productIdList,srTypeIdList,srSubTyeIdList);
if(caseConfigIdsWithCaseStage!=null && caseConfigIdsWithCaseStage.size()>0)
{
for(Case cs:newCaseListToUpdate)
{
//System.debug('insert keyyy='+key(cs));
Case_Configuration__c caseConfig=caseConfigIdsWithCaseStage.get(CaseConfigurationOperation.caseKey(cs));
if(caseConfig!=null)
{
cs.Case_Configuration__c= caseConfig.Id;
cs.Current_Stage__c=caseConfig.Case_Steps__r[0].Case_Stage__c;
}
}
}
}
/*-- private void initCaseConfigMap()
{
try
{
caseConfigIdsWithCaseStage=new Map<String,Case_Configuration__c>();
for(Case_Configuration__c caseConfig :
[select Id,Product__r.Id,SR_Sub_Type__r.Id,SR_Type__r.Id,(select Case_Stage__c from Case_Steps__r where Name='001')
from Case_Configuration__c
where Product__r.Id In :productIdList and SR_Sub_Type__r.Id In :srSubTyeIdList
and SR_Type__r.Id In :srTypeIdList])
{
//System.debug(caseConfig.Product__r);
if(isKeyNull(caseConfig)==false)
caseConfigIdsWithCaseStage.put(key(caseConfig),caseConfig);
}
}
catch(DMLException e)
{
System.debug(e);
}
}
private Boolean isKeyNull(Case_Configuration__c caseConfig)
{
if(caseConfig.Product__r.Id==null && caseConfig.SR_Type__r.Id==null && caseConfig.SR_Sub_Type__r.Id==null)
{
return true;
}
return false;
}
private static String key(Case cs)
{
return cs.Product__c + '|' + cs.SR_Type__c + '|' + cs.SR_Sub_Type__c ;
}
private static String key(Case_Configuration__c caseConfig)
{
return caseConfig.Product__r.Id + '|' + caseConfig.SR_Type__r.Id + '|' + caseConfig.SR_Sub_Type__r.Id ;
}
--*/
public void updateSteps()
{
if(isCurrStepUpdated()==true)
{
System.debug('current step is updated');
Map<ID,case_step__c> currentCaseStepList=new Map<ID,case_step__c>(
[select ID,Next_Step__r.Id,Next_Step__r.Case_Stage__c
from Case_Step__c
where Id In :caseStepsOfcases.values()]);
System.debug('currentCaseStepList obj created');
if(currentCaseStepList!=null && currentCaseStepList.size()>0)
{
for(Case caseToUpdate:caseStepsOfcases.keySet())
{
caseToUpdate.Previous_Status__c =caseToUpdate.Current_Status__c;
Case_Step__c currCaseStep=currentCaseStepList.get(caseToUpdate.Current_Step__c);
if(currCaseStep!=null)
{
ID nextStepId=currCaseStep.Next_Step__r.Id;
if(nextStepId!=null)
{
caseToUpdate.Current_Stage__c=currCaseStep.Next_Step__r.Case_Stage__c;
}
else
{
System.debug('no next found at line 150');
}
caseToUpdate.Current_Step__c=null;
}
else
{
System.debug('currCaseStep found null at 157');
}
}
}
else
{
System.debug('currentCaseStepList fount null empty at 158');
}
}
}
private Boolean isCurrStepUpdated()
{
Boolean currStepUpdated=false;
caseStepsOfcases=new Map<Case,ID>();
for(Integer i=0;i<newCaseListToUpdate.size();i++)
{
Case newCase=newCaseListToUpdate[i];
if(newCase.Current_Step__c != oldCaseList[i].Current_Step__c)
{
caseStepsOfcases.put(newCase,newCase.Current_Step__c);
currStepUpdated=true;
}
}
return currStepUpdated;
}
}
Below is my trigger
trigger testCase on Case(before insert,before update)
{
if(Trigger.isBefore)
{
if(Trigger.Isinsert )
{
new InsertAction(Trigger.new).setCaseConfigAndCurrStage();
}//end of if
if(Trigger.isupdate)
{
UpdateAction updateAct=new UpdateAction(Trigger.new,Trigger.old);
if(updateAct.isProductSRTypeOrSRSubTypeUpdated()==true)
{
System.debug('updating config and curr stage');
updateAct.setCaseConfigAndCurrStage();
}
updateAct.updateSteps();
System.debug('trigger executed');
}
}//End of ISbefore.
}//end of trigg
Thank you again for your patience and assistance. And thanks for using salesforce.com!
Error ID: 1836710115-341721 (1204153959)
Above error is occurred while updating.
But Error has been gone when I inactive the trigger
Below is my trigger code
Helper class
public class UpdateAction
{
List<Case> newCaseListToUpdate;
List<Case> oldCaseList;
List<ID> productIdList;//List Collection for product obj.ID
List<ID > srTypeIdList;//List Collection for srtype obj.ID
List<ID> srSubTyeIdList;//List Collection for srsubtype obj.ID
Map<String,Case_Configuration__c> caseConfigIdsWithCaseStage;
Map<Case,ID> caseStepsOfcases;
public UpdateAction(List<Case> newCaseListToUpdate,List<Case> oldCaseList)
{
this.newCaseListToUpdate=newCaseListToUpdate;
this.oldCaseList=oldCaseList;
}
public Boolean isProductSRTypeOrSRSubTypeUpdated()
{
if(initUpdatedListOfProductSrTypeAndSRSubType()==true)
return true;
return false;
}
private Boolean initUpdatedListOfProductSrTypeAndSRSubType()
{
productIdList=new List<ID>();
srTypeIdList=new List<ID>();
srSubTyeIdList=new List<ID>();
Boolean isNewDataFound=false;
for(Integer i=0;i<newCaseListToUpdate.size();i++)
{
Case newCase=newCaseListToUpdate[i];
if(newCase.Product__c != oldCaseList[i].Product__c
|| newCase.SR_Type__c != oldCaseList[i].SR_Type__c
|| newCase.SR_Sub_Type__c != oldCaseList[i].SR_Sub_Type__c)
{
productIdList.add(newCase.Product__c );
srTypeIdList.add(newCase.SR_Type__c );
srSubTyeIdList.add(newCase.SR_Sub_Type__c );
isNewDataFound=true;
}
}
return isNewDataFound;
}
public void setCaseConfigAndCurrStage()
{
// initCaseConfigMap();
caseConfigIdsWithCaseStage=CaseConfigurationOperation.getCaseStageOfCaseConfig(productIdList,srTypeIdList,srSubTyeIdList);
if(caseConfigIdsWithCaseStage!=null && caseConfigIdsWithCaseStage.size()>0)
{
for(Case cs:newCaseListToUpdate)
{
//System.debug('insert keyyy='+key(cs));
Case_Configuration__c caseConfig=caseConfigIdsWithCaseStage.get(CaseConfigurationOperation.caseKey(cs));
if(caseConfig!=null)
{
cs.Case_Configuration__c= caseConfig.Id;
cs.Current_Stage__c=caseConfig.Case_Steps__r[0].Case_Stage__c;
}
}
}
}
/*-- private void initCaseConfigMap()
{
try
{
caseConfigIdsWithCaseStage=new Map<String,Case_Configuration__c>();
for(Case_Configuration__c caseConfig :
[select Id,Product__r.Id,SR_Sub_Type__r.Id,SR_Type__r.Id,(select Case_Stage__c from Case_Steps__r where Name='001')
from Case_Configuration__c
where Product__r.Id In :productIdList and SR_Sub_Type__r.Id In :srSubTyeIdList
and SR_Type__r.Id In :srTypeIdList])
{
//System.debug(caseConfig.Product__r);
if(isKeyNull(caseConfig)==false)
caseConfigIdsWithCaseStage.put(key(caseConfig),caseConfig);
}
}
catch(DMLException e)
{
System.debug(e);
}
}
private Boolean isKeyNull(Case_Configuration__c caseConfig)
{
if(caseConfig.Product__r.Id==null && caseConfig.SR_Type__r.Id==null && caseConfig.SR_Sub_Type__r.Id==null)
{
return true;
}
return false;
}
private static String key(Case cs)
{
return cs.Product__c + '|' + cs.SR_Type__c + '|' + cs.SR_Sub_Type__c ;
}
private static String key(Case_Configuration__c caseConfig)
{
return caseConfig.Product__r.Id + '|' + caseConfig.SR_Type__r.Id + '|' + caseConfig.SR_Sub_Type__r.Id ;
}
--*/
public void updateSteps()
{
if(isCurrStepUpdated()==true)
{
System.debug('current step is updated');
Map<ID,case_step__c> currentCaseStepList=new Map<ID,case_step__c>(
[select ID,Next_Step__r.Id,Next_Step__r.Case_Stage__c
from Case_Step__c
where Id In :caseStepsOfcases.values()]);
System.debug('currentCaseStepList obj created');
if(currentCaseStepList!=null && currentCaseStepList.size()>0)
{
for(Case caseToUpdate:caseStepsOfcases.keySet())
{
caseToUpdate.Previous_Status__c =caseToUpdate.Current_Status__c;
Case_Step__c currCaseStep=currentCaseStepList.get(caseToUpdate.Current_Step__c);
if(currCaseStep!=null)
{
ID nextStepId=currCaseStep.Next_Step__r.Id;
if(nextStepId!=null)
{
caseToUpdate.Current_Stage__c=currCaseStep.Next_Step__r.Case_Stage__c;
}
else
{
System.debug('no next found at line 150');
}
caseToUpdate.Current_Step__c=null;
}
else
{
System.debug('currCaseStep found null at 157');
}
}
}
else
{
System.debug('currentCaseStepList fount null empty at 158');
}
}
}
private Boolean isCurrStepUpdated()
{
Boolean currStepUpdated=false;
caseStepsOfcases=new Map<Case,ID>();
for(Integer i=0;i<newCaseListToUpdate.size();i++)
{
Case newCase=newCaseListToUpdate[i];
if(newCase.Current_Step__c != oldCaseList[i].Current_Step__c)
{
caseStepsOfcases.put(newCase,newCase.Current_Step__c);
currStepUpdated=true;
}
}
return currStepUpdated;
}
}
Below is my trigger
trigger testCase on Case(before insert,before update)
{
if(Trigger.isBefore)
{
if(Trigger.Isinsert )
{
new InsertAction(Trigger.new).setCaseConfigAndCurrStage();
}//end of if
if(Trigger.isupdate)
{
UpdateAction updateAct=new UpdateAction(Trigger.new,Trigger.old);
if(updateAct.isProductSRTypeOrSRSubTypeUpdated()==true)
{
System.debug('updating config and curr stage');
updateAct.setCaseConfigAndCurrStage();
}
updateAct.updateSteps();
System.debug('trigger executed');
}
}//End of ISbefore.
}//end of trigg
Thanks for your response.
Let me send you the entire code.
--------------------------This is for Insert record-----------
public class InsertAction
{
private List<ID> productIdList;//List Collection for product obj.ID
private List<ID > srTypeIdList;//List Collection for srtype obj.ID
private List<ID> srSubTyeIdList;//List Collection for srsubtype obj.ID
public List<Case> caseListToInsert;
Integer i;
private Map<String,Case_Configuration__c> caseConfigIdsWithCaseStage;
public InsertAction(List<Case> caseList)
{
this.caseListToInsert=caseList;
tempTest();
}
private void tempTest()
{
i=0;
for(Account ac:[select Id from Account])
{
i++;
}
}
public void setCaseConfigAndCurrStage()
{
initListOfProductSrTypeAndSRSubType();
// initCaseConfigMap();
caseConfigIdsWithCaseStage=CaseConfigurationOperation.getCaseStageOfCaseConfig(productIdList,srTypeIdList,srSubTyeIdList);
if(caseConfigIdsWithCaseStage!=null && caseConfigIdsWithCaseStage.size()>0)
{
for(Case cs:caseListToInsert)
{
//System.debug('insert keyyy='+key(cs));
Case_Configuration__c caseConfig=caseConfigIdsWithCaseStage.get(CaseConfigurationOperation.caseKey(cs));
if(caseConfig!=null)
{
cs.Case_Configuration__c= caseConfig.Id;
cs.Current_Stage__c=caseConfig.Case_Steps__r[0].Case_Stage__c;
}
}
}
}
private void initListOfProductSrTypeAndSRSubType()
{
productIdList=new List<ID>();
srTypeIdList=new List<ID>();
srSubTyeIdList=new List<ID>();
for(Case c:caseListToInsert)
{
productIdList.add(c.Product__c ); //before inser ther is no relationship so dont use __r,,instead use __c
srTypeIdList.add(c.SR_Type__c );
srSubTyeIdList.add(c.SR_Sub_Type__c );
}
}
}
______________________________This is nfor update record_____________________________________
public class UpdateAction
{
List<Case> newCaseListToUpdate;
List<Case> oldCaseList;
List<ID> productIdList;//List Collection for product obj.ID
List<ID > srTypeIdList;//List Collection for srtype obj.ID
List<ID> srSubTyeIdList;//List Collection for srsubtype obj.ID
Map<String,Case_Configuration__c> caseConfigIdsWithCaseStage;
Map<Case,ID> caseStepsOfcases;
public UpdateAction(List<Case> newCaseListToUpdate,List<Case> oldCaseList)
{
this.newCaseListToUpdate=newCaseListToUpdate;
this.oldCaseList=oldCaseList;
}
public Boolean isProductSRTypeOrSRSubTypeUpdated()
{
if(initUpdatedListOfProductSrTypeAndSRSubType()==true)
return true;
return false;
}
private Boolean initUpdatedListOfProductSrTypeAndSRSubType()
{
productIdList=new List<ID>();
srTypeIdList=new List<ID>();
srSubTyeIdList=new List<ID>();
Boolean isNewDataFound=false;
for(Integer i=0;i<newCaseListToUpdate.size();i++)
{
Case newCase=newCaseListToUpdate[i];
if(newCase.Product__c != oldCaseList[i].Product__c
|| newCase.SR_Type__c != oldCaseList[i].SR_Type__c
|| newCase.SR_Sub_Type__c != oldCaseList[i].SR_Sub_Type__c)
{
productIdList.add(newCase.Product__c );
srTypeIdList.add(newCase.SR_Type__c );
srSubTyeIdList.add(newCase.SR_Sub_Type__c );
isNewDataFound=true;
}
}
return isNewDataFound;
}
public void setCaseConfigAndCurrStage()
{
// initCaseConfigMap();
caseConfigIdsWithCaseStage=CaseConfigurationOperation.getCaseStageOfCaseConfig(productIdList,srTypeIdList,srSubTyeIdList);
if(caseConfigIdsWithCaseStage!=null && caseConfigIdsWithCaseStage.size()>0)
{
for(Case cs:newCaseListToUpdate)
{
//System.debug('insert keyyy='+key(cs));
Case_Configuration__c caseConfig=caseConfigIdsWithCaseStage.get(CaseConfigurationOperation.caseKey(cs));
if(caseConfig!=null)
{
cs.Case_Configuration__c= caseConfig.Id;
cs.Current_Stage__c=caseConfig.Case_Steps__r[0].Case_Stage__c;
}
}
}
}
public void updateSteps()
{
if(isCurrStepUpdated()==true)
{
System.debug('current step is updated');
Map<ID,case_step__c> currentCaseStepList=new Map<ID,case_step__c>(
[select ID,Next_Step__r.Id,Next_Step__r.Case_Stage__c
from Case_Step__c
where Id In :caseStepsOfcases.values()]);
System.debug('currentCaseStepList obj created');
if(currentCaseStepList!=null && currentCaseStepList.size()>0)
{
for(Case caseToUpdate:caseStepsOfcases.keySet())
{
caseToUpdate.Previous_Status__c =caseToUpdate.Current_Status__c;
Case_Step__c currCaseStep=currentCaseStepList.get(caseToUpdate.Current_Step__c);
if(currCaseStep!=null)
{
ID nextStepId=currCaseStep.Next_Step__r.Id;
if(nextStepId!=null)
{
caseToUpdate.Current_Stage__c=currCaseStep.Next_Step__r.Case_Stage__c;
System.debug('Current_Stage__c is assigned');
}
else
{
System.debug('no next found at line 150');
}
caseToUpdate.Current_Step__c=null;
}
else
{
System.debug('currCaseStep found null at 157');
}
}
}
else
{
System.debug('currentCaseStepList fount null empty at 158');
}
}
}
private Boolean isCurrStepUpdated()
{
Boolean currStepUpdated=false;
caseStepsOfcases=new Map<Case,ID>();
for(Integer i=0;i<newCaseListToUpdate.size();i++)
{
Case newCase=newCaseListToUpdate[i];
if(newCase.Current_Step__c != oldCaseList[i].Current_Step__c)
{
caseStepsOfcases.put(newCase,newCase.Current_Step__c);
currStepUpdated=true;
}
}
return currStepUpdated;
}
}
____________________________________This is to perform case configuration operation_________________________
public class CaseConfigurationOperation
{
public static Map<String,Case_Configuration__c> getCaseStageOfCaseConfig(List<ID> productIdList,List<ID > srTypeIdList,List<ID> srSubTyeIdList)
{
Map<String,Case_Configuration__c> caseConfigIdsWithCaseStage=new Map<String,Case_Configuration__c>();
try
{
caseConfigIdsWithCaseStage.clear();
for(Case_Configuration__c caseConfig :
[select Id,Product__r.Id,SR_Sub_Type__r.Id,SR_Type__r.Id,(select Case_Stage__c from Case_Steps__r where Name='001')
from Case_Configuration__c
where Product__r.Id In :productIdList and SR_Sub_Type__r.Id In :srSubTyeIdList
and SR_Type__r.Id In :srTypeIdList])
{
//System.debug(caseConfig.Product__r);
if(CaseConfigurationOperation.isKeyNull(caseConfig)==false)
caseConfigIdsWithCaseStage.put(key(caseConfig),caseConfig);
}
}
catch(DMLException e)
{
System.debug(e);
}
return caseConfigIdsWithCaseStage;
}
private static Boolean isKeyNull(Case_Configuration__c caseConfig)
{
if(caseConfig.Product__r.Id==null && caseConfig.SR_Type__r.Id==null && caseConfig.SR_Sub_Type__r.Id==null)
{
return true;
}
return false;
}
public static String caseKey(Case cs)
{
return cs.Product__c + '|' + cs.SR_Type__c + '|' + cs.SR_Sub_Type__c ;
}
private static String key(Case_Configuration__c caseConfig)
{
return caseConfig.Product__r.Id + '|' + caseConfig.SR_Type__r.Id + '|' + caseConfig.SR_Sub_Type__r.Id ;
}
}
----------------------------Trigger Code----------------
trigger CaseTrigger on Case(before insert,before update)
{
if(Trigger.isBefore)
{
if(Trigger.Isinsert )
{
new InsertAction(Trigger.new).setCaseConfigAndCurrStage();
}//end of if
if(Trigger.isupdate)
{
UpdateAction updateAct=new UpdateAction(Trigger.new,Trigger.old);
if(updateAct.isProductSRTypeOrSRSubTypeUpdated()==true)
{
System.debug('updating config and curr stage');
updateAct.setCaseConfigAndCurrStage();
}
updateAct.updateSteps();
System.debug('trigger executed');
}
}//End of ISbefore.
}//end of trigg