Skip to content

Instantly share code, notes, and snippets.

@CristianoFIlho
Last active February 9, 2022 01:50
Show Gist options
  • Save CristianoFIlho/dc58bfc3b7bc266ce42562cb52b263b0 to your computer and use it in GitHub Desktop.
Save CristianoFIlho/dc58bfc3b7bc266ce42562cb52b263b0 to your computer and use it in GitHub Desktop.
APEX activity Cristiano Filho
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){
}
}
}
@CristianoFIlho
Copy link
Author

CristianoFIlho commented Feb 9, 2022

  • 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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment