• Sahana Shekar 7
  • 0 Points
  • Member since 2017

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
  • 4
Hi all,
I am trying to authenticate using the iam role. 
Here i dont have accesskey and secretkey. So Please post me with your code snippet as to how to use the iam role to dynamically generate the key and secret using assume role.
Also please provide the preconditions .

Hello, I am need to send one of our reports via csv. I am trying through apex with this code:

global class ReportEmailCharles implements system.Schedulable {
 global void execute(SchedulableContext sc) {
        ApexPages.PageReference report = new ApexPages.PageReference('/00O63000000uP8GEAU?csv=1');
        Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
        Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
        message.setFileAttachments(new Messaging.EmailFileAttachment[] { attachment } );
        message.setSubject('Overall Pull- 2 All');
        message.setPlainTextBody('Overall Pull- 2 All');
        message.setToAddresses( new String[] { 'mm@abc.org' } );
        Messaging.sendEmail( new Messaging.SingleEmailMessage[] { message } );

The 18 character id of the report I'm testing is 00O63000000uP8GEAU

However the "csv" excel doc of the email I receive looks like this:

User-added image
Anything I can change in my code to make this work?
Hi all,

I need more flexibility in the lightning component aspect of SF and i am relativity new in this.

how can i convert this detailed URL button into a lightning component: 


Just a background to this: since lighting you cannot use java script to validate a button. With lightning component you can use lightning record pages to hide components based on criteria.
I have a need to upload binary stream PDF files to Amazon S3.  I've seen the sample code available to use the REST API with the POST operation on visualforce page, however, I need to upload the file via APEX without user involvment, as I'm retrieiving the files from another database via their SOAP API.

I'm trying to do this using the PUT operation, but I don't think I'm doing the authentication correctly as I'm getting a 403 Forbidden response.

Any ideas?
public void uploadPDF(String binaryPdfString, String key, String secret){
        String Date = Datetime.now().formatGMT('EEE,   dd MMM yyyy HH:mm:ss z');
        String bucketname = 'BucketName';
        String method = 'PUT';
        String filename = 'FileName';
        HttpRequest req = new HttpRequest();
        req.setEndpoint('https://s3-us-west-2.amazonaws.com' + '/'+ bucketname + '/' + filename);
        req.setHeader('Content-Length', string.valueOf(binaryPdfString.length()));
        req.setHeader('Content-Encoding', 'base64');
        req.setHeader('Content-Type', 'pdf');
        req.setHeader('Date', Date);

        //get signature string
        String stringToSign = 'PUT\n\n\n'+formattedDateString+'\n\n/'+bucketname+'/'+filename;
        String encodedStringToSign = EncodingUtil.urlEncode(stringToSign,'UTF-8');
        String signed = createSignature(encodedStringToSign,secret);
        String authHeader = 'AWS' + ' ' + key + ':' + signed;
        Http http = new Http();

        try {
            //Execute web service call
            HTTPResponse res = http.send(req);
            System.debug('RESPONSE STRING: ' + res.toString());
            System.debug('RESPONSE STATUS: '+res.getStatus());
            System.debug('STATUS_CODE: '+res.getStatusCode());

        } catch(System.CalloutException e) {
            system.debug('AWS Service Callout Exception: ' + e.getMessage());


public string createSignature(string canonicalBuffer,String secret){
        string sig;
        Blob mac = Crypto.generateMac('HMacSHA1', blob.valueof(canonicalBuffer),blob.valueof(secret));
        sig = EncodingUtil.base64Encode(mac);

        return sig;