I have a method in beforeInsert trigger, when new SObject is inserted it should add a numeric prefix. That alone is working, but my assignment now is make it much shorter. Currently I'm having 1 block of code for each sobject.
public static void addPhonePrefix(List<SObject> sObjectsList){
if (sObjectsList.get(0)instanceof Account) {
for (SObject sobj : sObjectsList) {
Account account = (Account)sobj;
//e.g. account.Phone = '+421'+account.Phone;
//CONDITIONS ... }
}
if (sObjectsList.get(0)instanceof Contact) {
for (SObject sobj : sObjectsList) {
Contact contact = (Contact)sobj;
//CONDITIONS ... }
}
if (sObjectsList.get(0)instanceof Lead) {
for (SObject sobj : sObjectsList) {
Lead lead = (Lead)sobj;
//CONDITIONS ... }
}
}
Is there a way to use 1 block of code (conditions) for 3 sobjects (Leads, Contacts, Accounts) at once?