You need to sign in to do that
Don't have an account?
S N 27
System.ListException: Row with null Id at index: 0
Hi All,
I have written a small piece of code that basically checks for the asset related to Case. If the case status is updated to "Application-submitted" and if there are no asset related to a case then throw an error. I have made use of Aggregate result to count the asset on the case.I don't know where my code is going wrong.pls help
trigger assetCountonCase on Case (before update) {
Set<Id> caseId = new Set<Id>();
Set<Id> rtIds = new Set<Id>();
Map<ID,RecordType> casertMap = New Map<ID,RecordType>([Select ID,Name,DeveloperName From RecordType Where sObjectType ='Case']);
system.debug('casertMap=========================='+casertMap);
for(Case cse: Trigger.new){
system.debug('cse==========================');
if((cse.status=='Application-Submitted')&&((casertMap.get(cse.recordTypeID).Developername.containsIgnoreCase('Simple_Application'))||(casertMap.get(cse.recordTypeID).Developername.containsIgnoreCase('Complex_Application')))){
caseId.add(cse.Id);
system.debug('caseId========================'+caseId);
}
}
Map<Id,AggregateResult> assetConMap = new Map<Id,AggregateResult>([Select JMB1__Case__c id,count(id) a from Asset where JMB1__Case__c!=null and JMB1__Case__c in:caseId GROUP BY JMB1__Case__c]);
system.debug('assetConMap========================='+assetConMap);
for(Case cse: Trigger.new){
AggregateResult assetsize = assetConMap.get(cse.Id);
system.debug('assetsize==========================='+assetsize);
if(assetsize==null){
cse.addError('One asset is required');
}
}
}
I have written a small piece of code that basically checks for the asset related to Case. If the case status is updated to "Application-submitted" and if there are no asset related to a case then throw an error. I have made use of Aggregate result to count the asset on the case.I don't know where my code is going wrong.pls help
trigger assetCountonCase on Case (before update) {
Set<Id> caseId = new Set<Id>();
Set<Id> rtIds = new Set<Id>();
Map<ID,RecordType> casertMap = New Map<ID,RecordType>([Select ID,Name,DeveloperName From RecordType Where sObjectType ='Case']);
system.debug('casertMap=========================='+casertMap);
for(Case cse: Trigger.new){
system.debug('cse==========================');
if((cse.status=='Application-Submitted')&&((casertMap.get(cse.recordTypeID).Developername.containsIgnoreCase('Simple_Application'))||(casertMap.get(cse.recordTypeID).Developername.containsIgnoreCase('Complex_Application')))){
caseId.add(cse.Id);
system.debug('caseId========================'+caseId);
}
}
Map<Id,AggregateResult> assetConMap = new Map<Id,AggregateResult>([Select JMB1__Case__c id,count(id) a from Asset where JMB1__Case__c!=null and JMB1__Case__c in:caseId GROUP BY JMB1__Case__c]);
system.debug('assetConMap========================='+assetConMap);
for(Case cse: Trigger.new){
AggregateResult assetsize = assetConMap.get(cse.Id);
system.debug('assetsize==========================='+assetsize);
if(assetsize==null){
cse.addError('One asset is required');
}
}
}
use below updated code
Hope this will help you,
Thanks
karthik