Created
September 5, 2016 23:38
-
-
Save felipemesquita/61d13fde03df49eee9417e6855a2536d to your computer and use it in GitHub Desktop.
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 class AccountProcessManager { | |
private Account account; | |
private Case parentCase; | |
private final String SLA_ID = '5504100000007zk'; // Entitlement Id | |
private final String RISK_RECORD_TYPE_ID = '01241000000PvRL'; | |
private final String WC_RECORD_TYPE_ID = '01241000000PvRQ'; | |
private final String LOGISTIC_RECORD_TYPE_ID = '01241000000PvRV'; | |
private final String ALL_CASES_QUEUE_ID = '00G41000000axAH'; | |
private final String RISK_QUEUE_ID = '00G41000000dQUU'; | |
private final String WC_QUEUE_ID = '00G41000000dQUP'; | |
private final String LOGISTIC_QUEUE_ID = '00G41000000dQUZ'; | |
public AccountProcessManager(Account a) { account = a; } | |
public void execute(){ | |
// Cria o ticket pai do tipo CADASTRO | |
parentCase = createParentAccount(); | |
Case risk = createRiskCase(); | |
Case wc = createWCCase(); | |
if (account.Origem_do_credenciamento__c == 'APP Credenciamento') { | |
Case logistic = createLogisticCase(); | |
} | |
} | |
public Case createParentAccount() { | |
Case parentCase = new Case(); | |
parentCase.AccountId = account.Id; | |
parentCase.Subject = 'Novo cadastro do cliente: ' + account.Name; | |
parentCase.Status = 'Em análise'; | |
parentCase.Origin = 'Email'; | |
parentCase.Origem_de_cadastro__c = 'Novo Parceiro'; | |
parentCase.OwnerId = ALL_CASES_QUEUE_ID; | |
insert parentCase; | |
return parentCase; | |
} | |
public Case createRiskCase(){ | |
return createGenericCase('Risco', RISK_RECORD_TYPE_ID, RISK_QUEUE_ID); | |
} | |
public Case createWCCase() { | |
return createGenericCase('WC', WC_RECORD_TYPE_ID, WC_QUEUE_ID); | |
} | |
public Case createLogisticCase() { | |
return createGenericCase('Logística', LOGISTIC_RECORD_TYPE_ID, LOGISTIC_QUEUE_ID); | |
} | |
private Case createGenericCase(String caseType, String recordTypeId, String queueId) { | |
Case genericCase = new Case(); | |
genericCase.ParentId = parentCase.Id; | |
genericCase.Subject = 'Novo ticket de ' + caseType + ' para o cliente: ' + account.Name; | |
genericCase.Status = 'Em análise'; | |
genericCase.Origin = 'Email'; | |
genericCase.EntitlementId = SLA_ID; | |
genericCase.RecordTypeId = recordTypeId; | |
genericCase.OwnerId = queueId; | |
insert genericCase; | |
return genericCase; | |
} | |
} |
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 class CaseProcessManager { | |
private Case c; | |
public CaseProcessManager(Case instance) { c = instance; } | |
public void execute(){ | |
if (c.Status == 'Cancelado') { | |
If (c.ParentId != null) { | |
cancelCases(); | |
cancelParentCase(); | |
} | |
} | |
} | |
private void cancelCases() { | |
List<Case> cases = [SELECT Id | |
,Status | |
FROM Case | |
WHERE ParentId = :c.ParentId | |
AND Id != :c.Id]; | |
for (Case theCase : cases) { cancelCase(theCase); } | |
} | |
private void cancelCase(Case cancelableCase){ | |
if (cancelableCase.Status != 'Cancelado') { | |
cancelableCase.Status = 'Cancelado'; | |
update cancelableCase; | |
} | |
} | |
private void cancelParentCase() { | |
Case parentCase = [SELECT Id, Status FROM Case WHERE Id = :c.ParentId]; | |
cancelCase(parentCase); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment