function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Tyler HarrisTyler Harris 

Apex Heap Error on HttpResponse

I'm getting a Apex Heap Error on my HttpResponse on an XML feed I'm consuming. How can I optimize the consumption of the XML on line
33  HttpResponse res = h.send(req); ?
 
/*************************************************
 Class: GlobalPRM_RssRetrieval.cls
 Description: schedule apex for RSS Feed Retrieval
 Auther: Christine Wang
 Date:   1/15/2015

 Revision History:
---------------------------------------------------- 
***************************************************/ 
global class GlobalPRM_RssRetrieval implements Schedulable {
    public static string sourceURL = GlobalPRM_Setting__c.getAll().values().get(0).GlobalPRM_RssRetrieval_EndPoint__c;
        //'http://www.hidglobal.com/sites/default/files/pp_resources.xml';
    global GlobalPRM_RssRetrieval () {

    }
    
    global void execute(SchedulableContext c) {
        updateFileIndex();
    }

    @future(callout=true)
    static global void updateFileIndex() {
        List<Dom.XMLNode> extFileList = GlobalPRM_RssRetrieval.getRSSFeed(sourceURL);
        System.Debug('# OF POSTS FOUND: ' + extFileList.size() );
    }
    static global List<Dom.XMLNode> getRSSFeed(string URL) {
        Http h = new Http();
        HttpRequest req = new HttpRequest();
        // url that returns the XML in the response body  
    
        req.setEndpoint(url);
        req.setMethod('GET');
        HttpResponse res = h.send(req);
        Dom.Document doc = res.getBodyDocument();
        
        Dom.XMLNode rss = doc.getRootElement();
        System.debug('>>' + rss.getName());

        List<External_File__c> extFileList = new List<External_File__c>();
        List<Dom.XMLNode> rssList = new List<Dom.XMLNode>();
        for(Dom.XMLNode child : rss.getChildren()) {
           External_File__c ef = new External_File__c();
           for(Dom.XMLNode channel : child.getChildren()) {
               if(channel.getName() != null ) {
                    //System.debug('@@@@' + channel.getName() + ' = ' +channel.getText());
                   if( channel.getName() == 'File' ){
                        ef.File__c = channel.getText();
                        ef.File_URL__c =  (ef.File__c.substringAfter('href="') ).substringBefore('"');
                        ef.File_Type__c =  (ef.File__c.substringAfter('type="') ).substringBefore(';');
                        ef.File_Name__c = ef.File_URL__c.substring(ef.File_URL__c.lastIndexOf('/')+1);
                   }
                   else if( channel.getName() == 'Nid' ){
                       ef.Nid__c =  channel.getText();
                       System.debug('Nid__c = ' +  ef.Nid__c);
                   }
                   else if( channel.getName() == 'agile_eco_num' ){
                       ef.agile_eco_num__c =  channel.getText();
                   }
                   else if( channel.getName() == 'agile_english_parent_num' ){
                       ef.agile_english_parent_num__c =  channel.getText();
                   }
                   else if( channel.getName() == 'agile_part_num' ){
                       ef.agile_part_num__c  =  channel.getText();                   
                   }
                   else if( channel.getName() == 'Body' ){
                       ef.Body__c =  channel.getText();
                   }
                   else if( channel.getName() == 'Brand' ){
                       ef.Brand__c =  channel.getText();
                   }
                   else if( channel.getName() == 'Content-UUID' ){
                       ef.Content_UUID__c  =  channel.getText();
                   }
                   else if( channel.getName() == 'Display-Title' ){
                       ef.Display_Title__c  =  channel.getText();
                   }
                   else if( channel.getName() == 'Display-URL' ){
                       ef.Display_URL__c  =  channel.getText();
                   }
                   else if( channel.getName() == 'Document-type' ){
                       ef.Document_type__c   =  channel.getText();
                   }
                   else if( channel.getName() == 'Language' ){
                       ef.Language__c  =  channel.getText();
                   }
                   else if( channel.getName() == 'no-name' ){
                       ef.no_name__c  =  channel.getText();
                   }
                   else if( channel.getName() == 'Product-category' ){
                       ef.Product_category__c   =  channel.getText();
                   }
                   else if( channel.getName() == 'Published' ){
                       ef.Published__c   =  channel.getText();
                   }
                   else if( channel.getName() == 'System-Title' ){
                       ef.System_Title__c    =  channel.getText();
                   }
                   else if( channel.getName() == 'Updated-date' ){
                       ef.Updated_date__c     =  channel.getText();
                       try{
                           datetime startDate = datetime.newInstance(0);
                           ef.Update_DateTime__c  = startDate.addSeconds(Integer.valueOf(channel.getText()));
                       }catch(Exception e){
                           System.debug('GlobalPRM_RssRetrieval Update-dateTime Exception:'+e.getMessage());
                       }

                   }
               }
           }
           if (ef.Nid__c != null){
               String namex = ef.File_Name__c;
               if (namex.length() > 49){
                   namex = namex.substring(0, 49);
               }
               ef.Name = namex;
               ef.Update_Indication__c = true;
               extFileList.add(ef); 
           }     

        }
        system.debug( 'list size:' + extFileList.size() );
        system.debug(extFileList);
        upsert extFileList Nid__c;
        return rssList;
        
    }
}