Calling the REST API in javascript using forcetk is pretty straightforward in a content
script:
function processSessionID(sessionID) {
var client = new forcetk.Client();
client.setSessionToken(sessionID);
client.query("SELECT Id, Name FROM Opportunity", function(response){
// do something with response, response is a list of Opportunities in this case
});
}
Using it from a popup seems a little more involved. Firstly, I think you would need to use a content script to setup the forcetk client and interact with Salesforce. Then, from your popup, you'd have to use messaging to communicate back and forth. For example, in your popup.js
:
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {method: "getOpportunities"}, function(response) {
console.log(response.opps);
});
});
Then, in your content
script, add a listener:
var client = new forcetk.Client();
client.setSessionToken(sessionID);
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if(request.method === 'getOpportunities') {
client.query('SELECT Id, Name FROM Opportunity',function(response) {
sendResponse({opps: response});
}
}
});
PS. I haven't tried this but seems like it should work.