+ Start a Discussion
Kumar GKumar G 

An internal server error has occurred Error ID: 1520747772-53556 (1910990207)

Hi 

Here i am trying to create a Lightning component instead of VF Page , while doing this i recieved following error : An internal server error has occurred Error ID: 1520747772-53556 (1910990207)

Please find the code in "code sample" and share your valuable inputs to overcome this error
Component Code : 
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" 
                access="global" controller="JSONParserUtil">
    <aura:attribute name="feeds" type="feed[]"/>	 
    <aura:handler name="init" value="{!this}" action="{!c.getfeed}"/>
	<header align="center">
        <h1 class="slds-text-heading--large"  style="color:blue;text-align:center;border-bottom:3px solid blue" ><li>News</li></h1><br/>
    </header>
    
    <table class="slds-table slds-table--bordered slds-table--fixed-layout slds-scrollable--y" role="grid">	       
    <thead>
        <tr class="slds-text-heading--label ">        
                <th style="width:100px;" class="slds-is-sortable slds-is-resizable slds-text-title--caps slds-has-focus" scope="col" >
                  <a href="javascript:void(0);" class="slds-th__action slds-text-link--reset" tabindex="0">
                      <span class="slds-assistive-text">Sort </span>
                      <span class="slds-truncate" title="Title">Title</span>
                      <div class="slds-icon_container">
                      </div>
                      <span class="slds-assistive-text" aria-live="assertive" aria-atomic="true"></span>
                     </a>
                    <div class="slds-resizable">
                      <label for="cell-resize-handle-553" class="slds-assistive-text">Name column width</label>
                      <input type="range" min="20" max="1000" class="slds-resizable__input slds-assistive-text" id="cell-resize-handle-553" tabindex="0" />
                      <span class="slds-resizable__handle">
                        <span class="slds-resizable__divider"></span>
                      </span>
                    </div>
                   </th>	 	 	 
          </tr>  
    </thead>
    </table>
    <tbody>    
      <aura:iteration items="{!V.feeds}" var="art">
          <tr class="slds-hint-parent">				
				<td role="gridcell">
                     <div class="slds-truncate" title="Task Owner Name">{!art.title}</div>
               </td>
         </tr>                
     </aura:iteration>		 
    </tbody>    
</aura:component>


Controller :
({
getfeed : function(component,event, helper) 
        {
        helper.getfeed(component);
    	}
})


Helper : 

({
  getfeed : function(component) 
    {
        var action = component.get("c.getRSSData");
        
            if (a.getState() === "SUCCESS") {
            component.set("v.feeds", a.getReturnValue());
            } else if (a.getState() === "ERROR") {
            $A.log("callback error", a.getError());
    }   
	}
})

Controller in classic : 

public class RSS {
    public class channel {
       public list<RSS.item> items {get;set;}
        public channel() {
            items = new list<RSS.item>();
        }
    }
    public class item {
        public String title {get;set;}
        public String link {get;set;}
        public String pubDate {get;set;}
        public String getUrl() {
            String result = (link != null) ? link.substringAfterLast('url=') : null;
            return result;
        }
        public DateTime getPublishedDateTime() {
            DateTime result = (pubDate != null) ? DateTime.valueOf(pubDate.replace('T', ' ').replace('Z','')) : null;
            return result;
        }
    }
    public static RSS.channel getRSSData(string feedURL) 
	{
        HttpRequest req = new HttpRequest();
        req.setEndpoint(feedURL);
        req.setMethod('GET');
        Dom.Document doc = new Dom.Document();
        Http h = new Http();
        HttpResponse res = h.send(req);
        doc = res.getBodyDocument();
        Dom.XMLNode rss = doc.getRootElement();
		
		
        //first child element of rss feed is always channel
        Dom.XMLNode channel = rss.getChildElements()[0];
        RSS.channel result = new RSS.channel();
        list<RSS.item> rssItems = new list<RSS.item>();
       for(Dom.XMLNode elements : channel.getChildElements()) {
        if('item' == elements.getName()) {
                RSS.item rssItem = new RSS.item();
				
				
                //for each node inside item
                for(Dom.XMLNode xmlItem : elements.getChildElements()) {
                    if('title' == xmlItem.getName()) {
                        rssItem.title = xmlItem.getText();
                    }
                    if('link' == xmlItem.getName()) {
                        rssItem.link = xmlItem.getText();
                    }
                   if('pubDate' == xmlItem.getName()) {
                        rssItem.pubDate = xmlItem.getText();
                    }
                }
				
				
                //for each item, add to rssItem list
                rssItems.add(rssItem);
            }
          }
            //finish RSS.channel object by adding the list of all rss items
        result.items = rssItems;
        return result;
    }
        
}

 
Prathyu bPrathyu b
Hi kumar
update your helper with the below code:
({
    getfeedHelpr : function() {
        var action = component.get("c.getRSSData");
        action.setCallback(this, function(a) {
        if (a.getState() === "SUCCESS") {
            component.set("v.feeds", a.getReturnValue());
        } 
        else if (a.getState() === "ERROR") {
            $A.log("callback error", a.getError());
        }
        });
        $A.enqueueAction(action);
    }
})


 
Kumar GKumar G
Hi Prathyu,

Thanks for your response.

I have updated helper with the above code , still i am getting the same error.

If you need more INFO on this please let me know.





 
Prathyu bPrathyu b
Kumar,

public static RSS.channel getRSSData(string feedURL) { ---}
This is the apex method you are calling from helper.js right??
for this method you have to pass feedURL as a argument in helper.js ...Like:
action.setParams({"feedURL":url});
check this for more info on how to pass arguments in lightning :
 https://salesforce.stackexchange.com/questions/123120/passing-parameter-from-lightning-js-controller-to-apex-class
