You need to sign in to do that
Don't have an account?
CodeTalker
Help with using APEX package in a Java application
Hello,
I am having trouble calling a package created in Apex. I downloaded the WSDL and also generated the classes using Axis. I used the example from the Salesforce Apex Language Reference pdf called "myPackage." (I modified it just a little.)
package myPackage {
webService Id makeContact(String lastName) {
Contact c = new Contact(lastName = 'Apex', firstName = 'Test');
insert c;
commit;
return c.id;
}
}
webService Id makeContact(String lastName) {
Contact c = new Contact(lastName = 'Apex', firstName = 'Test');
insert c;
commit;
return c.id;
}
}
I now have 4 classes:
MyPackageBindingStub
MyPackageService
MyPackageServiceLocator
MyPackagePortType
Can someone show me how to relate these classes together to be able to call the package method.
I've tried logging in to salesforce using a bean, and then putting its session id into a new session header for the stub. When I go to call the method I get an error "No operation for this request."
MyPackageService service = new MyPackageServiceLocator();
MyPackageBindingStub bind = new MyPackageBindingStub();
SessionHeader sh = new SessionHeader(bean.getSessionId());
bind.setHeader(service.getServiceName().getNamespaceURI(), "SessionHeader", sh);
bind._setProperty(MyPackageBindingStub.ENDPOINT_ADDRESS_PROPERTY, bean.getLoginResult().getServerUrl());
String id = bind.makeContact("APEX test");
Does anyone have an example for calling a package? Thank you!
SessionHeader sh = new SessionHeader(bean.getSessionId());
URL packageURL = new URL("https://na4-api.salesforce.com/services/Soap/package/myPackage");
MyPackageService service = new MyPackageServiceLocator();
MyPackageBindingStub stub = new MyPackageBindingStub(packageURL, service);
String s = service.getServiceName().getNamespaceURI();
stub.setHeader(s, "SessionHeader", sh);
stub.makeContact("ApexText");
Thank you for the tip, you must have known that I didn't want to hardcode that url.
I think I found a way to get it without having to combine them.
The getMyPackageAddress() method returns it.
MyPackageService service = new MyPackageServiceLocator();
String packAddr = service.getmyPackageAddress();
URL packageURL = new URL(packAddr);
MyPackageBindingStub stub = new MyPackageBindingStub(packageURL, service);
...