You need to sign in to do that
Don't have an account?
Prasanth R
Apply Domain Layer Principles in Apex--challenge
i'm not able to complete the challenge..i added the code below
code:
public class Accounts extends fflib_SObjectDomain {
public Accounts(List<Account> sObjectList)
{
super(sObjectList);
}
public class Constructor implements fflib_SObjectDomain.IConstructable {
public fflib_SObjectDomain construct(List<sObject> sObjectList) {
return new Accounts(sObjectList);
}
}
public override void onApplyDefaults()
{
// Apply defaults to account
for(Account acc: (List<Account>) Records)
{
if(acc.Description == null)
{
acc.Description = 'Domain classes rock!';
}
}
}
public override void handleBeforeInsert()
{
onApplyDefaults();
}
public override void onBeforeUpdate(Map<Id,sObject> existingRecords) {
String rock = 'Domain classes rock!';
List<Account> updatedAccounts = new List<Account>();
for(Account acc : (List<Account>) Records) {
acc.AnnualRevenue = rock.getLevenshteinDistance(acc.Description);
updatedAccounts.add(acc);
}
fflib_SObjectUnitOfWork uow = new fflib_SObjectUnitOfWork(new Schema.SObjectType[] { Account.SObjectType });
uow.registerDirty(updatedAccounts);
}
}
trigger:
trigger AccountsTrigger on Account (
after delete, after insert, after update, after undelete, before delete, before insert, before update)
{
fflib_SObjectDomain.triggerHandler(Accounts.class);
}
kindly assit me to complete this challenge
code:
public class Accounts extends fflib_SObjectDomain {
public Accounts(List<Account> sObjectList)
{
super(sObjectList);
}
public class Constructor implements fflib_SObjectDomain.IConstructable {
public fflib_SObjectDomain construct(List<sObject> sObjectList) {
return new Accounts(sObjectList);
}
}
public override void onApplyDefaults()
{
// Apply defaults to account
for(Account acc: (List<Account>) Records)
{
if(acc.Description == null)
{
acc.Description = 'Domain classes rock!';
}
}
}
public override void handleBeforeInsert()
{
onApplyDefaults();
}
public override void onBeforeUpdate(Map<Id,sObject> existingRecords) {
String rock = 'Domain classes rock!';
List<Account> updatedAccounts = new List<Account>();
for(Account acc : (List<Account>) Records) {
acc.AnnualRevenue = rock.getLevenshteinDistance(acc.Description);
updatedAccounts.add(acc);
}
fflib_SObjectUnitOfWork uow = new fflib_SObjectUnitOfWork(new Schema.SObjectType[] { Account.SObjectType });
uow.registerDirty(updatedAccounts);
}
}
trigger:
trigger AccountsTrigger on Account (
after delete, after insert, after update, after undelete, before delete, before insert, before update)
{
fflib_SObjectDomain.triggerHandler(Accounts.class);
}
kindly assit me to complete this challenge
Please note that Questions about how to pass Trailhead challenges are not on topic, because these challenges are intended to be independent demonstrations of your abilities.
Trailhead Help (https://trailhead.salesforce.com/en/help?support=home) can provide assistance for situations where Trailhead does not appear to be functioning correctly. You can reach out to them if this is the case.
Please close the thread by selected as Best Answer so that we can keep our community clean
Thanks!!