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
baller4life7baller4life7 

STOCK market information for accounts

Hi guys,

I was wondering what would be the best solution to provide stock quotes and charts for an account on its detail page...

Do you already have solutions for that?

Best Answer chosen by Admin (Salesforce Developers) 
newcloudcodernewcloudcoder

<apex:page controller="GetStockController"> 

<apex:form >     

<apex:pageblock >         

<apex:pageblockSection >             

Stock Code <apex:inputtext value="{!stockCode}" />             

<apex:commandButton value="Get Value" action="{!getStockValue}"/>             

<apex:outputlabel value="{!stockValue}"></apex:outputlabel>         

</apex:pageblockSection>     

</apex:pageblock> 

</apex:form>

</apex:page>


public class GetStockController {
    public string stockCode{get;set;}   

   public string stockValue {get;set;}       

  public void getStockValue(){           

 

StockQuoteClient.StockQuoteSoap client = new StockQuoteClient.StockQuoteSoap();               

String retValue = client.GetQuote(stockCode);       

system.debug('val = '+retValue);               

XMLDom parser = new XMLDom(retValue);               

stockValue = parser.getElementByTagName('Name').textContent()+' : ' +parser.getElementByTagName('Last').textContent();                }

 }

 

 

Tag Names has been extracted from the document below. You can use the tagnames as u wish and depends on the information you would like to put up on your page.


http://www.webservicex.net/stockquote.asmx/GetQuote

This XML file does not appear to have any style information associated with it. The document tree is shown below.<string xmlns="http://www.webserviceX.NET/"><StockQuotes><Stock><Symbol>GOOG</Symbol><Last>534.18</Last><Date>9/7/2011</Date><Time>3:35pm</Time><Change>+12.00</Change><Open>529.97</Open><High>535.939</High><Low>527.40</Low><Volume>2072544</Volume><MktCap>172.5B</MktCap><PreviousClose>522.18</PreviousClose><PercentageChange>+2.30%</PercentageChange><AnnRange>463.02 - 642.96</AnnRange><Earns>27.719</Earns><P-E>18.84</P-E><Name>Google Inc.</Name></Stock></StockQuotes></string>

 

 

Hope this helps.. 

 

truly NCC

All Answers

newcloudcodernewcloudcoder

As per my knowledge,

You need to call up a webservice for that, and then include few custom fields in the account page to display the company relevant stock information.

 

regards Naveen

 

baller4life7baller4life7

Thank you newcloudcoder!

Which webservices do you know? Are they free?

newcloudcodernewcloudcoder

 

 I knew of webservicex.net. If you browse their website, you do find their services for free.. u can find the link to their WSDL file. Use that to call their webservice. Hope you know the procedures. go to www.webservicex.net

 

regards

NCC

 

baller4life7baller4life7

Thanks for the link!

 

I generated the following class:

 

//Generated by wsdl2apex

public class StockQuotes {
    public class GetQuote_element {
        public String symbol;
        private String[] symbol_type_info = new String[]{'symbol','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://www.webserviceX.NET/','true','false'};
        private String[] field_order_type_info = new String[]{'symbol'};
    }
    public class StockQuoteSoap {
        public String endpoint_x = 'http://www.webservicex.net/stockquote.asmx';
        public Map<String,String> inputHttpHeaders_x;
        public Map<String,String> outputHttpHeaders_x;
        public String clientCertName_x;
        public String clientCert_x;
        public String clientCertPasswd_x;
        public Integer timeout_x;
        private String[] ns_map_type_info = new String[]{'http://www.webserviceX.NET/', 'StockQuotes'};
        public String GetQuote(String symbol) {
            StockQuotes.GetQuote_element request_x = new StockQuotes.GetQuote_element();
            StockQuotes.GetQuoteResponse_element response_x;
            request_x.symbol = symbol;
            Map<String, StockQuotes.GetQuoteResponse_element> response_map_x = new Map<String, StockQuotes.GetQuoteResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'http://www.webserviceX.NET/GetQuote',
              'http://www.webserviceX.NET/',
              'GetQuote',
              'http://www.webserviceX.NET/',
              'GetQuoteResponse',
              'StockQuotes.GetQuoteResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.GetQuoteResult;
        }
    }
    public class GetQuoteResponse_element {
        public String GetQuoteResult;
        private String[] GetQuoteResult_type_info = new String[]{'GetQuoteResult','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://www.webserviceX.NET/','true','false'};
        private String[] field_order_type_info = new String[]{'GetQuoteResult'};
    }
}

However I have no clue how to use it ...  How can I get the stock quotes in a visualforce page now?

newcloudcodernewcloudcoder

<apex:page controller="GetStockController"> 

<apex:form >     

<apex:pageblock >         

<apex:pageblockSection >             

Stock Code <apex:inputtext value="{!stockCode}" />             

<apex:commandButton value="Get Value" action="{!getStockValue}"/>             

<apex:outputlabel value="{!stockValue}"></apex:outputlabel>         

</apex:pageblockSection>     

</apex:pageblock> 

</apex:form>

</apex:page>


public class GetStockController {
    public string stockCode{get;set;}   

   public string stockValue {get;set;}       

  public void getStockValue(){           

 

StockQuoteClient.StockQuoteSoap client = new StockQuoteClient.StockQuoteSoap();               

String retValue = client.GetQuote(stockCode);       

system.debug('val = '+retValue);               

XMLDom parser = new XMLDom(retValue);               

stockValue = parser.getElementByTagName('Name').textContent()+' : ' +parser.getElementByTagName('Last').textContent();                }

 }

 

 

Tag Names has been extracted from the document below. You can use the tagnames as u wish and depends on the information you would like to put up on your page.


http://www.webservicex.net/stockquote.asmx/GetQuote

This XML file does not appear to have any style information associated with it. The document tree is shown below.<string xmlns="http://www.webserviceX.NET/"><StockQuotes><Stock><Symbol>GOOG</Symbol><Last>534.18</Last><Date>9/7/2011</Date><Time>3:35pm</Time><Change>+12.00</Change><Open>529.97</Open><High>535.939</High><Low>527.40</Low><Volume>2072544</Volume><MktCap>172.5B</MktCap><PreviousClose>522.18</PreviousClose><PercentageChange>+2.30%</PercentageChange><AnnRange>463.02 - 642.96</AnnRange><Earns>27.719</Earns><P-E>18.84</P-E><Name>Google Inc.</Name></Stock></StockQuotes></string>

 

 

Hope this helps.. 

 

truly NCC

This was selected as the best answer
baller4life7baller4life7

If you add the XMLDom class and http://www.webservicex.net/stockquote.asmx  to the remote sites, it works perfect! Thank you very much!

newcloudcodernewcloudcoder

Yeah..Sorry for skipping that step..It was out of my mind.. Anyways I'm happy.