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

Example Sample HelloWorld WebService needed

I need examples for the foll:

1) How to create Sample HelloWorld WebService using Apex?.

2) How to generate WSDL for this Sample HelloWorld WebService ?. 

3) How to consume that Sample HelloWorldWebService in VisualForce page?..


Any Help would be appreciated.







Apex class methods can be exposed as custom Web Services API calls. Use the webService keyword to define these methods. For example:
global class HelloWorldWebService {
webService static string sayHello(String h) {
h = 'Hello World!';
return h;
You can download a WSDL from the Apex class detail page:
  1. In the application navigate to Setup | Develop | Apex Classes.
  2. Click the name of a class that contains webService methods.
  3. Click Generate WSDL.
var docURL = "apex_web_services_methods.htm";var docVersion = "16.0";var docType="APEX";var docFunctionalArea = "Online Help/Tip Sheets";

Thank you for Replying to my ques.


Can you please send me the complete code for consume the Webservice in VisualSource Page (BestPractices)?.


Will be waiting for ur reply:)


Hi ,

While invking the HelloWorld WebService  from page I am getting the foll exception.


exception occured after webservc call.System.CalloutException: IO Exception: Unauthorized endpoint, please check Setup->Security->Remote site settings. endpoint =



global class HelloWorldWebService {
   webService static string sayHello() {
        return 'Hello World!';


public class HelloWorldWSContoller{
    String uname="KK";
    public String getUsername() {
        return uname;
    public String getHelloWorld() {
        string result; 
        HelloworldServiceWSDL2Apex.HelloWorldWebService stub = new HelloworldServiceWSDL2Apex.HelloWorldWebService();
        uname = stub.sayHello();
        return result ;  




<apex:page controller="HelloWorldWSContoller" tabStyle="Account">
<apex:form >
        <!-- Define the JavaScript function sayHello-->
        <apex:actionFunction name="HelloWorld" action="{!getHelloWorld}"/>
      <apex:outputText value="{!Username}"/>
 <apex:outputText value="KK"/>



Anyhelp is appreciated.




After adding external server to Remote Sites, i am getting the following exception:


exception occured after webservc call.System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session faultcode=sf:INVALID_SESSION_ID faultactor=

Marty Y. ChangMarty Y. Chang

Hello, KrishnakumarJ.  I believe you need to set the sessionId after logging in, as shown in the code for the wrapper class in the following tutorial.


"NO-SOFTWARE Tutorial for Salesforce Web Services"


Hello Krishna,


Have you used two salesforce instances for this?


Even im working on same, can u brief the process of executing it.




hey street,


were you able to make this working?


even i need one example








same question to krishna too!!

were u able to solve this??


I was working on two sandbox instances. 


Hi KrishnaKumar,

      i executed above code but i am getting some error

ErrorError: HelloWorldWSContoller Compile Error: Invalid type: HelloworldServiceWSDL2Apex.HelloWorldWebService at line 9 column 67

please tell me what i will do for execute that code




Hello Krishna can u provide your complete code, i am also trying to implement webservice..


Hi am also getting the same error when I try to execute this one.

Error: HelloWorldWSContoller Compile Error: Invalid type: HelloworldServiceWSDL2Apex.HelloWorldWebService at line 9 column 67


can anyone solve this?




Did you execute these code? Is it code correct.


i have error occurred while save my apex class.

Ramesh KallooriRamesh Kalloori
Hi All,

I have created web service please go through the below code.

global class HelloWorldWebService { 
   webService static string sayHello() {
        return 'Hello World!'; 
<apex:page controller="HelloWorldWSContoller" tabStyle="Account">
<apex:form >
public class HelloWorldWSContoller{
    public String val{get;set;}
      public HelloWorldWSContoller()
           val = HelloWorldWebService.sayHello();

and create the remote site settings as HelloWorldWebservice after generating WSDL from HelloWorldWebservice class.