You need to sign in to do that
Don't have an account?
abi dzar
How can I expose this code as webservice?
Hi guys,
How can I expose this so that it can be called as webservice.
I tried using webservice, but how can I return string in webservice function.
String keyword = 'something'; String query = 'FIND \'' + keyword + '\' RETURNING KnowledgeArticleVersion (title, Summary, UrlName WHERE PublishStatus=\'online\')'; List<List<SObject>> searchList = search.query(query); KnowledgeArticleVersion [] matchedArticle = ((List<KnowledgeArticleVersion>)searchList[0]); String XMLResult = '<?xml version="1.0" encoding="UTF-8" ?>'; XMLResult +='<articles>'; for( integer i =0; i< matchedArticle.size(); i++){ XMLResult +='<article>'; XMLResult +='<title>' + matchedArticle[i].Title + '</title>'; XMLResult +='<summary>' + matchedArticle[i].Summary + '</summary>'; XMLResult +='<url>' + matchedArticle[i].UrlName + '</url>'; XMLResult +='</article>'; } XMLResult +='</articles>';
regards,
Abi Dzar
Hi,
Try accessing Force.com Apex Code Developer's Guide and search for "WebService Methods".
The following is copy/pasted from the doc:
That shows exactly how you'd go about creating a class/method as a web service. In this case an Id is returned but of course you can just change that to String, if that's what you need.
Two main things to take notice of here:
Hope it helps.
/Søren Nødskov Hansen
Hi, Thanks for the reply,
I have done that. But, I'm still having the problem of calling it from other site.
do we need to have @future(callout=true) ?
regards,
Abi Dzar
Hi,
The future keyword has nothing to do with exposing a method as a web service. It only defines if the method should be executed asynchronously.
It would probably be easier to help you if you would post your code and more importantly the error you get when trying to call the method.
I quick guess could be the user you use to login to SF with in your client code doesn't have the necessary privileges to class with the web service method.
/Søren Nødskov Hansen