• Andre Baxter 7
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 4
    Replies


I'm trying to do a POST call to SBA from Salesforce that involves uploading a file. The call asks for 4 parameters in the form of JSON. As I have tested, 3 of the 4 JSON fields are passing validation on the other end. However, when I use the VersionData(Blob) field on the ContentVersion, the error in the title is returned. I have also tried using PathOnClient(String) as the value, but receive the same error.

Perhaps there is another field on the ContentVersion object that I should be passing in to represent the file? Or maybe there is another object I should be using to retrieve the file and utilize it in Apex? My sandbox is fairly new so the Attachment object unfortunately doesn't retrieve any files via SOQL. My code is below:

public static void makeCallOutForUpload(){
    
    //query for File
ContentVersion file = [SELECT Title, PathOnClient, VersionData FROM ContentVersion WHERE ContentDocumentId = '0693J0000007rltQAA' AND IsLatest = true];
    
    
    //sample request for upload doc callout
    String jsonstring = '{'
                       +'"name": "delete these todos.csv",'
                       +'"document": "'+file.VersionData+'",'
                       +'"document_type": "1",'
                       +'"etran_loan": "7ab138f3-7507-47f9-a330-1a2c0b4e4f73"'
                       + '}';
  
    HttpResponse response;
    ETranDetails__c etranDetails = ETranDetails__c.getOrgDefaults();
    
    //call out logic here
    Http http = new Http();
    HttpRequest request = new HttpRequest();
    request.setHeader('Authorization', etranDetails.API_Key__c);
    request.setHeader('Vendor-Key', etranDetails.Vendor_Key__c);
    request.setHeader('Content-Type', 'application/json');
    request.setEndpoint(etranDetails.Forgiveness_Endpoint_For_Upload_Docs__c);
    request.setMethod('POST');
    request.setTimeout(120000);
    request.setBody(jsonstring);
    response = http.send(request);
    
    system.debug('what came back?'+response.getStatusCode()+' '+response.getBody());
    
}

I have tried a few different methods to query for the Attachments in my org, but zero rows are always returned.
I ran this query in the query editor in dev console, but zero rows were returned:

select id, name from Attachment

The same result occurred when I ran below code in the execute anonymous window:

for (Attachment [] atts : [select name from attachment]) {
// do something with atts system.debug
( atts.size() );
}

I'm expecting at least two rows to be returned on a Opportunity record that I'm using for testing. Is there something on the configuration end that I need to set up so that I'll be able to retrieve the attachments via soql? I'm guessing that there's something simple that needs to be tweaked that I overlooked.
Hello community, I'm having an issue getting a positive response(200 code) when making a callout to SBA API.  I use the same authentication headers and endpoint in Postman and the response is successful.  However, currently that's not the case for me in Salesforce.  Below is my callout method code.  The JSON is in a separate method.  I have tried to do the callout without the body and headers and still receive the same response code.  Anyone ever run into this issue and resolved it?  Thanks.

public static string makeCallout(string jsonstring) {
        
        //call out logic here
        ETranDetails__c etranDetails =       ETranDetails__c.getOrgDefaults();
        HttpResponse response;
        
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setHeader('Authorization', etranDetails.API_Key__c);
        request.setHeader('Vendor-Key', etranDetails.Vendor_Key__c);
        request.setHeader('Content-Type', 'application/json');
        request.setEndpoint(etranDetails.Forgiveness_Endpoint__c);
        request.setMethod('POST');
        request.setTimeout(120000);
        request.setBody(jsonstring);
        response = http.send(request);
        
        return null;
    }

I have tried a few different methods to query for the Attachments in my org, but zero rows are always returned.
I ran this query in the query editor in dev console, but zero rows were returned:

select id, name from Attachment

The same result occurred when I ran below code in the execute anonymous window:

for (Attachment [] atts : [select name from attachment]) {
// do something with atts system.debug
( atts.size() );
}

I'm expecting at least two rows to be returned on a Opportunity record that I'm using for testing. Is there something on the configuration end that I need to set up so that I'll be able to retrieve the attachments via soql? I'm guessing that there's something simple that needs to be tweaked that I overlooked.
Hello community, I'm having an issue getting a positive response(200 code) when making a callout to SBA API.  I use the same authentication headers and endpoint in Postman and the response is successful.  However, currently that's not the case for me in Salesforce.  Below is my callout method code.  The JSON is in a separate method.  I have tried to do the callout without the body and headers and still receive the same response code.  Anyone ever run into this issue and resolved it?  Thanks.

public static string makeCallout(string jsonstring) {
        
        //call out logic here
        ETranDetails__c etranDetails =       ETranDetails__c.getOrgDefaults();
        HttpResponse response;
        
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setHeader('Authorization', etranDetails.API_Key__c);
        request.setHeader('Vendor-Key', etranDetails.Vendor_Key__c);
        request.setHeader('Content-Type', 'application/json');
        request.setEndpoint(etranDetails.Forgiveness_Endpoint__c);
        request.setMethod('POST');
        request.setTimeout(120000);
        request.setBody(jsonstring);
        response = http.send(request);
        
        return null;
    }

I need a SOQL query that will retrieve a result set similar to what you get in the Notes And Attachments section of an Account. This list includes not only all Notes And Attachments with the Account itself as the parent, but also for all Cases, Opportunities and/or Contacts related to the Account. With the NoteAndAttachment entity not queryable directly, and with no UNION clause available, I don't even know where to begin writing a single all-includive query.