• Hanumantha Rao Muddana
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 4
    Replies
This is my controller :

public class ContactsListController{

 private string sortOrder = 'LastName';
 
 public List<Contact> getContacts(){
 
  string soqlQuery = 'SELECT Id, FirstName, LastName, Title, Email'+ 'from Contacts'+ 'OrderBy' + sortOrder 
                          + 'ASC' + 'LIMIT 10' ;
  
  List<Contact> results = Database.query(soqlQuery);
  return results;
  
 }                         

}



And this is my visualforce page :

<apex:page controller="ContactsListController" >
  <apex:form >
   <apex:pageBlock title="Contacts List" id="Contacts_list">
   
    <apex:pageBlockTable value="{!Contacts}" var="ct">
    <apex:column value="{!ct.FirstName}"/>
    <apex:column value="{!ct.LastName}"/>
    <apex:column value="{!ct.Title}"/>
    <apex:column value="{!ct.Email}"/>
    
    </apex:pageBlockTable>
  
   </apex:pageBlock>
  </apex:form>
</apex:page>


I'm getting an error "System.QueryException: unexpected token: 10 " while saving the above vf page. Please help.
Hi,

Is there any sample code to send multipart message from salesforce
Hi All,

What is the best integration approach which need to be followed when integrating SFDC and SAP with middileware SAP PI and the volume of data is expected to be between 1000 and 1500

Scenario 1 :: When SAP PI need to invoke SFDC
Scenario 2 :: When SFDC need to invoke SAP PI

Thanks...

 

 

Hi 

 

I want to upload  a word document  on Box( External Storage)  using Rest API calls  . 

 

Since i need blob as a valid UTF -8 string I am encoding first in base 64 using Encoding util class and then decoding it back as a blob and sending request using req.setbodyasblob() , 

 

I have used all the required parameters but I am getting below invalid request error .

 

{"type":"error","status":400,"code":"invalid_request_parameters","help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Invalid input parameters in request","request_id":"10130606285252db06ef703"}

 

can someone help ?

 

 

 

  public HTTPResponse uploadFile3()
{

   Document file =[Select Body, BodyLength, Id, Name, Type, ContentType From Document ];
      
      
        
       
        String p_fileName =file.Name+'.'+file.Type;
        String parent_id = '1121945745';
        String boundary = 'AaBbCcX30';
       
      
        
        
        String header = 'Content:\r\n--' + Boundary + '\r\n'+'Content-Disposition: form-data; name="files";filename="'+p_fileName+ '"\r\n'+ 'Content-Type:'+file.ContentType+'\r\n\r\n';
        header += '--' + Boundary +'\r\n'+'Content-Disposition: form-data; name="parent_id"'+'\r\n\r\n'+'0'+'\r\n' ;
         
        
       
        system.debug('header' +header);
        String footer = '\n--'+boundary+'--';
        system.debug('footer' +footer);
  // no trailing padding on header by adding ' ' before the last "\n\n" characters
  String headerEncoded = EncodingUtil.base64Encode(Blob.valueOf(header+'\n\n'));
  system.debug('headerEncoded' +headerEncoded);
  //this ensures no trailing "=" padding
  while(headerEncoded.endsWith('='))
  {
   header+=' ';
   headerEncoded = EncodingUtil.base64Encode(Blob.valueOf(header+'\n\n'));
   system.debug('headerEncoded@1' +headerEncoded);
  }
  //base64 encoded body
  String bodyEncoded = EncodingUtil.base64Encode(file.body);
  system.debug('bodyEncoded' +bodyEncoded);
  //base64 encoded footer
  String footerEncoded = EncodingUtil.base64Encode(Blob.valueOf(footer));
    system.debug('footerEncoded' +footerEncoded);
  Blob bodyBlob = null;
  //last encoded body bytes
  String last4Bytes = bodyEncoded.substring(bodyEncoded.length()-4,bodyEncoded.length());
  system.debug('last4Bytes' +last4Bytes);
  //if the last 4 bytes encoded base64 ends with the padding character (= or ==) then re-encode those bytes with the footer
  //to ensure the padding is added only at the end of the body
  if(last4Bytes.endsWith('='))
  {
   system.debug('inside last4 bytes');
   Blob  decoded4Bytes = EncodingUtil.base64Decode(last4Bytes);
   HttpRequest tmp = new HttpRequest();
   tmp.setBodyAsBlob(decoded4Bytes);
   String last4BytesFooter = tmp.getBody()+footer;   
   system.debug('inside last4 bytes@1'+last4BytesFooter);
   system.debug('inside last4 bytes@3'+EncodingUtil.base64Encode(Blob.valueOf(last4BytesFooter)));
   system.debug('inside last4 bytes@2'+ bodyEncoded.substring(0,bodyEncoded.length()-4));
  
   bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded.substring(0,bodyEncoded.length()-4)+EncodingUtil.base64Encode(Blob.valueOf(last4BytesFooter)));
   system.debug('bodyBlob' +bodyBlob);
  }
  else
  {
   bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+footerEncoded);
  }
   
//  if(bodyBlob.size()>3000000)
//  { 
   //this a "public class CustomException extends Exception{}"
 //  throw new CustomException('File size limit is 3 MBytes');
 // }
   
    Http h = new Http();
        HttpRequest req = new HttpRequest();
        string sUrl = 'https://upload.box.com/api/2.0/files/content';
        req.setHeader('Authorization', 'Bearer ' + accessToken);
        req.setHeader('Content-Type','multipart/form-data;boundary='+boundary);
        req.setHeader('Content-Encoding','base64');
      
        req.setEndpoint(sUrl);
        
        req.setMethod('POST');
        req.setBodyAsBlob(bodyBlob);
        System.debug('LAST ENCODING: '+EncodingUtil.base64Encode(req.getBodyAsBlob()));
  
   HttpResponse res;
        if(!Test.isRunningTest()){
            res = h.send(req);
        }
        else{
             res = new HttpResponse();
        }
        valuetoShow = 'Get Doc: ' + res.getBody(); 
        return res;