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
Ramandeep_SinghRamandeep_Singh 

No Search Result

Hi all,
I am trying to search news on the bases of account name and in the search box account name is displayed but, on searching there is no news or not even related drop down topic.

Error
*********************************Wrapper Class**********************************
public with sharing class YahooRssWrapper {
    public class channel {
        public String title {get;set;}
        public String link {get;set;}
        public String description {get;set;}
        public String language {get;set;}
        public String category {get;set;}
        public String copyright {get;set;}
        public String pubDate {get;set;}
        public String ttl {get;set;}
        public YahooRssWrapper.image image {get;set;}
        public list<YahooRssWrapper.item> items {get;set;}
        public channel() {
            items = new list<YahooRssWrapper.item>();
        }
    }
     
    public class image {
        public String url {get;set;}
        public String title {get;set;}
        public String link {get;set;}
    }
     
    public class item {
        public String title {get;set;}
        public String guid {get;set;}
        public String link {get;set;}
        public String description {get;set;}
        public String pubDate {get;set;}
        public String source {get;set;}
        public Date getPublishedDate() {
            Date result = (pubDate != null) ? Date.valueOf(pubDate.replace('T', ' ').replace('Z','')) : null;
            return result;
        }
        public DateTime getPublishedDateTime() {
            DateTime result = (pubDate != null) ? DateTime.valueOf(pubDate.replace('T', ' ').replace('Z','')) : null;
            return result;            
        }
    }
     
    public static YahooRssWrapper.channel getRSSData(string feedURL) {
        //Todo Remove
        //feedURL ='http://news.search.yahoo.com/rss?ei=UTF-8&p=Rainmaker&fr=sfp';        
        HttpRequest req = new HttpRequest();
        req.setEndpoint(feedURL);
        req.setMethod('GET');        
        Dom.Document doc = new Dom.Document();
        String xmlDom = '';
        Http h = new Http();
        HttpResponse res; 
        if (!Test.isRunningTest()){ 
            try{
                res = h.send(req);
            }catch(Exception ex){
                return null;
            }
            // Generate the HTTP response as an XML stream          
            if(res.getBody() != null){              
                doc.load(res.getBody().replace('&', EncodingUtil.urlEncode('&','UTF-8')).replace('<![CDATA[','').replace(']]>',''));//res.getBody());
            }            
            
        } else {
            String xmlString = '<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xmlns:os="http://a9.com/-/spec/opensearch/1.1/"><channel><title>salesforce.com - Bing News</title><link>http://www.bing.com/news</link><description>Search Results for salesforce.com at Bing.com</description><category>News</category><os:totalResults>3370</os:totalResults><os:startIndex>0</os:startIndex><os:itemsPerPage>10</os:itemsPerPage><os:Query role="request" searchTerms="salesforce.com" /><copyright>These XML results may not be used, reproduced or transmitted in any manner or for any purpose other than rendering Bing results within an RSS aggregator for your personal, non-commercial use. Any other use requires written permission from Microsoft Corporation. By using these results in any manner whatsoever, you agree to be bound by the foregoing restrictions.</copyright><image><url>http://www.bing.com/s/a/rsslogo.gif</url><title>Bing</title><link>http://www.bing.com/news</link></image><docs>http://www.rssboard.org/rss-specification</docs><item><title>Salesforce.com Makes Friends With CIOs - Information Week</title><guid>http://informationweek.com/news/cloud-computing/software/232602782</guid><link>http://informationweek.com/news/cloud-computing/software/232602782</link><description>Parade of CIOs at CloudForce shows how social networking inroads are making Salesforce.com a larger part of the IT infrastructure. Salesforce.com isn&apos;t just for sales forces anymore. Its Chatter app has opened a social networking avenue into the enterprise ...</description><pubDate>2012-03-19T15:21:47Z</pubDate><source>Information Week</source></item></channel></rss>';
            doc.load(xmlString);
        }
         
        Dom.XMLNode rss = doc.getRootElement();
        //first child element of rss feed is always channel
        Dom.XMLNode channel = rss.getChildElements()[0];
         
        YahooRssWrapper.channel result = new YahooRssWrapper.channel();
         
        list<YahooRssWrapper.item> rssItems = new list<YahooRssWrapper.item>();
         
        //for each node inside channel        
        for(Dom.XMLNode elements : channel.getChildElements()) {
            if('title' == elements.getName()) {
                    System.debug(')))))))))))))))))'+elements);
                result.title = elements.getText();
            }
            if('link' == elements.getName()) {
                result.link = elements.getText();
            }
            if('description' == elements.getName()) {
                result.description = elements.getText();
            }
            if('category' == elements.getName()) {
                result.category = elements.getText();
            }
            if('copyright' == elements.getName()) {
                result.copyright = elements.getText();
            }
            if('ttl' == elements.getName()) {
                result.ttl = elements.getText();
            }
            if('image' == elements.getName()) {
                YahooRssWrapper.image img = new YahooRssWrapper.image();
                //for each node inside image
                for(Dom.XMLNode xmlImage : elements.getChildElements()) {
                    if('url' == xmlImage.getName()) {
                        img.url = xmlImage.getText();
                    }
                    if('title' == xmlImage.getName()) {
                        img.title = xmlImage.getText();
                    }
                    if('link' == xmlImage.getName()) {
                        img.link = xmlImage.getText();
                    }
                }
                result.image = img;
            }
             
            if('item' == elements.getName()) {
                YahooRssWrapper.item rssItem = new YahooRssWrapper.item();
                //for each node inside item
                for(Dom.XMLNode xmlItem : elements.getChildElements()) {                    
                    if('title' == xmlItem.getName()) {
                        rssItem.title = EncodingUtil.urlDecode(xmlItem.getText(),'UTF-8');
                    }
                    if('guid' == xmlItem.getName()) {
                        rssItem.guid = xmlItem.getText();
                    }
                    if('link' == xmlItem.getName()) {
                        rssItem.link = xmlItem.getText();
                    }
                    if('description' == xmlItem.getName()) {
                        rssItem.description = EncodingUtil.urlDecode(xmlItem.getText(),'UTF-8');
                    }
                    if('pubDate' == xmlItem.getName()) {
                        rssItem.pubDate = EncodingUtil.urlDecode(xmlItem.getText(),'UTF-8');
                    }
                    if('source' == xmlItem.getName()) {
                        rssItem.source = EncodingUtil.urlDecode(xmlItem.getText(),'UTF-8');
                    }
                }
                //for each item, add to rssItem list
                rssItems.add(rssItem);
            }
        }
        //finish YahooRssWrapper.channel object by adding the list of all rss items
        result.items = rssItems;        
        return result;
    }
     
}
***********************************************************************************

