• Jacob Barnett
  • NEWBIE
  • 5 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
I have a requirement to build an easier way for the users to search for the final reason of Cases. However we have 4 levels of picklists to get there. So I am unsure of even where to start. Here is what we have:

On the Case object we have 4 levels of "Reasons" pickists:
  1. Category
  2. Sub Category
  3. Reason Type
  4. Reason
Currently they are all dependent on the previous picklist. So the user has to select the category first, then sub category, then reason type, then reason.

The ask is to allow the user to type in something that would filter out all picklist options that match what was typed in. And then based on what option the user selected the levels are seelcted. Here are the requirements I have:
  1. If the user types in "order" then the list will display all levels and options where "order" is an available option at any level or combination of said levels.
  2. If the user selects any level, any previous parent level is automatically selected so theortecially if the user seraches and selects the Reason directly, all the fields will be filled in.
    1. If the user selects (for example) an option at the Reason Category level, then the reverse lookup of Sub Category and Category is pre-filled and then they would still need to select the final Reason option
  3. This option is displayed on the Edit and Case Close page
    1. On the Case Close page the fields are required.
Hoping someone might have any ideas how to even start on this. I have a developer that suggested doing this as an external webpage but that got me thinking that maybe the Lightning Web Component might be a good option. Question is how would I go about doing such a thing?
I am getting an error that I can seem to figure out why it is failing validation. The error is System.TypeException: Invalid conversion from runtime type Utils_Api_WineOS.ErrorResponse to Utils_Api_WineOS.PostResponse

Here is the code snipet we have. This was built by an outside contractor we no longer have on the project and it's only now that it's erroring out.
    global abstract class BaseResponse {}

    global virtual class GetResponse extends BaseResponse {

        public List<SObject> records { get; set; }
        public Integer count { get {return this.records.size();} }
        public String next_records {
            get {
                if(this.records.size() >= 1) {
                    return 'before=' + records[records.size()-1].get('CreatedDate');
                }

                return null;
            }
        }

        public GetResponse() {
            this.records = new List<SObject>();
        }

        public GetResponse(System.RestResponse res, List<SObject> sObjs) {
            this.records = sObjs;
            res.statusCode = 200;
        }
    }

    global virtual class PostResponse extends BaseResponse {

        public List<SObject> records { get; set; }
        public Integer count { get {return this.records.size();} }

        public PostResponse() {
            this.records = new List<SObject>();
        }

        public PostResponse(System.RestResponse res, List<SObject> sObjs) {
            this.records = sObjs;
            res.statusCode = 200;
        }
    }

    global virtual class PatchResponse extends BaseResponse {

        public List<SObject> records { get; set; }
        public Integer count { get {return this.records.size();} }

        public PatchResponse() {
            this.records = new List<SObject>();
        }

        public PatchResponse(System.RestResponse res, List<SObject> sObjs) {
            this.records = sObjs;
            res.statusCode = 200;
        }
    }

    global virtual class DeleteResponse extends BaseResponse {

        public Boolean success { get; set; }

        public DeleteResponse(System.RestResponse res, Boolean success) {
            this.success = success;
            res.statusCode = 200;
        }
    }

    global virtual class StringResponse extends BaseResponse {

        public String data { get; set; }

        public StringResponse(System.RestResponse res, String data) {
            this.data = data;
            res.statusCode = 200;
        }
    }

    global class ErrorResponse extends BaseResponse {

        global String errorMessage {get; set;}

        public ErrorResponse() { }

        global ErrorResponse(System.RestResponse res, Integer errorCode, String errorMessage) {
            res.statusCode = errorCode;
            this.errorMessage = errorMessage;
        }
    }

I have the version of this on 45, the same as the dependant classes that use this class.
Cannot get this to work - get the 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.

Here's my code in the Accounts class:
 
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 onBeforeInsert() {
        List<Account> newAccounts = new List<Account>();
        
        for (Account acct : (List<Account>) Records) {
            acct.Description = 'Domain classes rock!';
            newAccounts.add(acct);
        }
        
        fflib_SObjectUnitOfWork uow = new fflib_SObjectUnitOfWork(new Schema.SObjectType[] { Account.SObjectType });
        uow.registerNew(newAccounts);
    }
    
    public override void onBeforeUpdate(Map<Id,sObject> Records) {
        String rock = 'Domain classes rock!';
        Set<Id> Ids = Records.keySet();
        
        List<Account> accountList = [SELECT Id, Description, AnnualRevenue 
                                     FROM Account 
                                     WHERE Id IN :Ids];
        
        List<Account> updatedAccounts = new List<Account>();
        
        for (Account acct : accountList) {
            if (acct.Description != NULL) {
                acct.AnnualRevenue = rock.getLevenshteinDistance(acct.Description);
                updatedAccounts.add(acct);
            }
        }
        
        fflib_SObjectUnitOfWork uow = new fflib_SObjectUnitOfWork(new Schema.SObjectType[] { Account.SObjectType });
        uow.registerDirty(updatedAccounts);
    }
    
    public override void onApplyDefaults() {
        String rock = 'Domain classes rock!';
        List<Account> accountList = (List<Account>)Records;
        List<Account> updatedAccounts = new List<Account>();
        
        for (Account acct : accountList) {
            if (acct.Description != NULL) {
                acct.AnnualRevenue = rock.getLevenshteinDistance(acct.Description);
                updatedAccounts.add(acct);
            }
        }
        
        fflib_SObjectUnitOfWork uow = new fflib_SObjectUnitOfWork(new Schema.SObjectType[] { Account.SObjectType });
        uow.registerDirty(updatedAccounts);
        uow.commitWork();
    }
}

 
please correct this code and help me earn this badge ...have completed all tasks ..except this one ....

IF( MONTH( NOW() ) = 12,
  DATE( YEAR( NOW() ), 12, 31 ),
  DATE( YEAR( NOW() ), MONTH( NOW() ) + 1, 1) - 1