• Trinath Reddy
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 2
    Replies
<td><a href=" http://sites/operations/id=" target="_blank" style="font-size:15px">Link</a></td>Lightning 
Can anyone help me how to replace "http://sites/operations/id=" the url with Custom settings in  lightning.
I need to display title,URL and pubDate

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='Google-News';
        rssURL = 'URL link';
    }
    else if(Usr.UserRole.Name=='CFO'){
         displayMessage='Times of India-News';
         rssURL = 'URL link';
    
    }
    }@AuraEnabled
    public RSS.channel getRSSFeed() {
        return RSS.getRSSData(rssURL);
    }
}
------------------
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;
        }
        
}
Please find the below End point URL,I need to disply in VF page with title,link and pubdate which is there in the item section of end point url
https://news.google.com/news?cf=all&hl=en&pz=1&ned=us&topic=b&output=rss

 
Please check my below code and suggest for the same.
Page:
<apex:page standardController="FeedLinks__c" extensions="JSONParserUtil"   showheader="false" sidebar="false">
 <apex:pageBlock title="Feed News">
       <apex:pageMessages /><apex:outputText value="{!responsemsg}" />
             </apex:pageBlock>
  </apex:page>
Controller:
public class JSONParserUtil {

    public String jsonvalue { get; set; }
     public List<FeedLinks__c> lstlink{get;set;}
    public String responsemsg { get; set; }
   
    public JSONParserUtil(ApexPages.StandardController controller) {
    responsemsg='';
this.parseJSONResponse();
    }
 
    public void parseJSONResponse() {        
        Http httpProtocol = new Http();
        // Create HTTP request to send.
        HttpRequest request = new HttpRequest();
        // Set the endpoint URL.
        String endpoint = 'https://newsapi.org/v1/articles?source=the-next-web&sortBy=latest&apiKey=89edf61c78424b0a8dcafc4f9739f031';
        request.setEndPoint(endpoint);
        // Set the HTTP verb to GET.
        request.setMethod('GET');
        // Send the HTTP request and get the response.
        // The response is in JSON format.
        HttpResponse response = httpProtocol.send(request);
        System.debug(response.getBody());
        if (response.getStatusCode() == 200) {
      JSONParser parser = JSON.createParser(response.getBody());
        system.debug('Parser='+parser);
        lstlink=new List<FeedLinks__c>();
        
        while (parser.nextToken() != null) {
            responsemsg+= parser.gettext();
             parser.nextToken();
             
                }
              system.debug('response msg='+responsemsg);
                
            }
        } 
        public class jsonvalue{
        
