Created
July 20, 2013 11:53
-
-
Save keirbowden/6044762 to your computer and use it in GitHub Desktop.
Extension controller for a Publisher action that posts case information to an account feed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public with sharing class ChatterAccountSnapshotExt | |
{ | |
private Id accId; | |
public Boolean posted {get; set;} | |
public ChatterAccountSnapshotExt(ApexPages.StandardController std) | |
{ | |
accId=std.getId(); | |
posted=false; | |
} | |
public Integer getClosedCases() | |
{ | |
Date startDate=System.today().toStartOfMonth(); | |
Date endDate=System.today().addMonths(1).toStartOfMonth(); | |
List<AggregateResult> ars=[select COUNT(Id) closedCount | |
from Case | |
where Status='Closed' | |
and AccountId=:accId | |
and ClosedDate>=:startDate | |
and ClosedDate<:endDate]; | |
Integer result=0; | |
if (ars.size()>0) | |
{ | |
AggregateResult ar=ars[0]; | |
result=(Integer) ar.get('closedCount'); | |
} | |
return result; | |
} | |
public Integer getNewCases() | |
{ | |
Date startDate=System.today().toStartOfMonth(); | |
Date endDate=System.today().addMonths(1).toStartOfMonth(); | |
List<AggregateResult> ars=[select COUNT(Id) newCount | |
from Case | |
where CreatedDate>=:startDate | |
and AccountId=:accId | |
and CreatedDate<:endDate]; | |
Integer result=0; | |
if (ars.size()>0) | |
{ | |
AggregateResult ar=ars[0]; | |
result=(Integer) ar.get('newCount'); | |
} | |
return result; | |
} | |
public Integer getOpenCases() | |
{ | |
Date startDate=System.today().toStartOfMonth(); | |
Date endDate=System.today().addMonths(1).toStartOfMonth(); | |
List<AggregateResult> ars=[select COUNT(Id) openCount | |
from Case | |
where status!='Closed' | |
and AccountId=:accId]; | |
Integer result=0; | |
if (ars.size()>0) | |
{ | |
AggregateResult ar=ars[0]; | |
result=(Integer) ar.get('openCount'); | |
} | |
return result; | |
} | |
public PageReference post() | |
{ | |
FeedItem item=new FeedItem(); | |
item.ParentId=accId; | |
item.body='Service snapshot\n' + | |
'As of ' + System.now().format('dd/MM/yyyy') + | |
'\nNew Cases : ' + getNewCases() + | |
'\nClosed Cases : ' + getClosedCases() + | |
'\nOpen Cases : ' + getOpenCases(); | |
insert item; | |
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Snapshot Posted')); | |
posted=true; | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment