You need to sign in to do that
Don't have an account?

Trigger for monthly count of particular column.
Dear All,
I have Inquiry__c table and Accident__c table.
Inquiry__c table Contains Date__c,Name__c,Account__c,Status__c(Picklist), __cStatus2(Picklist).
Now need to count Number of Accounts per month by when both picklist shows 'OK' .
The count values should be stored in Table2 Accident__c table.
It Contains Date__c,ItemName__c,Account__c,MonthlyGeneratedcount__c
My Code saves with out any error but i haven't get any O/P. Please help me.
Here is my code:
public class Inquiry{
@future public static void ValAdd(Set<Id> InquiryId) {
//integer countmonth,countyear;
string accountname;
List<Inquiry__c> Inquiry= [SELECT Account__c,Name__c,Date__c,Status__c from Inquiry__c where Id =:InquiryId];
Accident__c kpi = new Accident__c();
Inquiry__c FBR= Inquiry[0];
Date startDate=FBR.Date__c.toStartOfMonth();
Date endDate=FBR.Date__c.toStartOfMonth().addMonths(1);
//Date startDatey=FBR.Date__c.toStartOfyear();
//Date endDatey=FBR.Date__c.toStartOfday();
LIST<AggregateResult> countmonth=[SELECT count(Account__c)coun from Inquiry__c where Account__c=:FBR.Account__cand Date__c >= :startDate AND Date__c < :endDate and Status__c=:'OK' and Status2__c=:'OK'];
List<Accident__c> acc= [SELECT Date__c,Account__c ,itemname__c,MonthlyGeneratedCount__c from Accident__c where Date__c >= :startDate and Date__c < :endDate and Account__c=:FBR.Account__c];
if(!acc.isEmpty() )
{
Accident__c accupdate = acc[0];
Decimal decimalcountmonth = 0 ; string strcount= '' +countmonth[0].get('coun') ;
decimalcountmonth=Decimal.ValueOf(strcount);
kpi.MonthlyGeneratedCount__c=decimalcountmonth;
update accupdate ;
}else
{
List<Accident__c> ToUpdate = new List<Accident__c>();
kpi.Date__c=FBR.Date__c;
kpi.Account__c = FBR.Account__c;
kpi.itemname__c= FBR.Name__c;
Decimal decimalcountmonths = 0 ; string strcount= '' +countmonth[0].get('coun') ;
decimalcountmonths=Decimal.ValueOf(strcount);
kpi.MonthlyGeneratedCount__c=decimalcountmonths;
ToUpdate.add(kpi);
insert ToUpdate;
}
}
}
Please let me know wats wrong in this..