function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
nagalakshminagalakshmi 

Aggregate function is not working

Hi,

 

Actually i have wrote one trigger for calculating roll up summery. It is working in my developer account. When i use the same code in client account. It will give the wrong value with double digits.. But in client account currecy type having NOK type. How can i display correct value... please help me...

 

This is my trigger:

 

trigger addingvalue on Case(after insert,after update)
{
id caserid;
set<id> pset=new set<id>();
id caseparentid;
//list<case> clist=new list<case>();
map<id,case> insertmap=new map<id,case>();
map<id,case> updatemap=new map<id,case>();
id feereasonid;
for(Case c:trigger.New)
{
caserid=c.recordtypeid;
if(c.Parentid!=null)
{
pset.add(c.parentid);
caseparentid=c.parentid;


}
system.debug(pset+'p===');
}
map<string,case> cmap=new map<string,case>([select Total_Compensation__c,Total_Reimbursement_Value__c from case where id in :pset]);
//string recordtypename=[select id,name from recordtype where id=:caserid limit 1].name;
feereasonid=schema.sobjecttype.case.getRecordTypeInfosByName().get('Feedback Reasons').getRecordTypeId();
//system.debug(recordtypename+'rrr==');
system.debug(cmap+'c===');
if(trigger.isinsert)
{
for(Case c1:trigger.New)
{
if(c1.recordtypeid ==feereasonid)
{
system.debug('sss===');
if(c1.Compensation_Value__c!=null)
{
if(cmap.get(c1.parentid).Total_Compensation__c==null || cmap.get(c1.parentid).Total_Compensation__c==0){
if(c1.Compensation_Value__c!=null)
cmap.get(c1.parentid).Total_Compensation__c=c1.Compensation_Value__c;}
else
cmap.get(c1.parentid).Total_Compensation__c=cmap.get(c1.parentid).Total_Compensation__c+c1.Compensation_Value__c;
}
if(c1.Reimbursement_Value__c!=null){
if(cmap.get(c1.parentid).Total_Reimbursement_Value__c==null || cmap.get(c1.parentid).Total_Reimbursement_Value__c==0)
cmap.get(c1.parentid).Total_Reimbursement_Value__c=c1.Reimbursement_Value__c;
else
cmap.get(c1.parentid).Total_Reimbursement_Value__c=cmap.get(c1.parentid).Total_Reimbursement_Value__c+c1.Reimbursement_Value__c;
}

system.debug(cmap.get(c1.parentid).Total_Compensation__c+'222==');
system.debug(cmap.get(c1.parentid).id+'pid==');

//clist.add(cmap.get(c1.parentid));
insertmap.put(cmap.get(c1.parentid).id,cmap.get(c1.parentid));
}
}
}
list<case> caselist=new list<case>();
double comp=0;
double Reimbursement=0;
set<id> upset=new set<id>();
map<id,double> caseMap=new map<id,double>();
map<id,double> caseMap1=new map<id,double>();
if(trigger.isupdate)
{
for(case cc:trigger.new)
{
if(cc.parentid!=null)
upset.add(cc.parentid);

}

for(AggregateResult q : [select parentid,sum(Compensation_Value__c) from case where parentid IN :upset group by parentid])
{
caseMap.put((Id)q.get('parentid'),(Double)q.get('expr0'));
}

for(AggregateResult q1 : [select parentid,sum(Reimbursement_Value__c) from case where parentid IN :upset group by parentid])
{
caseMap1.put((Id)q1.get('parentid'),(Double)q1.get('expr0'));
}

for(case cu:trigger.new)
{
if(cu.parentid!=null)
{
cmap.get(cu.parentid).Total_Compensation__c=caseMap.get(cu.parentid);
//update.put(cmap.get(c2.parentid).id, cmap.get(c2.parentid));
cmap.get(cu.parentid).Total_Reimbursement_Value__c=caseMap1.get(cu.parentid);
updatemap.put(cmap.get(cu.parentid).id, cmap.get(cu.parentid));
}
}
if(insertmap.size()>0)
update insertmap.values();
if(updatemap.size()>0)
update updatemap.values();
}
}

 

Thanks,

Lakshmi