You need to sign in to do that
Don't have an account?
jpwagner
button to obtain html blob
Hi,
I'm looking to create a button that obtains an html blob from a URL (in the real implementation I'd actually be parsing that html to find some piece of information, but that's not important.)
So far I believe this is a pretty straight forward class to get that info:
global class htmlblob {
webservice static String getblob(String someurl) {
PageReference pageRef = new PageReference(someurl);
String htmlblob = pageRef.getContent().toString();
return htmlblob;
}
}
and I'm calling that class from the button like this:
{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js" )}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js" )}
var someurl = '/{!Opportunity.Id}';
var records = {!GETRECORDIDS($ObjectType.Opportunity)};
var result = sforce.apex.execute("htmlblob","getblob",{a:someurl});
var myObj = new sforce.SObject("Opportunity" );
myObj.id = records[0];
myObj.htmlblob__c = result.substring(0,50);
sforce.connection.update([myObj]);
window.parent.location="/"+'{!Opportunity.Id}';
Just a reminder that I don't actually care about saving the blob to a field so if that's a problem for some reason, I can parse it first, I just want to validate that I am receiving the correct data back.
Any help on this is appreciated!
Thanks
Ok figured it all out.
Couple of rookie mistakes.
1. can't use substring (was the issue with initial post)
2. update function must be webservice method (issue in second post)
hope this is a helpful reference.
{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}
var someurl = '/somepartialurl';
var result = sforce.apex.execute("htmlblob","getblob",{a:someurl});
var oppid = '{!Opportunity.Id}';
sforce.apex.execute("htmlblob","writeblob",{a:result, b:oppid});
window.parent.location="/"+'{!Opportunity.Id}';
All Answers
New piece of info:
If I take out the update, (which I think I screwed up anyway by not including whatever needs to be included to create a new sobject) I can see that it correctly grabs the html:
var result = sforce.apex.execute("htmlblob","getblob",{a:someurl});
alert(result);
window.parent.location="/"+'{!Opportunity.Id}';
If I then write a method to update the Opportunityfield with this result, it fails with a cryptic popup error:
'push' is null or not an object
Any thoughts on this?
THANKS!
Ok figured it all out.
Couple of rookie mistakes.
1. can't use substring (was the issue with initial post)
2. update function must be webservice method (issue in second post)
hope this is a helpful reference.
{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}
var someurl = '/somepartialurl';
var result = sforce.apex.execute("htmlblob","getblob",{a:someurl});
var oppid = '{!Opportunity.Id}';
sforce.apex.execute("htmlblob","writeblob",{a:result, b:oppid});
window.parent.location="/"+'{!Opportunity.Id}';