Let me know if it works 
Kumar GKumar G
Hi Prathyu,

I have replaced code mentioned in the code sample , this time no error is coming but values(Title) are not returning.

RSS class mentioned above is calling from onother class may be this is the reason for not returning values ?

Please find the class(RSSNewsReader ) which is calling RSS class  in code sample section.
({
    getfeed : function() {
    var fd = component.get("c.getRSSData");
        fd.setParams({"feedURL":url});
        fd.setCallback(this, function(a)) {
        component.set("v.feeds", a.getReturnValue());
        }
        $A.enqueueAction(fd);
    }
})


public class RSSNewsReader {
    public String rssQuery {get;set;}
    private String rssURL {get;set;}
    public String displayMessage { get; set; }
    
    public RSSNewsReader() {
    
    User Usr = [SELECT UserRole.Name FROM User WHERE Id = : UserInfo.getUserId()];
         system.debug('Usr.UserRole.Name'+ Usr.UserRole.Name);
         
         if(Usr.UserRole.Name=='CEO'){
         displayMessage='Samsung-News';
        rssURL = 'https://news.google.com/news?cf=all&hl=en&pz=1&ned=us&q=IBM&output=rss';
    }
    else if(Usr.UserRole.Name=='CFO'){
         displayMessage='IBM-News';
         rssURL = 'https://news.google.com/news?cf=all&hl=en&pz=1&ned=us&q=IBM&output=rss';
    
    }
    }
    public RSS.channel getRSSFeed() {
        return RSS.getRSSData(rssURL);
    }
}




 
Kumar GKumar G
Hi Prathyu,

I have replaced code mentioned in the code sample , this time no error is coming but values(Title) are not returning.

RSS class mentioned above is calling from onother class may be this is the reason for not returning values ?

Please find the class(RSSNewsReader ) which is calling RSS class  in code sample section.
({
    getfeed : function() {
    var fd = component.get("c.getRSSData");
        fd.setParams({"feedURL":url});
        fd.setCallback(this, function(a)) {
        component.set("v.feeds", a.getReturnValue());
        }
        $A.enqueueAction(fd);
    }
})


public class RSSNewsReader {
    public String rssQuery {get;set;}
    private String rssURL {get;set;}
    public String displayMessage { get; set; }
    
    public RSSNewsReader() {
    
    User Usr = [SELECT UserRole.Name FROM User WHERE Id = : UserInfo.getUserId()];
         system.debug('Usr.UserRole.Name'+ Usr.UserRole.Name);
         
         if(Usr.UserRole.Name=='CEO'){
         displayMessage='Samsung-News';
        rssURL = 'https://news.google.com/news?cf=all&hl=en&pz=1&ned=us&q=IBM&output=rss';
    }
    else if(Usr.UserRole.Name=='CFO'){
         displayMessage='IBM-News';
         rssURL = 'https://news.google.com/news?cf=all&hl=en&pz=1&ned=us&q=IBM&output=rss';
    
    }
    }
    public RSS.channel getRSSFeed() {
        return RSS.getRSSData(rssURL);
    }
}




 
Prathyu bPrathyu b
Ok..
Below are the changes :
1. If the apex method is in RSSNewsReader  controller class then you haev to update the controlelr = 'RSSNewsReader' in component Like
<aura:component implements="force:appHostable" controller="RSSNewsReader">    
    <aura:handler name="init" value="{!this}" action="{!c.getfeed }"/>
</aura:component>

2. If apex controller methos is a lightning method then you have to add below to your method:

public class RSSNewsReader{
    @AuraEnabled      
    public static JSONParserUtil.channel getRSSFeed() {
        String rssQuery;
        String rssURL;
        String displayMessage;
         User Usr = [SELECT UserRole.Name FROM User WHERE Id = : UserInfo.getUserId()];
        system.debug('Usr.UserRole.Name'+ Usr.UserRole.Name);         
        if(Usr.UserRole.Name=='CEO'){
            displayMessage='Samsung-News';
            rssURL = 'https://news.google.com/news?cf=all&hl=en&pz=1&ned=us&q=IBM&output=rss';
        }
        else if(Usr.UserRole.Name=='CFO'){
            displayMessage='IBM-News';
            rssURL = 'https://news.google.com/news?cf=all&hl=en&pz=1&ned=us&q=IBM&output=rss';    
        }
        system.debug('in call to method');
        return JSONParserUtil.getRSSData(rssURL);
    }
}

Note:  1. @AuraEnabled  is must for lightning methods
           2. method should be static
So update your class with the above.
 and Add debugs to the JSONParserUtil class method to know the result like:
         result.items = rssItems;
        system.debug('final result '+result);  // add this statement in your JSONParserUtil  class
        return result;

3. update helper with below:
({
    getfeed : function(component) {
        console.log('in helper call');
        var action = component.get("c.getRSSFeed");
        action.setCallback(this, function(a) {
        if (a.getState() === "SUCCESS") {
           component.set("v.feeds", a.getReturnValue());
           console.log('return value '+a.getReturnValue());
        } 
        else if (a.getState() === "ERROR") {
            $A.log("callback error", a.getError());
        }
        });
        $A.enqueueAction(action);        
    }
})

Check the output in debug logs for the output if you face any issues 

I think you are new to lightning. Please complete the trailhead to get more understanding on how the logic will work in lightning
https://trailhead.salesforce.com/projects/slds-lightning-components-workshop/steps/slds-lc-4

Let me know if you have any