Trigger :
trigger answerOptionManagement on Employees__c (before update) {
Set<Id> setIDS = new Set<Id>();
List<Employees__c> listIDS = new List<Employees__c>();
for(Employees__c emp : trigger.new){
setIDS.add(emp.Id);
listIDS.add(emp);
}
if(!listIDS.isEmpty() && listIDS.size()>0){
cmdMainOperation(listIDS,setIDS);
}
public static void cmdMainOperation(List<Employees__c> listIDS,Set<Id> setIDS){
AggregateResult [] aggr = [select count(id),First_Name__c fristName,Employees__c employeeId from Contact_Us__c where Employees__c IN :setIDS and First_Name__c != null group by First_Name__c,Employees__c order by First_Name__c desc];
system.debug(aggr);
Map<Id,String> mapAggr = new Map<Id,String>();
for(AggregateResult agr : aggr){
system.debug(mapAggr);
string category=String.valueOf(agr.get('fristName'));
category = category.subString(category.indexOf(':')+1,category.length());
if(mapAggr.containsKey(String.valueOf(agr.get('employeeId')))){
String strCategory = mapAggr.get(String.valueOf(agr.get('employeeId')))+ ','+category;
mapAggr.put(String.valueOf(agr.get('employeeId')),strCategory );
system.debug('mapAggr in if 21 line--->>'+mapAggr);
}else{
mapAggr.put(String.valueOf(agr.get('employeeId')),category);
system.debug('mapAggr in if 24 line--->>'+mapAggr);
}
}
for(Employees__c emp : listIDS){
if(mapAggr.containsKey(emp.id)){
emp.Answer_Options__c = mapAggr.get(emp.id);
system.debug('emp.Answer_Options__c in if 30 line--->>'+emp.Answer_Options__c);
}
}
}
}
trigger answerOptionManagement on Employees__c (before update) {
Set<Id> setIDS = new Set<Id>();
List<Employees__c> listIDS = new List<Employees__c>();
for(Employees__c emp : trigger.new){
setIDS.add(emp.Id);
listIDS.add(emp);
}
if(!listIDS.isEmpty() && listIDS.size()>0){
cmdMainOperation(listIDS,setIDS);
}
public static void cmdMainOperation(List<Employees__c> listIDS,Set<Id> setIDS){
AggregateResult [] aggr = [select count(id),First_Name__c fristName,Employees__c employeeId from Contact_Us__c where Employees__c IN :setIDS and First_Name__c != null group by First_Name__c,Employees__c order by First_Name__c desc];
system.debug(aggr);
Map<Id,String> mapAggr = new Map<Id,String>();
for(AggregateResult agr : aggr){
system.debug(mapAggr);
string category=String.valueOf(agr.get('fristName'));
category = category.subString(category.indexOf(':')+1,category.length());
if(mapAggr.containsKey(String.valueOf(agr.get('employeeId')))){
String strCategory = mapAggr.get(String.valueOf(agr.get('employeeId')))+ ','+category;
mapAggr.put(String.valueOf(agr.get('employeeId')),strCategory );
system.debug('mapAggr in if 21 line--->>'+mapAggr);
}else{
mapAggr.put(String.valueOf(agr.get('employeeId')),category);
system.debug('mapAggr in if 24 line--->>'+mapAggr);
}
}
for(Employees__c emp : listIDS){
if(mapAggr.containsKey(emp.id)){
emp.Answer_Options__c = mapAggr.get(emp.id);
system.debug('emp.Answer_Options__c in if 30 line--->>'+emp.Answer_Options__c);
}
}
}
}
No comments:
Post a Comment