My Question is - is there a way to modify this page? Is there a way to write my own custom page? Are there any experts that have been into that portion of integration?
Thanks
trigger Task on Task (before insert, before update, after insert, after update) {
HandlerTask taskHandler = new HandlerTask();
/*
BEFORE INSERT, BEFORE UPDATE
*/
if(trigger.isBefore) {
taskHandler.maintainPresentedIds(trigger.new);
}
/*
AFTER INSERT, AFTER UPDATE
*/
if(trigger.isAfter) {
// Check for any presented services....
boolean servicesPresented = false;
for(Task t :trigger.new) {
if(t.Services_Presented__c != null && t.Services_Presented__c != 'null') {
servicesPresented = true;
}
}
if(servicesPresented) {
if(util_utilities.alreadyExecuted != true) {
util_utilities.alreadyExecuted = true;
taskHandler.addUpdateAccountServices(trigger.newmap);
}
}
// Update case & add new Tasks if needed....
taskHandler.caseManagement(trigger.new,trigger.oldmap);
}
}
HandlerTask.cls.....
public with sharing class HandlerTask {
/*
MAINTAIN SERVICES PRESENTED IDs
*/
public void maintainPresentedIds(list<Task> triggeredTasks) {
// Build map<ServiceName,ServiceId> mServiceNameId - from Service__c master
map<string,id> mServiceNameId = new map<string,id>();
map<id,string> mServiceIdName = new map<id,string>();
for(Service__c s :[SELECT id,name FROM Service__c]) {
mServiceNameId.put(s.name,s.id);
mServiceIdName.put(s.id,s.name);
}
for(Task t :triggeredTasks) {
list<string> presentedServiceNames = new list<string>();
presentedServiceNames = stringNullCheck(t.Services_Presented__c).split(';');
string presentedServiceIds = '';
for(string presentedServiceName :presentedServiceNames) {
if(mServiceNameId.containsKey(presentedServiceName))
if(presentedServiceIds.length()>0) {
presentedServiceIds = presentedServiceIds + ';';
}
presentedServiceIds = presentedServiceIds + mServiceNameId.get(presentedServiceName);
}
t.ServicePresentedIds__c = presentedServiceIds;
}
}
/*
ADD UPDATE ACCOUNT-SERVICES AS NEEDED
*/
public void AddUpdateAccountServices(map<id,Task> mTriggeredTasks) {
system.debug('');
system.debug('HandlerTask.AddUpdateAccountServices....');
system.debug('');
// Get all services from Service Master ...
// Build map<ServiceName,ServiceId> mServiceNameId - from Service__c master
map<string,id> mServiceNameId = new map<string,id>();
map<id,string> mServiceIdName = new map<id,string>();
for(Service__c service :[SELECT id,name FROM Service__c]) {
mServiceNameId.put(service.name,service.id);
mServiceIdName.put(service.id,service.name);
}
// Get all services presented on this call
// Build Map<TaskId,list<PresentedServiceIds>> mTaskPresentedServicesIds
map<id,list<id>> mTaskPresentedServiceIds = new map<id,list<id>>();
set<id> accountIds = new set<id>();
set<id> presentedServiceIds = new set<id>();
for(Task t :mTriggeredTasks.values()) {
system.debug('Task='+t);
if(t.Account__c != null) {
accountIds.add(t.Account__c);
if(t.ServicePresentedIds__c != null && t.ServicePresentedIds__c != 'null') {
list<string> iterPresentedServiceIds = t.ServicePresentedIds__c.split(';');
system.debug('t.ServicePresentedIds__c='+t.ServicePresentedIds__c);
system.debug('iterPresentedServiceIds='+iterPresentedServiceIds);
for(string s :iterPresentedServiceIds) {
system.debug('s='+s);
presentedServiceIds.add(s);
}
}
}
}
system.debug('presentedServiceIds='+presentedServiceIds);
// Get existing AccountService records
// Build map of Account to list<AccountService>
map<id,list<AccountService__c>> mAccountAccountServices = new map<id,list<AccountService__c>>();
map<string,AccountService__c> mAccountServiceIdsToAccountService = new map<string,AccountService__c>();
list<AccountService__c> accountServices = [SELECT id,name,Account__c,Last_Call_Disposition__c,
Last_Call_Services_Presented__c,Last_Contact__c,
Service__c,Status__c
FROM AccountService__c
WHERE Account__c IN :accountIds
AND Service__c IN :presentedServiceIds
];
for(AccountService__c accountService :accountServices) {
system.debug('accountService='+accountService);
string combinedIds = string.valueOf(accountService.Account__c) + string.valueOf(accountService.Service__c);
mAccountServiceIdsToAccountService.put(combinedIds,AccountService);
list<AccountService__c> iterAS = new list<AccountService__c>();
if(mAccountAccountServices.containsKey(accountService.Account__c)) {
iterAs = mAccountAccountServices.get(accountService.Account__c);
}
iterAs.add(accountService);
mAccountAccountServices.put(accountService.Account__c,iterAs);
}
// Loop through triggered Tasks - and update/write new AccountService__c's
list<AccountService__c> accountServicesToAdd = new list<AccountService__c>();
map<id,AccountService__c> accountServicesToUpdate = new map<id,AccountService__c>();
for(Task t :mTriggeredTasks.values()) {
system.debug('HandlerTask.AddUpdateAccountServices.Task='+t);
if(t.Account__c != null) {
list<string> iterPresentedServiceIds = t.ServicePresentedIds__c.split(';');
if(!mAccountAccountServices.containsKey(t.Account__c)) {
// No services for this account - add them
for(id presentedServiceId :iterPresentedServiceIds) {
accountServicesToAdd.add(new AccountService__c(Name=mServiceIdName.get(presentedServiceId),
Account__c = t.Account__c,
Last_Call_Disposition__c = stringNullCheck(t.Call_Disposition__c),
Last_Call_Services_Presented__c = stringNullCheck(t.Services_Presented__c),
Last_Contact__c = t.CreatedDate,
Service__c = presentedServiceId,
Status__c = 'Presented',
TaskId__c = t.id
));
}
} else {
// Update existing AccountServices, add missing ones....
for(id presentedServiceId :iterPresentedServiceIds) {
string combinedIds = string.valueOf(t.Account__c) + string.valueOf(presentedServiceId);
if(mAccountServiceIdsToAccountService.containsKey(combinedIds)) {
// Update the AccountService__c record
AccountService__c iterAccountService = new AccountService__c();
iterAccountService = mAccountServiceIdstoAccountService.get(combinedIds);
if(t.CreatedDate > iterAccountService.Last_Contact__c) {
iterAccountService.Last_Contact__c = t.CreatedDate;
iterAccountService.Last_Call_Disposition__c = stringNullCheck(t.Call_Disposition__c);
iterAccountService.Last_Call_Services_Presented__c = stringNullCheck(t.Services_Presented__c);
If(iterAccountService.Status__c == null ||
iterAccountService.Status__c == 'None' ||
iterAccountService.Status__c == 'Opportunity Lost'
) {
iterAccountService.Status__c = 'Presented';
}
}
accountServicesToUpdate.put(iterAccountService.id,iterAccountService);
} else {
// Add a new AccountService__c record
accountServicesToAdd.add(new AccountService__c(Name=mServiceIdName.get(presentedServiceId),
Account__c = t.Account__c,
Last_Call_Disposition__c = stringNullCheck(t.Call_Disposition__c),
Last_Call_Services_Presented__c = stringNullCheck(t.Services_Presented__c),
Last_Contact__c = t.CreatedDate,
Service__c = presentedServiceId,
Status__c = 'Presented',
TaskId__c = t.id
));
}
}
}
}
}
// DML updates as needed
if(accountServicesToAdd.size()>0) {
system.debug('accountServicesToAdd='+accountServicesToUpdate);
insert accountServicesToAdd;
}
If(accountServicesToUpdate.values().size()>0) {
system.debug('accountServicesToUpdate='+accountServicesToUpdate.values());
update accountServicesToUpdate.values();
}
}
9 People are following this question.