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
devsalesforce27devsalesforce27 

Urgent: Webservice callout

Hey guys,

 

I have developed a basic VF page which is basically a general form entry page for end user. We will be placing this page on force.com Site. we want whenevr users click the submit button, two tasks should be performed. 

1.) Record should be saved in Lead.

2.) all the information enetered in the fields should be sent to SAP. 

 

In order to send information to SAP, I have generated apex class from WSDL (provided by SAP). Now next step is to callout this webservice class in the submit button. I have idea how to do this . I would really aprreciate if somone can guide me. below is the generated apex class.

 

//Generated by wsdl2apex

public class sapComDocumentSapRfcFunctions {
    public class ZARU_S_ATHENA_EVAL_ORDER {
        public String FIRST_NAME;
        public String LAST_NAME;
        public String COMPANY;
        public String EMAIL_ADDRESS;
        public String TELEPHONE;
        public String CITY;
        public String COUNTRY;
        public String POSTAL_CODE;
        public String CAMPAIGN;
        public String USER_TYPE;
        public String EVALUATION_HORIZON;
        public String POTENTIAL_USER_COUNT;
        public String EVALUATION_TERMS;
        private String[] FIRST_NAME_type_info = new String[]{'FIRST_NAME','urn:sap-com:document:sap:rfc:functions','char60','1','1','false'};
        private String[] LAST_NAME_type_info = new String[]{'LAST_NAME','urn:sap-com:document:sap:rfc:functions','char60','1','1','false'};
        private String[] COMPANY_type_info = new String[]{'COMPANY','urn:sap-com:document:sap:rfc:functions','char50','1','1','false'};
        private String[] EMAIL_ADDRESS_type_info = new String[]{'EMAIL_ADDRESS','urn:sap-com:document:sap:rfc:functions','char241','1','1','false'};
        private String[] TELEPHONE_type_info = new String[]{'TELEPHONE','urn:sap-com:document:sap:rfc:functions','char30','1','1','false'};
        private String[] CITY_type_info = new String[]{'CITY','urn:sap-com:document:sap:rfc:functions','char35','1','1','false'};
        private String[] COUNTRY_type_info = new String[]{'COUNTRY','urn:sap-com:document:sap:rfc:functions','char3','1','1','false'};
        private String[] POSTAL_CODE_type_info = new String[]{'POSTAL_CODE','urn:sap-com:document:sap:rfc:functions','char10','1','1','false'};
        private String[] CAMPAIGN_type_info = new String[]{'CAMPAIGN','urn:sap-com:document:sap:rfc:functions','char80','1','1','false'};
        private String[] USER_TYPE_type_info = new String[]{'USER_TYPE','urn:sap-com:document:sap:rfc:functions','char2','1','1','false'};
        private String[] EVALUATION_HORIZON_type_info = new String[]{'EVALUATION_HORIZON','urn:sap-com:document:sap:rfc:functions','char2','1','1','false'};
        private String[] POTENTIAL_USER_COUNT_type_info = new String[]{'POTENTIAL_USER_COUNT','urn:sap-com:document:sap:rfc:functions','numeric5','1','1','false'};
        private String[] EVALUATION_TERMS_type_info = new String[]{'EVALUATION_TERMS','urn:sap-com:document:sap:rfc:functions','char2','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'urn:sap-com:document:sap:rfc:functions','false','true'};
        private String[] field_order_type_info = new String[]{'FIRST_NAME','LAST_NAME','COMPANY','EMAIL_ADDRESS','TELEPHONE','CITY','COUNTRY','POSTAL_CODE','CAMPAIGN','USER_TYPE','EVALUATION_HORIZON','POTENTIAL_USER_COUNT','EVALUATION_TERMS'};
    }
    public class Z_ATHENA_EVAL_ORDERSoapBinding {
        public String endpoint_x = 'http://DEC.arubanetworks.com:8000/sap/bc/srt/rfc/sap/Z_ATHENA_EVAL_ORDER?sap-client=500';
        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[]{'urn:sap-com:document:sap:rfc:functions', 'sapComDocumentSapRfcFunctions'};
        public sapComDocumentSapRfcFunctions.ZARU_BAPI_CREATE_EVAL_ORDERResponse_element ZARU_BAPI_CREATE_EVAL_ORDER(sapComDocumentSapRfcFunctions.BAPIRET2_TT ET_RETURN,String I_DEFAULT_VALUES_KEY,sapComDocumentSapRfcFunctions.ZARU_S_ATHENA_EVAL_ORDER I_EVAL_ORDER,String I_TESTRUN) {
            sapComDocumentSapRfcFunctions.ZARU_BAPI_CREATE_EVAL_ORDER_element request_x = new sapComDocumentSapRfcFunctions.ZARU_BAPI_CREATE_EVAL_ORDER_element();
            sapComDocumentSapRfcFunctions.ZARU_BAPI_CREATE_EVAL_ORDERResponse_element response_x;
            request_x.ET_RETURN = ET_RETURN;
            request_x.I_DEFAULT_VALUES_KEY = I_DEFAULT_VALUES_KEY;
            request_x.I_EVAL_ORDER = I_EVAL_ORDER;
            request_x.I_TESTRUN = I_TESTRUN;
            Map<String, sapComDocumentSapRfcFunctions.ZARU_BAPI_CREATE_EVAL_ORDERResponse_element> response_map_x = new Map<String, sapComDocumentSapRfcFunctions.ZARU_BAPI_CREATE_EVAL_ORDERResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'http://DEC.arubanetworks.com:8000/sap/bc/srt/rfc/sap/Z_ATHENA_EVAL_ORDER?sap-client=500',
              'urn:sap-com:document:sap:rfc:functions',
              'ZARU_BAPI_CREATE_EVAL_ORDER',
              'urn:sap-com:document:sap:rfc:functions',
              'ZARU_BAPI_CREATE_EVAL_ORDERResponse',
              'sapComDocumentSapRfcFunctions.ZARU_BAPI_CREATE_EVAL_ORDERResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x;
        }
    }
    public class ZARU_BAPI_CREATE_EVAL_ORDER_element {
        public sapComDocumentSapRfcFunctions.BAPIRET2_TT ET_RETURN;
        public String I_DEFAULT_VALUES_KEY;
        public sapComDocumentSapRfcFunctions.ZARU_S_ATHENA_EVAL_ORDER I_EVAL_ORDER;
        public String I_TESTRUN;
        private String[] ET_RETURN_type_info = new String[]{'ET_RETURN','urn:sap-com:document:sap:rfc:functions','BAPIRET2_TT','1','1','false'};
        private String[] I_DEFAULT_VALUES_KEY_type_info = new String[]{'I_DEFAULT_VALUES_KEY','urn:sap-com:document:sap:rfc:functions','char4','0','1','false'};
        private String[] I_EVAL_ORDER_type_info = new String[]{'I_EVAL_ORDER','urn:sap-com:document:sap:rfc:functions','ZARU_S_ATHENA_EVAL_ORDER','1','1','false'};
        private String[] I_TESTRUN_type_info = new String[]{'I_TESTRUN','urn:sap-com:document:sap:rfc:functions','char1','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'urn:sap-com:document:sap:rfc:functions','false','true'};
        private String[] field_order_type_info = new String[]{'ET_RETURN','I_DEFAULT_VALUES_KEY','I_EVAL_ORDER','I_TESTRUN'};
    }

Tim BarsottiTim Barsotti

I would put a trigger on the lead object. Have the trigger call the webservice;  you will need to use an asynchronous method. Asynchronous methods are annotated using @future. You must use the parameter (CallOut = true). 

 

Have your trigger call an Apex asynchronous method, have the asynchronous method call the webservice. 

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_future.htm

 

Here is a tutorial on webservice and callouts in SFDC: 

http://wiki.developerforce.com/page/Apex_Web_Services_and_Callouts