Limitations of Apex Replay Debugger in VS Code

global class Opportunity_EmailService implements Messaging.InboundEmailHandler {
public Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, Messaging.InboundEnvelope env) {
    Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();

    //try{
        List<Opportunity> oppsToUpsert = new List<Opportunity>();
        List<Account> agenciesToUpsert = new List<Account>();
        List<Policyholder__c> policyholdersToUpsert = new List<Policyholder__c>();

        for(Messaging.InboundEmail.BinaryAttachment att : email.binaryAttachments){
            String attBody = att.Body.toString();
            String firstRow = attBody.split('rn', 2)[0];
            system.debug(firstRow);
            List<String> columns = firstRow.split('\|');

            Integer columnCount = columns.size();
            system.debug(columnCount);

            if(columnCount == 13) {
                boolean isFirstRow = true;
                for(String row : attBody.split('rn')) {
                    if(isFirstRow){
                        isFirstRow = false;
                        continue;
                    }
                    List<String> agencyData = row.split('\|');
                    system.debug(JSON.serializePretty(agencyData));
                    Account acct = new Account();//if the opp already exists this has to be new Opportunity(Id = existingOpp.id);
                    acct.Name = agencyData[1];
                    acct.Phone = agencyData[10];
                    acct.Email__c = agencyData[11];
                    acct.BillingStreet = agencyData[5];
                    acct.BillingCity = agencyData[7];
                    acct.BillingState = agencyData[8];
                    acct.BillingPostalCode = agencyData[9];
                    //whats the rest of the data?
                    //add the rest of the parsing                       
                    agenciesToUpsert.add(acct);
                }
            }
            if (columnCount == 22) {
                boolean isFirstRow = true;
                for(String row : attBody.split('rn')) {
                    if(isFirstRow){
                        isFirstRow = false;
                        continue;
                    }

                    List<String> oppData = row.split('\|');
                    system.debug(JSON.serializePretty(oppData));
                    Opportunity opp = new Opportunity();//if the opp already exists this has to be new Opportunity(Id = existingOpp.id);
                    opp.CloseDate = system.today();//THIS NEEDS TO CHANGE
                    opp.Name = oppData[4];
                    opp.StageName = oppData[11];
                    //whats the rest of the data?
                    //add the rest of the parsing
                    oppsToUpsert.add(opp);
                }
            }
            if (columnCount == 16) {
                boolean isFirstRow = true;
                for(String row : attBody.split('rn')) {
                    if(isFirstRow){
                        isFirstRow = false;
                        continue;
                    }

                    List<String> policyholderData = row.split('\|');
                    system.debug(JSON.serializePretty(policyholderData));
                    Policyholder__c policyholder = new Policyholder__c();//if the opp already exists this has to be new Opportunity(Id = existingOpp.id);
                    policyholder.Name = policyholderData[2];
                    //whats the rest of the data?
                    //add the rest of the parsing
                    policyholdersToUpsert.add(policyholder);
                }
            }
        }
        if (agenciesToUpsert.size() > 0) {
            Database.UpsertResult[] urList = Database.upsert(agenciesToUpsert, false);

            // Iterate through each returned result
            for (Database.UpsertResult sr : urList) {
                if (sr.isSuccess()) {
                    // Operation was successful, so get the ID of the record that was processed
                    System.debug('Successfully inserted account. Account ID: ' + sr.getId());
                }
                else {
                    // Operation failed, so get all errors                
                    for(Database.Error err : sr.getErrors()) {
                        System.debug('The following error has occurred.');                    
                        System.debug(err.getStatusCode() + ': ' + err.getMessage());
                        System.debug('Account fields that affected this error: ' + err.getFields());
                    }
                }
            }
        }
        if(oppsToUpsert.size() > 0) {
            System.debug(oppsToUpsert);
            upsert oppsToUpsert;
        }
        if (policyholdersToUpsert.size() > 0) {
            upsert policyholdersToUpsert;
        }
    return result;
}

}

So when I use the replay debugger it displays the instantiated Lists you see at the top as empty arrays in the variables section of the VS Code debugger. As I step through the code and hit a variety of breakpoints these arrays/lists never update in the variables debugger with the added values so I can’t check to see that they are getting filled. Am I missing something? Is there additional functionality in VS Code debugger that I’m not aware of or a way to easily accomplish this without using system.debug.
Maybe the watch or checkpoint sections?

Entering one of the lists in watch didn’t produce anything for me…

I could also just be a total noob…

Or is this a limitation of the Replay functionality?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

It can’t simulate all variable states. To capture more info, use Checkpoints.

See https://releasenotes.docs.salesforce.com/en-us/winter19/release-notes/rn_vscode_replay_debugger.htm


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x