8

I have a Scheduled Apex job, 'scheduleUnsub,' which calls a class 'resubscribeCall,' which runs some code including a method in a Managed Package (ExactTarget) which makes an API call to ExactTarget. When I test 'resubscribeCall' it works as expected. However, whenever the Scheduled Apex job runs, the API call instead of succeeding, returns with

No content to map to Object due to end of input

Does anyone know why it would be behaving differently when run as a scheduled job than when run alone? I had previously tested this in a trigger with the API call as an @future method, but encountered the same problem.

Code below the break


global class scheduleUnsubscribe implements Schedulable{
    global void execute(SchedulableContext SC) {
      resubscribeCall rc = new resubscribeCall();
    }

}

public with sharing class resubscribeCall {
Id contactIds;
static Date startDate = Date.valueOf('2015-04-28');
Set<String> testEmails = new Set<String>{'[email protected]', '[email protected]', '[email protected]'};
public resubscribeCall(){
    Contact[] contacts = [Select Id, Email, HasOptedOutOfEmail, (Select Id, Name from Unsubscribed_Lists__r), 
                    (Select Id, Name from et4ae5__IndividualEmailResults__r WHERE 
                    et4ae5__DateUnsubscribed__c != NULL AND et4ae5__DateUnsubscribed__c > :startDate ORDER BY et4ae5__DateUnsubscribed__c DESC LIMIT 1)
                    from Contact WHERE HasOptedOutOfEmail = true AND Email IN :testEmails];
    Map<Id, Contact> cMap = new Map<Id, Contact>();
    for(Contact c : contacts){
        System.debug(c);
        if(c.et4ae5__IndividualEmailResults__r.size() > c.Unsubscribed_Lists__r.size())
            cMap.put(c.id, c);
    }

    Unsubscribed_List__c[] toInsert = new Unsubscribed_List__c[]{};
    for(Contact c : contacts)
    {
        if(c.et4ae5__IndividualEmailResults__r.isEmpty() || !cMap.containsKey(c.id)) continue;

        Unsubscribed_List__c unsub = new Unsubscribed_List__c();
        unsub.Contact__c = c.id;
        String name = c.et4ae5__IndividualEmailResults__r[0].Name.split(',')[0].trim();
        System.debug(name);
        unsub.Name = name;
        unsub.Email__c = c.et4ae5__IndividualEmailResults__r[0].Id;

        toInsert.add(unsub);
        c.HasOptedOutOfEmail = false;
        String output;
        try{
            if(!Test.isRunningTest())
                output = et4ae5.jsButtonMethods.performResub(c.id, 'contact');
        }catch(Exception e)
        {
            output = e.getMessage();
        }
        System.debug(output);
    }
    insert toInsert;

    update contacts;                                            
}
3
  • 1
    Yay! someone else who uses the Array style syntax!! Unsubscribed_List__c[] toInsert = new Unsubscribed_List__c[]{}; Apr 30, 2015 at 21:53
  • 2
    This line is vulnerable to nulls in a big way: String name = c.et4ae5__IndividualEmailResults__r[0].Name.split(',')[0].trim(); Apr 30, 2015 at 21:55
  • That error basically means that there was NO data returned in the body of the response when the call was made. Be aware that no session id is available in a schedule class without a little bit of work. Not sure if et uses the session ID as part of the callout or not. You would be best served to contact ET support and have them look at the debug logs to identify the issue
    – Eric
    Apr 30, 2015 at 22:57

1 Answer 1

0

Is the scheduled class making a callout? That error looks like an error from a blank response from a callout.

Scheduled classes can't make callouts directly from what I remember - they have to call future methods with callouts enabled on them...e.g. @future(callout=true)

1
  • This might be it- I also hadn't specified callout=true when I did it with a @future method before. Will test tomorrow and let you know. May 1, 2015 at 5:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .