Skip to main content

I am stuck in the "Implement a basic Domain class and Apex trigger" challenge. The challenge states

Implement a basic Domain class and accompanying Apex trigger with default and update logic based upon domain conventions.

Create a basic Domain class named Accounts that extends fflib_SObjectDomain.

Create a trigger named AccountsTrigger for Account that calls the fflib_SObjectDomain triggerHandler method for all trigger methods.

Implement defaulting logic that executes when a record is inserted and sets the Description field to the value Domain classes rock!

Implement update logic that calculates the Levenshtein distance between the phrase Domain classes rock! and whatever the contents of the Description field is when an Account is updated. Use the Apex String method getLevenshteinDistance(stringToCompare) and store the result in the Annual Revenue field.

I am getting the following error:

Challenge Not yet complete... here's what's wrong:

The 'Accounts' class 'onBeforeUpdate' method does not appear to be calculating the Levenshtein distance between the phrase default Description ‘Domain classes rock!’ and the value in the updated Description and storing the result in the Annual Revenue field correctly.

My Domain class code is

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)

{

acc.Description = 'Domain classes rock!';

}

}

public override void onbeforeUpdate(Map<Id,SObject> existingRecords)

{

updateAnnualRevenue(existingRecords);

}

private void updateAnnualRevenue(Map<Id,SObject> existingRecords)

{

//calculate value and assign to annualrev

String defaultStr = 'Domain classes rock!';

for(Account acc: (List<Account>)Records)

{

Account oldVal = (Account)existingRecords.get(acc.Id);

String s = oldVal.Description;

acc.AnnualRevenue = defaultStr.getLevenshteinDistance(s);

}

}

}

 
6 answers
  1. Nov 28, 2016, 12:25 AM
    Figured out the error

    The code should compare the old value of description to the new value and not the phrase mentiond in the challege.

    The working code is 

    private void updateAnnualRevenue(Map<Id,SObject> existingRecords)

    {

    //calculate value and assign to annualrev

    for(Account acc: (List<Account>)Records)

    {

    Account oldVal = (Account)existingRecords.get(acc.Id);

    String s = oldVal.Description;

    acc.AnnualRevenue = (acc.Description).getLevenshteinDistance(s);

    }

    }

     
0/9000