Salesforce Certified Application Architect

Tuesday 17 February 2015

How auto-assignment should take plae through trigger

The maximum number of cases an agent can have pending is 12. Once the pending case falls below 12 the auto-assignment should take place.


trigger test on Case (after insert) {

List<Id> caseIds = new List<Id>{};
integer intcount=0;
for (Case theCase:trigger.new)
caseIds.add(theCase.Id);

List<Case> cases = new List<Case>{};

AggregateResult[] counts = [SELECT count(id)calls FROM Case  WHERE OwnerId=:UserInfo.getUserId() GROUP BY OwnerId];
for(AggregateResult c : counts  )
{
intcount =integer.valueof(c.get('calls'));
System.debug('intcount ==>'+intcount );
if(intcount <12)  {
Database.DMLOptions dmo = new Database.DMLOptions();

dmo.assignmentRuleHeader.useDefaultRule = true;
c.setOptions(dmo);

}

else{
c.AddError('Does not allow' );

}              
//cases.add(c);
System.debug('cases===>'+cases.size());


}

Database.upsert(cases);
}

Cheers..

Salesforce Certified Application Architect & Certified Data Architecture and Management Designer Exam

How to pass Salesforce Certified Data Architecture and Management Designer Exam This exam was 1st architect exam for me. Its not that muc...