2

I am facing a weird issue and was wondering if anyone had faced this error. Here are the details:

I have written a Custom Rest Service in my Salesforce Sandbox org named CustomAccountService which has a Post Method in it. The method takes a list of Accounts. All I am doing is updating a custom field on Account object based on an InternalKey. This is how my Service looks like:

@RestResource(urlMapping='/Account/')
global with sharing class CustomAccountService {

//Private class used as request dto
global class MerchantStatusUpdateMessage {
    public String BeyondClientId { get; set; }
    public String MerchantStatus { get; set; }
}

@HttpPost
global static Map <String,String> doPost(List<MerchantStatusUpdateMessage> merchantStatusUpdateMessage) {
    //response returned by api endpoint
    Map <String,String> response = new Map <String,String>();

    try {
        //Variable to collect all the ClientIds
        Set<String> beyondClientIds = new Set<String>();

        //Variable to hold a key value map
        Map<String, String> clientId_StatusMap = new Map<String, String>();

        for (MerchantStatusUpdateMessage request : merchantStatusUpdateMessage) {
            //Collect all ClientIds 
            beyondClientIds.add(request.BeyondClientId);

            //Create a key value map based for ClientId -> MerchantStatus
            clientId_StatusMap.put(request.BeyondClientId, request.MerchantStatus);
        }

        //Get all the accounts based on ClientIds
        List<Account> accounts = [SELECT Id, Name, Beyond_Unique_ID__c, Payment_Status__c FROM Account WHERE Beyond_Unique_ID__c  = :beyondClientIds];

        //Update status for each client
        for (Account account : accounts) {
            if(clientId_StatusMap.containsKey(account.Beyond_Unique_ID__c)) {
                account.Payment_Status__c = clientId_StatusMap.get(account.Beyond_Unique_ID__c);
            }
        }

        //Update changes in the database
        update accounts;

        //Mark isSuccess as True
        response.put('isSuccess','True');

        return response;
    }
    catch (Exception e) {
        System.Debug ('------Exception-----'+e.getMessage ());
        response.put('isSuccess','False');

        //Mark isSuccess as false
        return response;
    } 
    }
}

Now, I am consuming this API from one of our Azure function (c#). There are two steps, first to make a login call and get the Token. Next call is the actual post request using token. When I run it locally, its working fine and updating the status in Salesforce. Here is the sample code:

HttpClient httpClient = new HttpClient();

            var formContent = new FormUrlEncodedContent(new[]
            {
             new KeyValuePair<string, string>("client_id", _salesforceClientId),
             new KeyValuePair<string, string>("client_secret", _salesforceClientSecret),
             new KeyValuePair<string, string>("username", _salesforceUserName),
             new KeyValuePair<string, string>("password", _salesforcePassword),
             new KeyValuePair<string, string>("grant_type", _salesforceGrantType)
         });

            log.Info(formContent.ReadAsStringAsync().Result);
            //Call to get access token
            var loginResponse = httpClient.PostAsync(_salesforceLoginUrl, formContent).Result;

            if (loginResponse != null)
            {
                log.Info(loginResponse.Content.ReadAsStringAsync().Result);

                var token = JsonConvert.DeserializeObject<SalesforceLoginResponse>(loginResponse.Content.ReadAsStringAsync().Result).access_token;
                httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {token}");

                var sfAccountUpdateUrl = string.Concat(_salesforceEntityUpdateUrl, "/services/apexrest/Account/");

                //Call to update Entity in Salesforce
                var entityUpdateResponse = httpClient.PostAsync(sfAccountUpdateUrl,
                    new StringContent(JsonConvert.SerializeObject(new { merchantStatusUpdateMessage = merchantStatusUpdateMessage }), Encoding.UTF8, "application/json")).Result;

                if(entityUpdateResponse.StatusCode != HttpStatusCode.OK)
                    throw new Exception($"Error occured while updating entity status in Salesforce");
            }

But now when I build the same code to one of our Dev environment and try to make the call from Dev server, I get the following error message:

An internal server error has occurred An internal server error has occurred An error has occurred while processing your request. The salesforce.com support team has been notified of the problem. If you believe you have additional information that may be of help in reproducing or correcting the error, please contact Salesforce Support. Please indicate the URL of the page you were requesting, any error id shown on this page as well as any other related information. We apologize for the inconvenience. Thank you again for your patience and assistance. And thanks for using salesforce.com! An internal server error has occurred An error has occurred while processing your request. The salesforce.com support team has been notified of the problem. If you believe you have additional information that may be of help in reproducing or correcting the error, please contact Salesforce Support. Please indicate the URL of the page you were requesting, any error id shown on this page as well as any other related information. We apologize for the inconvenience. Thank you again for your patience and assistance. And thanks for using salesforce.com! Error ID: 1245306877-10173 (1478489697)

Also, even if make the same call from POSTMAN, it works fine and returns token back. Any idea what is going wrong here?

  • That is a GACK response, which indicates something is broken on the Salesforce side. Yet that it fails only in Dev suggests something environmental causing the problem. Are you using the same versions of .NET with the same TLS 1.2 support? Do other API integrations and/or tools work from the Dev server? – Daniel Ballinger Aug 10 '17 at 19:39
  • Is there anything in the Apex debug logs on the Salesforce side that indicates when/where the internal server error is occurring? – Daniel Ballinger Aug 10 '17 at 19:41
  • Daniel - Thanks for your response. I figured out the issue and it was indeed TLS issue. My .net code was running from Azure function which was making API call with TLS1.0. – Suresh Dalal Aug 12 '17 at 15:08
  • Suresh, let us know if there are any helpful links or other details on how to resolve this and I'll merge them into the answer to help future visitors. – Daniel Ballinger Aug 12 '17 at 21:13
0

As per the comments, this was likely a TLS 1.0 vs 1.2 issue. Salesforce is in the last stages of removing TLS 1.0 support - See Salesforce disabling TLS 1.0.

You typically need both OS and programming language support for TLS 1.2 to make it work.

With .NET if you you can be on 4.6 or higher you should be in a good position.

It sounds like you isolated the problem to the Azure function using TLS 1.0.

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.