*************************************Class****************************************
public with sharing class RSSNewsReader { 
    public String rssQuery {get;set;}
    public boolean recordNotFound{get;set;}
    public String age{get;set;}     
    public YahooRssWrapper.channel rssFeed {get;set;}
    
    public RSSNewsReader(ApexPages.StandardController controller) {
        age = apexpages.currentpage().getparameters().get('age');
        String query = apexpages.currentpage().getparameters().get('q');
        if(age == null || age.trim().equals('')){
            age = '';
        }
        if(query == null || query.trim().equals('')){
                Account objAcc = [SELECT Name FROM Account WHERE Id=:controller.getRecord().Id ];
            rssQuery = ObjAcc.Name;//default on load
        } else{
            rssQuery = query;
            system.debug('@@@@@@' + rssQuery);
        }       
        init('http://news.search.yahoo.com/rss?p='+EncodingUtil.urlEncode(rssQuery,'UTF-8')+'&fr=sfp&age=' + age.trim());
    }


    private void init(String rssURL) {
        try{
            recordNotFound = true;
            rssFeed = YahooRssWrapper.getRSSData(rssURL);            
        }catch(Exception ex){
            recordNotFound = false;
        }
    }
    
     public pagereference getRSSFeed2() {  
        apexpages.currentpage().getparameters().put('q',rssQuery);      
        init('http://news.search.yahoo.com/rss?p='+EncodingUtil.urlEncode(rssQuery,'UTF-8')+'&fr=sfp&age=' + age.trim());        
        return null;
     }
}
************************************************************************************

*********************************Visualforcepage**********************************
<apex:page standardController="Account" showHeader="false" sidebar="false" extensions="RSSNewsReader">
<style type="text/css">
    body {
    font: 13px/1.231 arial,helvetica,clean,sans-serif;
    }

    #results .yschttl, #yschiy .yschttl {
    font-size: 123.1%;
    }

    #web h3 {
    font-weight: normal;
    }

    #results .res {
    margin-bottom: 17px;
    }

    .res {
    position: relative;
    }

    #web ol li a.yschttl:link, #web li .active a:link {
    color: #0000DE;
    }

    li {
    list-style: none;
    }

    #web .res .url {
    color: #A0A0A0;
    }

    #web .url, .yschurl {
    color: green;
    font-weight: bold;
    }

    h1 {
        border-bottom: 2px solid threedlightshadow;
        font-size: 160%;
        margin: 0 0 0.2em;
    }


    #feedSubtitleText {
        color: threeddarkshadow;
        font-size: 110%;
        font-weight: normal;
        margin: 0 0 0.6em;
    }

    .msg {
    background: #FEFBDD;
    margin-left: 128px;
    margin-right: 5px;
    padding: 9px;
    word-wrap: break-word;
    font-size: 16px;
    margin-bottom: 16px;
    padding-left: 11px;
    }
    #left-panel ul{list-syle:none}
    #left-panel ul li{padding:2px; margin:0;list-style:none;display:block;clear:left}
    #logo {
    height: 37px;
    left: -2px;
    margin-top: 0px;
    position: absolute;
    top: 1px;
    width: 168px;
    background-image: url(http://l.yimg.com/pv/i/all/vertical/news/us_srp_metro_news_201301281307.png);
    background-size: 80%;
    background-repeat: no-repeat;
    }
    .listHeading{
    color: #949FA6;
        font-size: 13px;
        font-weight: 400;
        margin: 0 0 3px 8px;
        text-transform: uppercase;
    }
    .listItems{
        margin: 0;
        padding: 5px 0;    
    }
    .listItems a{
        color: #1A4B8E;
        text-decoration: none;
        white-space: nowrap;    
    }

    #anyTime{
        color:{!IF($CurrentPage.parameters.age == '','black !important','#1A4B8E')};
    }
    #d1{
        color:{!IF($CurrentPage.parameters.age == '1d','black !important','#1A4B8E')};
    }
    #h1{
        color:{!IF($CurrentPage.parameters.age == '1h','black !important','#1A4B8E')};
    }
    #h1{
        color:{!IF($CurrentPage.parameters.age == '1w','black !important','#1A4B8E')};
    }
</style>
<apex:form id="yahooFormId">
<div>
    <div id="left-panel" style="width:9.9%; float:left;">
    <span id="logo"></span>        
        <ul style="margin:58px 0 0 10px; padding:2px 0;">
            <li class="listHeading">Filter by Time</li> 
            <li class="listItems"><a href="/apex/yahooRSSFeed?q={!rssQuery}&age=" id="anyTime">Any time</a></li>
            <li class="listItems"><a href="/apex/yahooRSSFeed?age=1h&q={!rssQuery}" id="h1">Past hour</a></li>
            <li class="listItems"><a href="/apex/yahooRSSFeed?age=1d&q={!rssQuery}" id="d1">Past day</a></li>
            <li class="listItems"><a href="/apex/yahooRSSFeed?age=1w&q={!rssQuery}" id="w2">Past week</a></li>        
        </ul>
    </div>
    <div id="results" style="width:90%; float:left; ">
        <div id="feedTitleContainer" style="margin-left: 58px;">
           <apex:inputText style="border-color: #929292 #D5D5D5 #D5D5D5 #929292;border-style: solid;border-width: 1px; height: 18px;
                padding: 3px 10px;width: 534px;" value="{!rssQuery}"/> 
           <apex:commandButton style="background: #FDCE3E;border: 1px solid #E5A716;color: #434343;height: 26px;margin-left: 7px;
                padding: 0 23px;font-size: 15px; font-weight: bold;" action="{!getRSSFeed2}" value="Search" reRender="yahooFormId"/>          
        </div>
        <div id="web" style="border-left:solid 1px #ccc;">
            <ol start="0">
                <apex:repeat value="{!rssFeed.items}" var="n">
                    <li>
                        <div class="res">
                            <div>
                                <h3>
                                    <a class="yschttl spt" href="{!n.link}">                                 
                                        <apex:outputText value="{!n.title}" escape="false"/> 
                                    </a>
                                </h3>
                            </div>
                    
                            <div class="abstr">
                                <apex:outputText value="{!n.Description}" escape="false"/>
                            </div>
                    
                            <span class="url">
                                <apex:outputText value="{!n.source} {!n.pubDate}" escape="false"/>
                            </span>
                        </div>
                    </li>
                </apex:repeat>
            </ol>    
        </div>
    </div>
</div>
<apex:outputPanel rendered="{!IF(OR(!recordNotFound, rssFeed.items == null, rssFeed.items.size == 0),true,false)}">
    <ol start="0">
        <li>
            <p class="msg zrpmsg">We did not find results for: <b>{!rssQuery}</b> <strong> </strong>. Try the suggestions below or type a new query above.</p>      
        </li>
    </ol>
</apex:outputPanel>
</apex:form>
</apex:page>

Please anyone help me out of this. It will be really grateful.

Thanks and Regards,
Ramandeep
Ramandeep_SinghRamandeep_Singh
Hi all,

I tried to copy and run this code 

https://sfdchack.blogspot.com/2013/04/yahoo-news-rss-feed-integration-with.html?m=1
But I am getting this exception  "EXCEPTION_THROWN [62]|System.XmlException: Failed to parse XML due to: unexpected markup <!d (position: START_DOCUMENT seen <!d... @1:3) "  

this exception is in YahooRssWraper.apxc.  some where after line 55 "res = h.send(req);"

***********************
Please respond.

Thanks and Regards
Ramandeep