         public String title{get;set;}
         Public String description {get;set;}
        
        }
}
I am geeting Http response  like:
{"status":"ok","source":"the-next-web","sortBy":"latest","articles":[{"author":"Rachel Kaser","title":"Donuts delivered via drone is the future we all imagined","description":"This Wednesday, a Denver-based bakery, in collaboration with Texas-based company Drone Dispatch, delivered fresh donuts to the Denver city officials via drone. Recipients include policemen, ...","url":"https://thenextweb.com/insider/2017/06/01/donuts-delivered-via-drone-future-imagined/","urlToImage":"https://cdn0.tnwcdn.com/wp-content/blogs.dir/1/files/2017/06/Drone-donuts.jpg","publishedAt":"2017-06-01T03:13:11Z"},
 I am geeting Vf page output like:
{okthe-next-weblatest[authortitledescriptionurlurlToImagepublishedAt}
Excepted output format  should be like;
tille:Donuts delivered via drone is the future we all imagined
description:This Wednesday, a Denver-based bakery, in collaboration with Texas-based company Drone Dispatch, delivered fresh donuts to the Denver city officials via drone. Recipients include policemen
url:https://thenextweb.com/insider/2017/06/01/donuts-delivered-via-drone-future-imagined/
publishedAt:2017-06-01T03:13:11Z
Please check my below code and suggest for the same.
Page:
<apex:page standardController="FeedLinks__c" extensions="JSONParserUtil"   showheader="false" sidebar="false">
 <apex:pageBlock title="Feed News">
       <apex:pageMessages /><apex:outputText value="{!responsemsg}" />
             </apex:pageBlock>
  </apex:page>
Controller:
public class JSONParserUtil {

    public String jsonvalue { get; set; }
     public List<FeedLinks__c> lstlink{get;set;}
    public String responsemsg { get; set; }
   
    public JSONParserUtil(ApexPages.StandardController controller) {
    responsemsg='';
this.parseJSONResponse();
    }
 
    public void parseJSONResponse() {        
        Http httpProtocol = new Http();
        // Create HTTP request to send.
        HttpRequest request = new HttpRequest();
        // Set the endpoint URL.
        String endpoint = 'https://newsapi.org/v1/articles?source=the-next-web&sortBy=latest&apiKey=89edf61c78424b0a8dcafc4f9739f031';
        request.setEndPoint(endpoint);
        // Set the HTTP verb to GET.
        request.setMethod('GET');
        // Send the HTTP request and get the response.
        // The response is in JSON format.
        HttpResponse response = httpProtocol.send(request);
        System.debug(response.getBody());
        if (response.getStatusCode() == 200) {
      JSONParser parser = JSON.createParser(response.getBody());
        system.debug('Parser='+parser);
        lstlink=new List<FeedLinks__c>();
        
        while (parser.nextToken() != null) {
            responsemsg+= parser.gettext();
             parser.nextToken();
             
                }
              system.debug('response msg='+responsemsg);
                
            }
        } 
        public class jsonvalue{
        
         public String title{get;set;}
         Public String description {get;set;}
        
        }
}
I am geeting Http response  like:
{"status":"ok","source":"the-next-web","sortBy":"latest","articles":[{"author":"Rachel Kaser","title":"Donuts delivered via drone is the future we all imagined","description":"This Wednesday, a Denver-based bakery, in collaboration with Texas-based company Drone Dispatch, delivered fresh donuts to the Denver city officials via drone. Recipients include policemen, ...","url":"https://thenextweb.com/insider/2017/06/01/donuts-delivered-via-drone-future-imagined/","urlToImage":"https://cdn0.tnwcdn.com/wp-content/blogs.dir/1/files/2017/06/Drone-donuts.jpg","publishedAt":"2017-06-01T03:13:11Z"},
 I am geeting Vf page output like:
{okthe-next-weblatest[authortitledescriptionurlurlToImagepublishedAt}
Excepted output format  should be like;
tille:Donuts delivered via drone is the future we all imagined
description:This Wednesday, a Denver-based bakery, in collaboration with Texas-based company Drone Dispatch, delivered fresh donuts to the Denver city officials via drone. Recipients include policemen
url:https://thenextweb.com/insider/2017/06/01/donuts-delivered-via-drone-future-imagined/
publishedAt:2017-06-01T03:13:11Z
Please find the below End point URL,I need to disply in VF page with title,link and pubdate which is there in the item section of end point url
https://news.google.com/news?cf=all&hl=en&pz=1&ned=us&topic=b&output=rss

 
Please check my below code and suggest for the same.
Page:
<apex:page standardController="FeedLinks__c" extensions="JSONParserUtil"   showheader="false" sidebar="false">
 <apex:pageBlock title="Feed News">
       <apex:pageMessages /><apex:outputText value="{!responsemsg}" />
             </apex:pageBlock>
  </apex:page>
Controller:
public class JSONParserUtil {

    public String jsonvalue { get; set; }
     public List<FeedLinks__c> lstlink{get;set;}
    public String responsemsg { get; set; }
   
    public JSONParserUtil(ApexPages.StandardController controller) {
    responsemsg='';
this.parseJSONResponse();
    }
 
    public void parseJSONResponse() {        
        Http httpProtocol = new Http();
        // Create HTTP request to send.
        HttpRequest request = new HttpRequest();
        // Set the endpoint URL.
        String endpoint = 'https://newsapi.org/v1/articles?source=the-next-web&sortBy=latest&apiKey=89edf61c78424b0a8dcafc4f9739f031';
        request.setEndPoint(endpoint);
        // Set the HTTP verb to GET.
        request.setMethod('GET');
        // Send the HTTP request and get the response.
        // The response is in JSON format.
        HttpResponse response = httpProtocol.send(request);
        System.debug(response.getBody());
        if (response.getStatusCode() == 200) {
      JSONParser parser = JSON.createParser(response.getBody());
        system.debug('Parser='+parser);
        lstlink=new List<FeedLinks__c>();
        
        while (parser.nextToken() != null) {
            responsemsg+= parser.gettext();
             parser.nextToken();
             
                }
              system.debug('response msg='+responsemsg);
                
            }
        } 
        public class jsonvalue{
        
         public String title{get;set;}
         Public String description {get;set;}
        
        }
}
I am geeting Http response  like:
{"status":"ok","source":"the-next-web","sortBy":"latest","articles":[{"author":"Rachel Kaser","title":"Donuts delivered via drone is the future we all imagined","description":"This Wednesday, a Denver-based bakery, in collaboration with Texas-based company Drone Dispatch, delivered fresh donuts to the Denver city officials via drone. Recipients include policemen, ...","url":"https://thenextweb.com/insider/2017/06/01/donuts-delivered-via-drone-future-imagined/","urlToImage":"https://cdn0.tnwcdn.com/wp-content/blogs.dir/1/files/2017/06/Drone-donuts.jpg","publishedAt":"2017-06-01T03:13:11Z"},
 I am geeting Vf page output like:
{okthe-next-weblatest[authortitledescriptionurlurlToImagepublishedAt}
Excepted output format  should be like;
tille:Donuts delivered via drone is the future we all imagined
description:This Wednesday, a Denver-based bakery, in collaboration with Texas-based company Drone Dispatch, delivered fresh donuts to the Denver city officials via drone. Recipients include policemen
url:https://thenextweb.com/insider/2017/06/01/donuts-delivered-via-drone-future-imagined/
publishedAt:2017-06-01T03:13:11Z