• WellSky Integration User
  • NEWBIE
  • 10 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 3
    Replies
I am constantly getting an email with the error below.  I have tried changing the setTimeout value and that does not seem to work.  I am not sure if it is the code that is causing it or maybe the endpoint being to slow.

The idea is to enter an Account record that is sent to the endpoint.  The endpoint creates a record, then sends back To SalesForce an update with the associated id number from the record that was created on the endpoint's side.  It is looking as if most (not all) transactions cause the error/warning.  There have even been times where a duplicate record was attempted to be added on the endpoints side - which I am thinking is due to the time of the response being so long the transaction is sent again....but that is just a guess at this point.

Apex script unhandled exception by user/organization: 0055Y00000HMWkA/00D5Y000002W93U

Failed to invoke future method 'public static void putDestination(String)' on class 'AccountDestinationCallout' for job id '7075Y0000BUIrcf'

caused by: System.CalloutException: Read timed out

Class.AccountDestinationCallout.putDestination: line 45, column 1
Line 45 is :
HTTPResponse objRes = objHttp.send(objReq);


The code for AccountDestinationCallout:
public class AccountDestinationCallout {
    public static String generatedToken {set; get;}
    static String errorMessage {set; get;}
    static String TimelineResponse {set; get;}
    
    @future(callout = true)
    
// called by trigger AccountUpdate
    
    public static void putDestination(string buildMessage) {    
		HttpRequest req = new HttpRequest();
		req.setMethod('POST');
	    req.setHeader('Authorization', 'Basic ' + EncodingUtil.base64Encode(Blob.valueOf('Sales' + ':' + 'someid')));
    	req.setHeader('content-type', 'application/x-www-form-urlencoded');
        req.setEndpoint('https://homedomainname.com/api/prod_gateway/path');
		req.setBody('grant_type=client_credentials');

	    Http http = new Http();
		req.setTimeout(120000);
   	   	HTTPResponse res = http.send(req);
     	JSONParser objParse = JSON.createParser(res.getBody());
        while (objParse.nextToken() != null) 
        {
           if (objParse.getCurrentToken() == JSONToken.FIELD_NAME && objParse.getText() == 'access_token')
           {                               
              objParse.nextToken();
              generatedToken = objParse.getText();
           }
        }
        	if(generatedToken == null ) 
            {
            	TimelineResponse = 'Error while generating token, so unable to get messages. Check your debug log.';
            	return;
        	}

	        HttpRequest objReq = new HttpRequest();
 
        objReq.setEndpoint('https://homedomainname.com/api/prod_gateway/SalesForce/postSF');
        	objReq.setMethod('POST');
            objReq.setHeader('Authorization', 'Bearer ' + generatedToken);
            objReq.setBody(buildMessage);
	        Http objHttp = new Http();
            objReq.setTimeout(20000);
    	    HTTPResponse objRes = objHttp.send(objReq);
        	TimelineResponse = objRes.getBody();
    	    if(String.isBlank(TimelineResponse))
            {
        	   TimelineResponse = objRes.toString();
            }
    }
}


 
Which is the correct syntax if I want to check for a specific record id and if the type field is not null?
if (a.RecordTypeId == '0125Y000001GTK4QAO' && a.Account_Type__c != 'null')
 
if (a.RecordTypeId == '0125Y000001GTK4QAO' && a.Account_Type__c != null)

 
Ideally we are looking to complete the following:
         1) User changes field in Contact object
         2) SalesForce authenticates to our site with oAuth2
         3) Field(s) from Contact object are updated in our database.
Currently this works starting from Postman:  I can authenticate to our endpoint, receive and store the token and update the data to our endpoint.

I have the setup in Sandbox.

I have an APEX trigger that kicks off on an update to the Contact object which does a callout to and APEX class.

I have an Auth Provider setup.  The provider type I selected is Open ID Connect - since I did not know what else to pick.  The URL Suffix is 
My_Auth.  The consumer key and consumer secret are filled in the same as on Postman.  The Authorize endpoint and Token endpoint are https://oursite.com/token.

I have a Named Credential setup with the name My_Endpoint.  The url is the full token url(https://oursite.com/token).  It is also setup with an Identity Type of Named Principal, Auth Protocol of oAuth 2.0 and an Auth Provider of My_Auth.

When I change a field in the Contact object, everything kicks off - but I get a Read Time Out error.  

Can anyone help me with debugging further to see why I cannot get the token returned and/or why it does not seem to hit the token endpoint?
 
Hope this is the right area to post this.  I am logged into SalesForce Lightning and can move around normally with our data. When I open up a new tab and access Workbench, the objects I run a query against are not ours.  For example, our Account object has 26 records in it currently.  But in Workbench, a count against the Account object indicates there are over 200,000 records.  Also the custom fields are not listed. I havent logged in a little over a month but up until my last login, everything was fine.  Any help and/or ideas?
I did post this in Trailhead/Trailblazer as well - not sure which was the appropriate group.

We are using SF with our software by updating objects on SF from us.  Currently we have the inbound to SF working, our app authenticates with SF then updates/adds to the appropriate object.  We now are trying to have SF authenticate to our server using oAuth2 and update the record(s) on our system.  We have the endpoints ready and this has been internally tested.  We created an Outbound Message for the update.  Our server requires oAuth2 authentication, so our issue is how to get SF to authenticate to us?  We have created an app that is shown in App Manager with oAuth settings enabled and the callback url pointing to our authentication server along with oAuth scopes, yet we constantly fail to get SF to authenticate to our server.  To me this setup looks like in handles inbound to SF rather than outbound.  Is that correct?  What should be setup to have SF authenticate outbound for outbound messages?
Which is the correct syntax if I want to check for a specific record id and if the type field is not null?
if (a.RecordTypeId == '0125Y000001GTK4QAO' && a.Account_Type__c != 'null')
 
if (a.RecordTypeId == '0125Y000001GTK4QAO' && a.Account_Type__c != null)

 
Hope this is the right area to post this.  I am logged into SalesForce Lightning and can move around normally with our data. When I open up a new tab and access Workbench, the objects I run a query against are not ours.  For example, our Account object has 26 records in it currently.  But in Workbench, a count against the Account object indicates there are over 200,000 records.  Also the custom fields are not listed. I havent logged in a little over a month but up until my last login, everything was fine.  Any help and/or ideas?