• Adheena jacob 1
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 7
    Replies

Hi, I'm trying to upload file to Google cloud. I need to assign the attachment to a key "document" and then upload using REST API
This is a screenshot from postman. I need to upload file in this format using REST API.
In java you achieve this by doing something like this
.body("------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"document\"; filename=\"Test.pdf\"\r\nContent-Type: application/pdf\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; )
How do we do this in apex. 
Can anyone help? Thanks in advance
Adheena

Hi,
I want to upload salesforce attachments to box.com account using Rest API. For authentication I am using Auth Provider. I have created a named credential "TestBox" which uses this Auth Provider and url "https://upload.box.com/api/2.0/".  I am able to uplaod .txt files using this. But while uploading .docx file it shows "Script-thrown exception".

I am able to upload .docx file by hardcoding Endpoint. But here I want to use named credentials. Can anyone help.

This is my code::


attachment file1= [SELECT Id, Name, Body FROM attachment where name like '%COS%' LIMIT 1];
system.debug('file1'+file1);
String x= uploadFileToBox('0', file1 ); 
system.debug('x'+x);
public static String uploadFileToBox(String strFolderId,attachment file)
{
    String fileId ;
    String boundary = '----------------------------741e90d31eff';
    String header = '--'+boundary+'\nContent-Disposition: form-data; name="file"; filename="'+file.name+'";\nContent-Type: multipart/form-data;'+'\nnon-svg='+True;
    String footer = '--'+boundary+'--';             
    String headerEncoded = EncodingUtil.base64Encode(Blob.valueOf(header+'\r\n\r\n'));
    //HttpResponse res;
    String strFileId;
    
    while(headerEncoded.endsWith('='))
    {
        header+=' ';
        headerEncoded = EncodingUtil.base64Encode(Blob.valueOf(header+'\r\n\r\n'));
    }
    
    String bodyEncoded = EncodingUtil.base64Encode(file.body);
    
    Blob bodyBlob = null;
    String last4Bytes = bodyEncoded.substring(bodyEncoded.length()-4,bodyEncoded.length());
    
    // GW: replacement section to get rid of padding without corrupting data
    if(last4Bytes.endsWith('==')) 
    {
        last4Bytes = last4Bytes.substring(0,2) + '0K';
        bodyEncoded = bodyEncoded.substring(0,bodyEncoded.length()-4) + last4Bytes;
        String footerEncoded = EncodingUtil.base64Encode(Blob.valueOf(footer));
        bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+footerEncoded);
    }
    
    else if(last4Bytes.endsWith('=')) 
    {
        last4Bytes = last4Bytes.substring(0,3) + 'N';
        bodyEncoded = bodyEncoded.substring(0,bodyEncoded.length()-4) + last4Bytes;
        footer = '\n' + footer;
        String footerEncoded = EncodingUtil.base64Encode(Blob.valueOf(footer));
        bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+footerEncoded);              
    } 
    
    else 
    {
        footer = '\r\n' + footer;
        String footerEncoded = EncodingUtil.base64Encode(Blob.valueOf(footer));
        bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+footerEncoded);  
    }
    
    String sUrl = 'callout:TestBox/files/content?parent_id='+strFolderId;
    HttpRequest req = new HttpRequest();
    
    //req.setHeader('Content-Type','multipart/form-data;non_svg='+True+';boundary='+boundary);
    req.setHeader('Content-Type','application/msword');
    
    req.setMethod('POST');
    req.setEndpoint(sUrl);
    req.setBodyAsBlob(bodyBlob);
    req.setTimeout(60000);
      
    req.setHeader('Content-Length',String.valueof(req.getBodyAsBlob().size()));
    
    Http http = new Http();
    
    system.debug('*****size****'+req.getBodyAsBlob().size());
    
    if(Test.isRunningTest()) {
        
        // Create a fake response
        //res = new HttpResponse();
        //res.setStatusCode(201);
    }
    else {
        
        try{
            HttpResponse res = http.send(req);   
            System.debug('res = ' + res);
            System.debug('res = ' + res.getBody());
            
            Jsonparser parser = Json.createParser(res.getBody());
            system.debug('parser '+parser );
            while (parser.nextToken() != null) 
            {
                parser.nextValue();
                String fieldName = parser.getCurrentName();
                String fieldValue = parser.getText();
                
                if(fieldName == 'id')
                {
                    fileId = fieldValue;
                    system.debug('fileId '+fileId );
                    return fileId;
                }
            }                      
            return fileId; 
        }catch (System.CalloutException e){
            System.debug('ERROR:' + e);
        }
    }
    return fileId;
}


Thanks,

