Last active
February 9, 2022 01:50
-
-
Save CristianoFIlho/dc58bfc3b7bc266ce42562cb52b263b0 to your computer and use it in GitHub Desktop.
APEX activity Cristiano Filho
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 AccountHandler { | |
public static void validateAccount (List<Account> accs) { | |
for(Account acc : accs){ | |
if(acc.CustomerPriority__c == null || acc.BillingCity == null || acc.BillingState == null || acc.BillingStreet == null || acc.BillingCountry == null){ | |
acc.addError('Error check the Customer Priority and Billing Address fields'); | |
} | |
} | |
} | |
public static void associateContact(List<Account> accs){ | |
List<Contact> ctts = new List<Contact>(); | |
for(Account acc : accs){ | |
if(acc.CustomerPriority__c == 'High'){ | |
Contact ctt = new Contact(); | |
ctt.FirstName = 'account contact'; | |
ctt.LastName = acc.Name; | |
ctt.AccountId = acc.Id; | |
ctts.add(ctt); | |
} | |
} | |
List<Database.SaveResult> result = Database.insert(ctts, false); | |
for (Database.SaveResult res : result) { | |
System.debug('Sucess ' + res.isSuccess()); | |
System.debug('Id: ' + res.getId()); | |
System.debug('Error: ' + res.getErrors()); | |
} | |
} | |
} | |
-------------------------------------TRIGGER---------------------------------------------------------- | |
trigger ApexTrigger on Account (before insert, after insert, before update, after update) { | |
if(Trigger.isBefore) { | |
if(Trigger.isInsert){ | |
AccountHandler.validateAccount(Trigger.New); | |
} | |
if(Trigger.isUpdate){ | |
} | |
}else{ | |
if(Trigger.isInsert){ | |
AccountHandler.associateContact(Trigger.New); | |
} | |
if(Trigger.isUpdate){ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Create picklist field in Customer Priority Account with values of ['HIGH', 'MEDIUM', 'LOW']
Whenever the account is promoted in Customer Priority, create an Opportunity.
Whenever the account is demoted in Customer Priority, create a Task.
Create a Tasks cleaning routine as follows:
- Tasks older than a week must be deleted.
Cover generated classes with test class (minimum 80% coverage) and with Assert in each test method;