1

I am making a callout to SAP webservice in order to create a customer in SAP. The customer data is nothing but our Account. Now i am getting an exception "IO Exception: Read timed out". i knew that increasing the timeout will solve the issue. But statements inside and after the catch block got executed even after an exception occurred. Is that normal? I need the statements inside the catch block should executed when an exception occurred and the code execution should get stopped. Why this is happening? Is this normal behavior of try catch? Any ideas please...

    public static void CreateCustomer(String accid) {
    //Variable declaration
    CustomerCreateRequestDTO cust = new CustomerCreateRequestDTO();
    sapComDocumentSapSoapFunctionsMcS.Z_GSSMWFM_HNDL_EVNTRQST00 sap1 = new sapComDocumentSapSoapFunctionsMcS.Z_GSSMWFM_HNDL_EVNTRQST00();       
    Map<List<String>,List<List<String>>> mapSAP = new Map<List<String>,List<List<String>>> {};
    List<String> strReqData = new List<String>{};

    sap1.timeout_x = 900;
    sapComDocumentSapSoapFunctionsMcS.ZgssmbstDatarcrd01 req = new sapComDocumentSapSoapFunctionsMcS.ZgssmbstDatarcrd01();

    Account acc = [select Account_Group__c, Title__c, First_Name__c, Last_Name__c, House_No__c, Search_Term__c, BillingStreet, BillingCountry, BillingPostalCode, SAP_REGIO__c, BillingCity from Account where Id =: accid];        

    cust.AccountGroup = acc.Account_Group__c;
    cust.Title = acc.Title__c;
    cust.FirstName = acc.First_Name__c;
    cust.LastName = acc.Last_Name__c;
    cust.SearchTerm = acc.Search_Term__c;
    cust.StreetHNo = acc.BillingStreet;
    cust.PostCode = acc.BillingPostalCode;
    cust.Region = acc.SAP_REGIO__c;
    cust.City = acc.BillingCity;
    cust.Country = acc.BillingCountry;

    //CUSTOMER CREATION
    /*
    //CUSTOMER CREATION
    DEVICE-ID:160000000000000:DEVICE-TYPE:SFDC-CLIENT:APPLICATION-ID:SFDC-SALES
    NOTATION:ZML:VERSION:0:DELIMITER:[.]
    EVENT[.]SFDC-CUST-CREATE[.]VERSION[.]0[.]RESPONSE-TYPE[.]FULL-SETS
    DATA-TYPE[.]ZGSEVAST_SDCRTCUST[.]ANRED[.]LAND1[.]NAME1[.]NAME2[.]ORT01[.]PSTLZ[.]REGIO[.]SORTL[.]STRAS[.]MCOD1[.]KTOKD
    ZGSEVAST_SDCRTCUST[.]Company[.]US[.]EMAX[.]ANAHEIM[.]ANA9[.]0023[.]CA[.]AB[.]AB[.]AB[.]ZARG

    Account Group   KTOKD
    First Name  NAME1
    Last Name   NAME2
    Title       ANRED   
    Search Term SORTL
    Street/H No.    STRAS

    Postal Code:    PSTLZ
    City:   ORT01
    Region: REGIO
    Country LAND1

    */

    String EventType = 'EVENT[.]SFDC-CUST-CREATE[.]VERSION[.]0[.]RESPONSE-TYPE[.]FULL-SETS';
    String InputFields = 'DATA-TYPE[.]ZGSEVAST_SDCRTCUST[.]ANRED[.]LAND1[.]NAME1[.]NAME2[.]ORT01[.]PSTLZ[.]REGIO[.]SORTL[.]STRAS[.]KTOKD';
    String InputData = 'ZGSEVAST_SDCRTCUST[.]'+cust.Title+'[.]'+cust.Country+'[.]'+cust.FirstName+'[.]'+cust.LastName+'[.]'+cust.City+'[.]'+cust.PostCode+'[.]'+cust.Region+'[.]'+cust.SearchTerm+'[.]'+cust.StreetHNo+'[.]'+cust.AccountGroup;
    strReqData.add(EventType);
    strReqData.add(InputFields);
    strReqData.add(InputData);
    req.item = Utility.LoadRequestData(strReqData);
    sapComDocumentSapSoapFunctionsMcS.ZGssmwfmHndlEvntrqst00Response_element ret;
    try {
        ret =  sap1.ZGssmwfmHndlEvntrqst00('',req);
    } catch(Exception ex) {
        System.debug('>>>>>>>>>>>>>>>>>>>>'+ex.getmessage());
        ProcessorControl.inFutureContext = true;
        Account ac = [select id, SAP_KUNNR__c from account where id =: AccId];
        ac.SAP_KUNNR__c = 'xxxxxxxxxx';//r.MessageV2;
        update ac;
    }
        System.debug('$$$$$$$$$$$$$$$$$$$$$$$$$'+ret);
        sapComDocumentSapSoapFunctionsMcS.Bapiret2 r = ret.DpostMssg.item[0];
    ProcessorControl.inFutureContext = true;
    Account ac = [select id, SAP_KUNNR__c from account where id =: AccId];
    ac.SAP_KUNNR__c = r.MessageV2;
    update ac;


} 

Thanks, Baskaran

  • It would help to put a brief code example illustrating exactly where the code is executing that you are unsure about. It does not even have to be the "real" code, actually, it is better to write up an example that is very brief without extra stuff in it. – user6861 Mar 24 '14 at 17:03
4

This is indeed normal behaviour.

If you need code execution to stop in the catch block, put a return; statement at the end of that block, or, if that is applicable, don't catch the exception at all.

  • Thanks @guy. but it is a void method. Moreover i need to update a boolean field if the exception occurs. so i wrote little bit of code to perform a DML inside the catch block. – Bforce Mar 24 '14 at 16:18
  • That's no problem. You can still return; after doing those actions. They will be executed and after that the method will be stopped (returning nothing, obviously, because it is a void) – Guy Clairbois Mar 24 '14 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.