Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6760705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:05:45+00:00 2026-05-26T14:05:45+00:00

I want to turn a Salesforce VisualForce Page into a widget for my corporate

  • 0

I want to turn a Salesforce VisualForce Page into a widget for my corporate website. I want to access the widget using server side code and a service account. I’ll cache, style, and output the widget html in my web page. I know I could just reproduce the widget with server side code and several API calls but I like the idea of being able to manage the widget in Salesforce and having the widget available for reuse elsewhere within Salesforce.

In this case, the widget is going to report on the current leaders in a contest we’re tracking in Salesforce. I plan on reusing this approach for other “mini-report widgets.” This is a very useful pattern. I’m sure somebody out there has elegantly solved it already. My searches have come up empty so far.

I was trying to avoid Sites because the user hitting our corporate website does not have a user account in Salesforce (now I’m thinking about a Site that allows anonymous access).

My first attempt looked like this (inspired by SSO to Self Service Portal):

var ws = new sfapi.SforceService();
var lr = ws.login(Secrets.salesforce_user_name, Secrets.salesforce_password);
string url = "https://na6.salesforce.com/apex/mywidget?sessionId=" + lr.sessionId;

I tried ?sid and ?csssid too, but urls like these just bounce me to the Salesforce login page:

https://na6.salesforce.com/apex/mywidget?sessionId=00D3000000myorg!my-session-id-from-logging-in-with-the-api-8_i2fX_9wnYdwnwatGVuX6jGjmVmnv50j78yfGF1aKHdoDFtIx_J9

I could probably use standard screen scraping techniques to post to the standard Salesforce login form with a username and password and then pull the /apex/mywidget page. But that feels clumsy and unsupported.

Now I’m thinking about making a new Site that is publicly available just to expose my widget. At least I could screen scrape that page with confidence.

Any help is appreciated. I’m going to play with the anonymous sites approach for now.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:05:46+00:00Added an answer on May 26, 2026 at 2:05 pm

    Rendering the data into a Visualforce page, then screenscraping it seems a bit brittle, not to mention inefficient – there is a better way…

    Define an Apex REST web service, then you can easily invoke that web service from your server side code, and still render it in Visualforce if you need to – you can call an Apex REST method like any other Apex method.

    Here’s a sample REST web service. I’m just returning a Map<String,String> here, but you can return any primitive type, any sObject or a List or Map of primitives or sObjects (as long as the Map has String keys) – see the Apex REST Web Services docs

    @RestResource(urlMapping='/MyResource/*')
    global with sharing class MyRestResource {
        @HttpGet
        global static Map<String,String> getResource() {
            Map<String,String> result = new Map<String,String>();
    
            result.put('key1', 'value1');
            result.put('key2', 'value2');
    
            return result;
        }
    }
    

    Here’s some PHP that calls it (I’ll assume you have an access token (aka session ID) and instance URL):

    $url = "$instance_url/services/apexrest/MyResource";
    $curl = curl_init($url);
    
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER,
      array("Authorization: OAuth $access_token",
        "Content-type: application/json"));
    
    $json_response = curl_exec($curl);
    
    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    
    if ( $status != 200 ) {
        die("Error: call to URL $url failed with status $status, ".
          "response $json_response\n");
    }
    
    $response = json_decode($json_response, true);
    
    echo "The service says ".$response['key1'].' '.$response['key2']."\n";
    
    curl_close($curl);
    

    And here’s a Visualforce page, if you want to show the same data

    <apex:page controller="TestRestController">
      <p>Controller says {!result}</p>
    </apex:page>
    

    The page controller:

    public class TestRestController {
        public String getResult() {
            Map<String, String> result = MyRestResource.getResource();
    
            return result.get('key1') + ' ' + result.get('key2');
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

so my code I want to turn into JSON is the following var locationData
I want to turn a program I have into a service so I can
I want to turn off JavaScript using JavaScript (and/or jQuery) code, only if the
I want to turn the following C# code into PHP. The C# is: byte[]
I want to turn my table rows into links using JS. I have it
I want to turn Model.attribute into Attribute.models. e.g. I currently have Model.first.attribute => string
I'm using jQuery Mobile and want to turn of Ajax handling because it does
I have a set of points that i want to turn into a closed
I have a list of objects which I want to turn into a set.
I created a console application, but I want to turn it into a windows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.