You need to sign in to do that
Don't have an account?
How to create a stub for apex class generated by WSDL, call a method of that class on a button click
Hi,
I have created a custom button(Content Source is Onclick Javascript) on a standard page layout of my custom object "Sales Order".
When I click on this button, I need to capture the Id of the record along with values in that record like name,division,Sales Document Number,Sales Document Type etc....
And along with that, when I click on that button a stub of the apex class(Generated by WSDL) needs to be created and a method in that apex class needs to be called.
The apex class generated from the WSDL is shown below:
//Generated by wsdl2apex
public class biostadtClientMidasBodhtreeCom {
public class processSalesOrderResponse_element {
public String return_x;
private String[] return_x_type_info = new String[]{'return','http://www.w3.org/2001/XMLSchema','string','0','1','true'};
private String[] apex_schema_type_info = new String[]{'http://biostadt.client.midas.bodhtree.com','true','true'};
private String[] field_order_type_info = new String[]{'return_x'};
}
public class processSalesOrder_element {
public String salesDocType;
public String salesOrg;
public String distChannel;
public String division;
public String partnerRole;
public String partnerNumber;
public String purchaseOrdNumber;
public String itemNumber;
public String requiredQuantity;
public String material;
private String[] salesDocType_type_info = new String[]{'salesDocType','http://www.w3.org/2001/XMLSchema','string','0','1','true'};
private String[] salesOrg_type_info = new String[]{'salesOrg','http://www.w3.org/2001/XMLSchema','string','0','1','true'};
private String[] distChannel_type_info = new String[]{'distChannel','http://www.w3.org/2001/XMLSchema','string','0','1','true'};
private String[] division_type_info = new String[]{'division','http://www.w3.org/2001/XMLSchema','string','0','1','true'};
private String[] partnerRole_type_info = new String[]{'partnerRole','http://www.w3.org/2001/XMLSchema','string','0','1','true'};
private String[] partnerNumber_type_info = new String[]{'partnerNumber','http://www.w3.org/2001/XMLSchema','string','0','1','true'};
private String[] purchaseOrdNumber_type_info = new String[]{'purchaseOrdNumber','http://www.w3.org/2001/XMLSchema','string','0','1','true'};
private String[] itemNumber_type_info = new String[]{'itemNumber','http://www.w3.org/2001/XMLSchema','string','0','1','true'};
private String[] requiredQuantity_type_info = new String[]{'requiredQuantity','http://www.w3.org/2001/XMLSchema','string','0','1','true'};
private String[] material_type_info = new String[]{'material','http://www.w3.org/2001/XMLSchema','string','0','1','true'};
private String[] apex_schema_type_info = new String[]{'http://biostadt.client.midas.bodhtree.com','true','true'};
private String[] field_order_type_info = new String[]{'salesDocType','salesOrg','distChannel','division','partnerRole','partnerNumber','purchaseOrdNumber','itemNumber','requiredQuantity','material'};
}
public class SalesOrderClientHttpSoap11Endpoint {
public String endpoint_x = 'http://220.225.225.13:8080/axis2/services/SalesOrderClient.SalesOrderClientHttpSoap11Endpoint';
public Map<String,String> inputHttpHeaders_x;
public Map<String,String> outputHttpHeaders_x;
public String clientCertName_x;
public String clientCert_x;
public String clientCertPasswd_x;
public Integer timeout_x;
private String[] ns_map_type_info = new String[]{'http://biostadt.client.midas.bodhtree.com', 'biostadtClientMidasBodhtreeCom'};
public String processSalesOrder(String salesDocType,String salesOrg,String distChannel,String division,String partnerRole,String partnerNumber,String purchaseOrdNumber,String itemNumber,String requiredQuantity,String material) {//This method needs to be called on a button click
biostadtClientMidasBodhtreeCom.processSalesOrder_element request_x = new biostadtClientMidasBodhtreeCom.processSalesOrder_element();
biostadtClientMidasBodhtreeCom.processSalesOrderResponse_element response_x;
request_x.salesDocType = salesDocType;
request_x.salesOrg = salesOrg;
request_x.distChannel = distChannel;
request_x.division = division;
request_x.partnerRole = partnerRole;
request_x.partnerNumber = partnerNumber;
request_x.purchaseOrdNumber = purchaseOrdNumber;
request_x.itemNumber = itemNumber;
request_x.requiredQuantity = requiredQuantity;
request_x.material = material;
Map<String, biostadtClientMidasBodhtreeCom.processSalesOrderResponse_element> response_map_x = new Map<String, biostadtClientMidasBodhtreeCom.processSalesOrderResponse_element>();
response_map_x.put('response_x', response_x);
WebServiceCallout.invoke(
this,
request_x,
response_map_x,
new String[]{endpoint_x,
'urn:processSalesOrder',
'http://biostadt.client.midas.bodhtree.com',
'processSalesOrder',
'http://biostadt.client.midas.bodhtree.com',
'processSalesOrderResponse',
'biostadtClientMidasBodhtreeCom.processSalesOrderResponse_element'}
);
response_x = response_map_x.get('response_x');
return response_x.return_x;
}
}
}
Please find the screenshot below for better understanding:
file:///E:/Sales%20Order%20Sample%20Pic.JPG
When I click on "Submit" button Sales Order Name(Test1),Division(1),Id of that particular record should be captured ans a stub of the apex class needs to be created and a method in that apex class needs to be called.
Since I am new to calling a web service method in salesforce through a custom button, please suggest a javascript code for the button that fullfills this functionality.
Thanks & Regards,
Jagadeesh K.
Hi Jagadeesh,
please refer to this cookbook recipe for an example of how to call an Apex webservice from a custom button:
http://developer.force.com/cookbook/recipe/creating-a-button-with-apex