0

I have a method like this (this is partial but the rest of it is less important to the question).

public static List<Contact> syncList() {
        List<Contact> syncList = new List<Contact>();
        Map<Id, List<Contact>> lookerByIds = zuoraContactSync.lookerById(zuoraContactSync.mergeList());
        List<Contact> sfdcList = [SELECT AccountId, Email, FirstName, LastName, status__c FROM Contact WHERE ID in : lookerByIds.keySet()];
        //set status__c AKA Role to Billing Contact
        system.debug(sfdcList.size());

        for(Contact con : sfdcList) { 
{

//other code

return syncList;

My problem is that I do not know how to pass a value to the lookerByIds map. This is a method calling out to an external location. To test that particular method I just built a list and passed it to the method.

So my question is, how do I alter this? Do I make syncList() take an argument like:

syncList(Map<Id, List<Contact>> mapItems)? If so, how do I artificially populate something like that? It is pretty important that I keep this particular method a void as this is going into a schedulable.

  • what inputs does zuoraContactSync.mergeList() take? that is what you need to establish in the testmethod before testing syncList() – cropredy Sep 10 at 18:05
0

Personally, I'd solve this by having a field on the object which the Test method sets. This function can then check to see if that field is set, and uses it, instead of calling out.

public static List<Contact> syncList() {
    List<Contact> syncList = new List<Contact>();
    Map<Id, List<Contact>> lookerByIds;
    if (debugfield != null) {
        lookerByIds = debugfield;
    } else {
        lookerByIds = zuoraContactSync.lookerById(zuoraContactSync.mergeList());
    }
    ...

A better way would be to strucutre the code to make testing easier. There are whole books on this subject, I'm sure :-)

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.