+ Start a Discussion
TryCodingTryCoding 

How to Call WebService Method in Java

Hi all,

I am trying to use apex class webService method in java. But it is giving following error


 

Exception in thread "main" AxisFault


Details are as following

Apex Class

 

 

global class WebServiceAccountPlan {
 
   
   global class Plan {
      webservice String name;
      webservice Integer planNumber;
      webservice Date planningPeriod;
      webservice Id planId;
   }
 
   webservice static Plan createAccountPlan(Plan vPlan) {
       
       Account acct = new Account();
       acct.Name = vPlan.name;
       acct.AccountNumber = String.valueOf(vPlan.planNumber);
       insert acct;
       vPlan.planId=acct.Id;
       return vPlan;
  }
   
}

 

 

 

Java Code:

 

 

public class trySendingEmail {

 

 public static void main(String[] args) throws Exception {

 login();         //general login code in method

 //sendEmail();

 WebServiceAccountPlanBindingStub wbind = new WebServiceAccountPlanBindingStub();

 Plan vPlan = new Plan();

 vPlan.setName( "Namita");

 vPlan.setPlanId("abcdNewPlan");

 vPlan.setPlanningPeriod(null);

 vPlan.setPlanNumber(1234);

 

// This line gives the error

 Plan endresult = wbind.createAccountPlan(vPlan);

 //System.out.println("----------------"+endresult);

 }

 

 

}

 

Can anybody please tell me where am i going wrong

 

Best Answer chosen by Admin (Salesforce Developers) 
TryCodingTryCoding

My problem has been Solved. There were some lines i was missing.

i am putting correct  Java Code Below:

 

 

public static void main(String[] args) throws Exception { 
            login();
 
           WebServiceAccountPlanServiceLocator locator = new WebServiceAccountPlanServiceLocator();
           java.net.URL url = new java.net.URL(locator.getWebServiceAccountPlanAddress());
           WebServiceAccountPlanBindingStub wbind = new WebServiceAccountPlanBindingStub(url, locator);
          String sforceURI = locator.getWebServiceAccountPlanAddress();
          wbind.setHeader(sforceURI, "SessionHeader", sh);
 
          Plan vPlan = new Plan();
          vPlan.setName( "Namita");
 
          vPlan.setPlanningPeriod(null);
         vPlan.setPlanNumber(1234);
 
          Plan endresult = wbind.createAccountPlan(vPlan);
         System.out.println("----------------"+endresult.getPlanId());
 }

 

 

All Answers

TryCodingTryCoding

My problem has been Solved. There were some lines i was missing.

i am putting correct  Java Code Below:

 

 

public static void main(String[] args) throws Exception { 
            login();
 
           WebServiceAccountPlanServiceLocator locator = new WebServiceAccountPlanServiceLocator();
           java.net.URL url = new java.net.URL(locator.getWebServiceAccountPlanAddress());
           WebServiceAccountPlanBindingStub wbind = new WebServiceAccountPlanBindingStub(url, locator);
          String sforceURI = locator.getWebServiceAccountPlanAddress();
          wbind.setHeader(sforceURI, "SessionHeader", sh);
 
          Plan vPlan = new Plan();
          vPlan.setName( "Namita");
 
          vPlan.setPlanningPeriod(null);
         vPlan.setPlanNumber(1234);
 
          Plan endresult = wbind.createAccountPlan(vPlan);
         System.out.println("----------------"+endresult.getPlanId());
 }

 

 

This was selected as the best answer
Sunny_SlpSunny_Slp

@TryCoding

 

I'm trying to do the same thing. I'm new to SFDC and Java. I'm trying to understand the code you have here, but got lost

 

          login();

 
           WebServiceAccountPlanServiceLocator locator = new WebServiceAccountPlanServiceLocator();
           java.net.URL url = new java.net.URL(locator.getWebServiceAccountPlanAddress());
           WebServiceAccountPlanBindingStub wbind = new WebServiceAccountPlanBindingStub(url, locator);
          String sforceURI = locator.getWebServiceAccountPlanAddress();
          wbind.setHeader(sforceURI, "SessionHeader", sh);



What does the above code do? I understood other parts of your code but failed to understand what's going on here.  Would you please explain this part of your code for me? It would be of great help.

 

Thank you,

Sunny_Slp