0

Really two different things here. What this is doing is comparing the Email addresses of an external platform (Zuora Billing platform) to email addresses and accounts that already exist within SFDC.

This works as I intend it to but I have one issue I don't really understand. For the Contact loop of the scope of SFDC internal data I com just checking the Set against what exists in the Zuora platform. If SFDC does not contain that email it creates a new one. If it DOES it will hit the else statement. Which it does. But it won't compare any of the con fields to the if conditions and simply skips them all.

However, when I test it the code coverage simply doesn't hit it despite that I know for certain the test data contains multiple records that would hit these requirements. Am I missing something very obvious?

The finalSet here isn't declared in this snippet but its just a set that adds things that were already added so I do not add any duplicates during the loop.

    public Database.QueryLocator start(Database.BatchableContext context){
       return Database.getQueryLocator([SELECT Id, AccountId, Email, LastName, status__c FROM Contact WHERE AccountId IN : lookerByIds.keySet()]);

    }

    public void execute(Database.BatchableContext context, List<Contact> scope) {
        Set<String> check = new Set<String>();
        Set<Contact> upSet = new Set<Contact>();
        List<Contact> upsertList = new List<Contact>();

        for(Contact con : scope) {
            check.add(con.email);
        }
        for(Contact con : scope) {

            for(String email : lookerByIds.get(con.AccountId)) {

                if(!check.contains(email)) {

                    if(!finalSet.contains(email)) {

                    finalSet.add(email);
                    upSet.add(new Contact(LastName = 'Accounts Payable', AccountId = con.AccountId, status__c = 'Billing Primary', Email = email, 
                    CreatedById = '0050b000005iSW3AAM', 
                    HasOptedOutOfEmail = False));
                    }
                }
                else {

                    //if the email in SFDC is already null for some reason
                    if(!con.status__c.contains('Billing Primary')) {
                    con.status__c = con.status__c + ';Billing Primary';
                    }
                    if(String.isBlank(con.Status__c)) {
                    con.Status__c = 'Billing Primary';                    
                    }
                    if(con.status__c.contains('No Longer There') && con.status__c.contains('Billing')) {
                    con.status__c = null;
                    con.HasOptedOutOfEmail = True;
                    con.Inactive_Contact__c = True;
                    }
                    con.LastModifiedById = '0050b000005iSW3AAM';
                    upSet.add(con); 
                    //adds to upsert list indicates modification
                }
            }
        }      
        upsertList.addall(upSet);
        upsert upsertList;

    }

    public void finish(Database.BatchableContext BC) {

    }

To be more clear it stops here

     //if the email in SFDC is already null for some reason
                    if(!con.status__c.contains('Billing Primary')) {
                    con.status__c = con.status__c + ';Billing Primary';
                    }
                    if(String.isBlank(con.Status__c)) {
                    con.Status__c = 'Billing Primary';                    
                    }
                    if(con.status__c.contains('No Longer There') && con.status__c.contains('Billing')) {
                    con.status__c = null;
                    con.HasOptedOutOfEmail = True;
                    con.Inactive_Contact__c = True;
                    }
                    con.LastModifiedById = '0050b000005iSW3AAM';
                    upSet.add(con); 
                    //adds to upsert list indicates modification
3
  • In which line stops? the test coverage.. in which line stops the test? Jun 5, 2020 at 9:27
  • @CarlosNaranjo edited
    – Randy B.
    Jun 5, 2020 at 9:34
  • Is lookerById a static variable? The execute method will run in a separate transaction so the static variable will not contain the same as during start. Unless you set it again
    – alesremta
    Jun 5, 2020 at 20:35

1 Answer 1

0

Ended up being a silly mistake on my end where my test data was not as good as I thought it was.

1
  • This answer would be improved if you went into more detail. What test data did you change? how was the old test data causing a problem? how did the new test data fix it? The goal here is for the question and answers to not only benefit you, but also be of use to other people with similar problems that are searching for help on (insert search engine of choice here)
    – Derek F
    Jun 6, 2020 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.