Adheena
For Development of a POC for an integration project, we need to generate an Apex Class from a WSDL file of a third party system. We have the WSDL files from their API support. The link is provided below.
https://soapapi.findapprenticeship.service.gov.uk/Services/VacancyManagement/VacancyManagement51.svc?WSDL
But on generating Apex Class from these files,I am hitting some errors in the WSDL. Error is as follows: 
Failed to parse wsdl: Failed to parse WSDL: Unable to find schema for element; {http://services.imservices.org.uk/AVMS/Interfaces/5.1}PublicKey
 
I am trying to connect salesforce and Sap using Salesforce connect using the steps provided in the following link

https://developer.salesforce.com/blogs/developer-relations/2015/11/salesforce-1-lightning-connect-sap-step-step.html

I am facing some issues here.
I cant find the join us option given in the first screenshot. So I'm not sure if I have to create account in SAP Cloud Platform Cockpit, which I did.
I am unable to find an option to add tables in my Sap cloud account.
I'm not getting status as success now. Instead I get following
Screenshot of status
I have integrated salesforce and nab transact for payment purpose. I created fingerprint in my visualforce page using javascript. Now for security reasons I need to change fingerprint generation from visualforce page to my apex controller. I have the following code for the same.
 
String hashv= nabname+'|'+nabpass+ '|2|'+paymentId+'|'+ amtT + '|' + now_utc;
String targetString =hashv ;
Blob targetBlob = Blob.valueOf(targetString);
Blob hashSHA1 = Crypto.generateDigest('SHA1', targetBlob);
String hashBase64SHA1 = EncodingUtil.base64encode(hashSHA1);

"hashBase64SHA1" variable is assigned to the fringerprint field in my vf page. This gives me invalid Fingerprint error. Can anyone help me.
Thanks in advance.
SOS fetch case history of customer as shown in the pic. Here in sos no email address is entered by customer. So how does the case details appear in console?
 User-added image

Hi, I'm trying to upload file to Google cloud. I need to assign the attachment to a key "document" and then upload using REST API
This is a screenshot from postman. I need to upload file in this format using REST API.
In java you achieve this by doing something like this
.body("------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"document\"; filename=\"Test.pdf\"\r\nContent-Type: application/pdf\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; )
How do we do this in apex. 
Can anyone help? Thanks in advance
Adheena

Hi,
I want to upload salesforce attachments to box.com account using Rest API. For authentication I am using Auth Provider. I have created a named credential "TestBox" which uses this Auth Provider and url "https://upload.box.com/api/2.0/".  I am able to uplaod .txt files using this. But while uploading .docx file it shows "Script-thrown exception".

I am able to upload .docx file by hardcoding Endpoint. But here I want to use named credentials. Can anyone help.

This is my code::


attachment file1= [SELECT Id, Name, Body FROM attachment where name like '%COS%' LIMIT 1];
system.debug('file1'+file1);
String x= uploadFileToBox('0', file1 ); 
system.debug('x'+x);
public static String uploadFileToBox(String strFolderId,attachment file)
{
    String fileId ;
    String boundary = '----------------------------741e90d31eff';
    String header = '--'+boundary+'\nContent-Disposition: form-data; name="file"; filename="'+file.name+'";\nContent-Type: multipart/form-data;'+'\nnon-svg='+True;
    String footer = '--'+boundary+'--';             
    String headerEncoded = EncodingUtil.base64Encode(Blob.valueOf(header+'\r\n\r\n'));
    //HttpResponse res;
    String strFileId;
    
    while(headerEncoded.endsWith('='))
    {
        header+=' ';
        headerEncoded = EncodingUtil.base64Encode(Blob.valueOf(header+'\r\n\r\n'));
    }
    
    String bodyEncoded = EncodingUtil.base64Encode(file.body);
    
    Blob bodyBlob = null;
    String last4Bytes = bodyEncoded.substring(bodyEncoded.length()-4,bodyEncoded.length());
    
    // GW: replacement section to get rid of padding without corrupting data
    if(last4Bytes.endsWith('==')) 
    {
        last4Bytes = last4Bytes.substring(0,2) + '0K';
        bodyEncoded = bodyEncoded.substring(0,bodyEncoded.length()-4) + last4Bytes;
        String footerEncoded = EncodingUtil.base64Encode(Blob.valueOf(footer));
        bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+footerEncoded);
    }
    
    else if(last4Bytes.endsWith('=')) 
    {
        last4Bytes = last4Bytes.substring(0,3) + 'N';
        bodyEncoded = bodyEncoded.substring(0,bodyEncoded.length()-4) + last4Bytes;
        footer = '\n' + footer;
        String footerEncoded = EncodingUtil.base64Encode(Blob.valueOf(footer));
        bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+footerEncoded);              
    } 
    
    else 
    {
        footer = '\r\n' + footer;
        String footerEncoded = EncodingUtil.base64Encode(Blob.valueOf(footer));
        bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+footerEncoded);  
    }
    
    String sUrl = 'callout:TestBox/files/content?parent_id='+strFolderId;
    HttpRequest req = new HttpRequest();
    
    //req.setHeader('Content-Type','multipart/form-data;non_svg='+True+';boundary='+boundary);
    req.setHeader('Content-Type','application/msword');
    
    req.setMethod('POST');
    req.setEndpoint(sUrl);
    req.setBodyAsBlob(bodyBlob);
    req.setTimeout(60000);
      
    req.setHeader('Content-Length',String.valueof(req.getBodyAsBlob().size()));
    
    Http http = new Http();
    
    system.debug('*****size****'+req.getBodyAsBlob().size());
    
    if(Test.isRunningTest()) {
        
        // Create a fake response
        //res = new HttpResponse();
        //res.setStatusCode(201);
    }
    else {
        
        try{
            HttpResponse res = http.send(req);   
            System.debug('res = ' + res);
            System.debug('res = ' + res.getBody());
            
            Jsonparser parser = Json.createParser(res.getBody());
            system.debug('parser '+parser );
            while (parser.nextToken() != null) 
            {
                parser.nextValue();
                String fieldName = parser.getCurrentName();
                String fieldValue = parser.getText();
                
                if(fieldName == 'id')
                {
                    fileId = fieldValue;
                    system.debug('fileId '+fileId );
                    return fileId;
                }
            }                      
            return fileId; 
        }catch (System.CalloutException e){
            System.debug('ERROR:' + e);
        }
    }
    return fileId;
}


Thanks,

Adheena
For Development of a POC for an integration project, we need to generate an Apex Class from a WSDL file of a third party system. We have the WSDL files from their API support. The link is provided below.
https://soapapi.findapprenticeship.service.gov.uk/Services/VacancyManagement/VacancyManagement51.svc?WSDL
But on generating Apex Class from these files,I am hitting some errors in the WSDL. Error is as follows: 
Failed to parse wsdl: Failed to parse WSDL: Unable to find schema for element; {http://services.imservices.org.uk/AVMS/Interfaces/5.1}PublicKey
 
I have integrated salesforce and nab transact for payment purpose. I created fingerprint in my visualforce page using javascript. Now for security reasons I need to change fingerprint generation from visualforce page to my apex controller. I have the following code for the same.
 
String hashv= nabname+'|'+nabpass+ '|2|'+paymentId+'|'+ amtT + '|' + now_utc;
String targetString =hashv ;
Blob targetBlob = Blob.valueOf(targetString);
Blob hashSHA1 = Crypto.generateDigest('SHA1', targetBlob);
String hashBase64SHA1 = EncodingUtil.base64encode(hashSHA1);

"hashBase64SHA1" variable is assigned to the fringerprint field in my vf page. This gives me invalid Fingerprint error. Can anyone help me.
Thanks in advance.
Hi,
We are replacing native functionality of Attachments to upload files to "Box"external storage using Rest API, I was able to upload small files upto 5MB but when trying to upload big files I get the error in Apex code (not even going to box) 
System.StringException: String length exceeds maximum: 6000000
This is occurig when trying to decoding ( base64Decode ) from String blob before Rest API call, please check the code.
String bodyEncoded = EncodingUtil.base64Encode(fileBody);
Blob bodyBlob = null;
String last4Bytes = bodyEncoded.substring(bodyEncoded.length()-4,bodyEncoded.length());
// GW: replacement section to get rid of padding without corrupting data
if(last4Bytes.endsWith('==')) {
    last4Bytes = last4Bytes.substring(0,2) + '0K';
    bodyEncoded = bodyEncoded.substring(0,bodyEncoded.length()-4) + last4Bytes;
    String footerEncoded = EncodingUtil.base64Encode(Blob.valueOf(footer));
    bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+footerEncoded); //Here its failing
}else if(last4Bytes.endsWith('=')){
    last4Bytes = last4Bytes.substring(0,3) + 'N';
    bodyEncoded = bodyEncoded.substring(0,bodyEncoded.length()-4) + last4Bytes;
    footer = '\n' + footer;
    String footerEncoded = EncodingUtil.base64Encode(Blob.valueOf(footer));
    bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+footerEncoded);              
}else{
    footer = '\r\n' + footer;
    String footerEncoded = EncodingUtil.base64Encode(Blob.valueOf(footer));
    bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+footerEncoded);  
}

Error is triggering at "bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+footerEncoded);" this line.
Please advice how can we ignore the size of the file? We need to upload at least 10 MB.

Thanks,
Sumant K

 
SOS fetch case history of customer as shown in the pic. Here in sos no email address is entered by customer. So how does the case details appear in console?
 User-added image
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: 622001247-7550 (-697924050)

*****************************************************************

I receive this error message when trying to load the change set details page.

I tried to log a case with Salesforce.  Seems as though I was directed here and wasn't able to edit any of the case content to fill out the required fields... like Description.  Not sure how you guys could help me.  But if anyone has some insight, that'd be great.  Deployments were working fine yesterday.  I cloned my changeset to upload to production, that didn't work.  Create a brand new change set to upload to production and that didn't work.  So I went to the partial sandbox and created a new change set from there and uploaded it as well, and that also didn't work.  

Thanks