• Kiran Kumar Punuru
  • NEWBIE
  • 0 Points
  • Member since 2017
  • Salesforce Developer


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 2
    Replies

Hi All,

I have issue to update a record in another application from salesforce i am using the below code to update the record but looks like there is an issue becuase of that i am getting the below error:

Does someone tell me is there anything went wrong on my code with respect to body which i am using to update?

22:21:46:468 USER_DEBUG [188]|DEBUG|Response body{"ok":false,"errors":[{"code":"invalid_api_key","message":"Invalid token: bad hash"}]}

global static void updateRecipients(){
      
       string endPoint = 'https://api.paymentrails.com/v1/recipients/R-2nVbDmuyF7ykgd57eY1VQS';
       string reqpath = '/v1/recipients/R-2nVbDmuyF7ykgd57eY1VQS';
       string API_KEY = 'xyztest';
       string apiSecret = 'xyztest';
  
        string body = '{"lastName":"punuru"}';
    
        
      // Get the timestamp
      Datetime dt = Datetime.now();  
      Long l = dt.getTime();
      system.debug(l);
      Long epochDate = dt.getTime()/1000;
      Integer timeStamp = epochDate.intValue();  
      system.debug('@@@timeStamp'+timeStamp);
      string authoriation = 'prsign'+' '+API_KEY+':'+SecurityManagerController.generateAuthorization('PATCH',reqpath,apiSecret,timeStamp,body);
      system.debug('@@@authoriation'+authoriation);
     
     //Create Request
      HttpRequest req = new HttpRequest();
      req.setMethod('PUT');
      req.setHeader('X-HTTP-Method-Override','PATCH');
      req.setHeader('content-type', 'application/json');
      req.setHeader('Authorization', authoriation);
      req.setHeader('X-PR-Timestamp', timeStamp + '');
      req.setEndpoint(endPoint);
      req.setBody(body);
      Http http = new Http();
      HttpResponse res = http.send(req);
      system.debug('Response body'  +res.getBody());
      system.debug('STATUS: '+ res.getStatus());
      system.debug('STATUS_CODE:'+ res.getStatusCode());
    }

SecurityManagerController
public with sharing class SecurityManagerController {

  public static final String MACENCRIPTION = 'HmacSHA256';
 

  public static String generateAuthorization(String method,String requestPath,String secretKey,integer timestamp,String body){
    
         String signatureData = +timestamp + '\n' + method + '\n' + requestPath + '\n' + body + '\n' ;
        
        
        System.debug('@@@signatureData'+signatureData);
         Blob mac        = crypto.generateMac('HmacSHA256', Blob.valueOf(signatureData), Blob.valueOf(secretKey));
         system.debug('@@@data'+mac);
        // Blob hash = Crypto.generateDigest('SHA-256', mac);
        // Boolean verified = Crypto.verifyHMac('HmacSHA256', Blob.valueOf(signatureData), Blob.valueOf(secretKey), mac);
         System.debug('@@@verified'+mac);
         String signature = EncodingUtil.convertToHex(mac);
         System.debug('@@@docBody'+signature);
         return signature;
  }
 }

Thanks in Advance!!

Hi All,

​​I am using emoji symbol in html and using in email body in Apex class.It is working fine in sandbox but when deployed the code to production it is not working any specific reason?

Thanks in advance.
 
Hi All,

I am trying to integrate googel form to salesforce.

Example : When form is submitted from the google form it has to create a account record in salesforce.

If someone has done could you please provide  links for reference .

Thanks 
Hi All,

I have a requirement where i need to update the owner for the new record created to the user which has the email in the same record.

For example:

If i create a record with name : abc
                                     email : xyz@test.com

then after record was created the owner for the new record has to be changed to user associated with email xyz@test.com.

Any suggestions or ideas are helpful .

Thanks
Hi ,
I have a requirement like this ,I have a custom object which related to account,opportunity when a value of a field in custom object is changed from one to another i need to send an email with pdf as attachment.
The attached pdf should contains 4 tables :
1)Account Information
2)Custom Object Information
3)Opportunity Information
4)Opportunity Product Information
Can you help me how to achieve this i already tried but not getting desired result.
Thanks,
Kiran

Hi All,

I have issue to update a record in another application from salesforce i am using the below code to update the record but looks like there is an issue becuase of that i am getting the below error:

Does someone tell me is there anything went wrong on my code with respect to body which i am using to update?

22:21:46:468 USER_DEBUG [188]|DEBUG|Response body{"ok":false,"errors":[{"code":"invalid_api_key","message":"Invalid token: bad hash"}]}

global static void updateRecipients(){
      
       string endPoint = 'https://api.paymentrails.com/v1/recipients/R-2nVbDmuyF7ykgd57eY1VQS';
       string reqpath = '/v1/recipients/R-2nVbDmuyF7ykgd57eY1VQS';
       string API_KEY = 'xyztest';
       string apiSecret = 'xyztest';
  
        string body = '{"lastName":"punuru"}';
    
        
      // Get the timestamp
      Datetime dt = Datetime.now();  
      Long l = dt.getTime();
      system.debug(l);
      Long epochDate = dt.getTime()/1000;
      Integer timeStamp = epochDate.intValue();  
      system.debug('@@@timeStamp'+timeStamp);
      string authoriation = 'prsign'+' '+API_KEY+':'+SecurityManagerController.generateAuthorization('PATCH',reqpath,apiSecret,timeStamp,body);
      system.debug('@@@authoriation'+authoriation);
     
     //Create Request
      HttpRequest req = new HttpRequest();
      req.setMethod('PUT');
      req.setHeader('X-HTTP-Method-Override','PATCH');
      req.setHeader('content-type', 'application/json');
      req.setHeader('Authorization', authoriation);
      req.setHeader('X-PR-Timestamp', timeStamp + '');
      req.setEndpoint(endPoint);
      req.setBody(body);
      Http http = new Http();
      HttpResponse res = http.send(req);
      system.debug('Response body'  +res.getBody());
      system.debug('STATUS: '+ res.getStatus());
      system.debug('STATUS_CODE:'+ res.getStatusCode());
    }

SecurityManagerController
public with sharing class SecurityManagerController {

  public static final String MACENCRIPTION = 'HmacSHA256';
 

  public static String generateAuthorization(String method,String requestPath,String secretKey,integer timestamp,String body){
    
         String signatureData = +timestamp + '\n' + method + '\n' + requestPath + '\n' + body + '\n' ;
        
        
        System.debug('@@@signatureData'+signatureData);
         Blob mac        = crypto.generateMac('HmacSHA256', Blob.valueOf(signatureData), Blob.valueOf(secretKey));
         system.debug('@@@data'+mac);
        // Blob hash = Crypto.generateDigest('SHA-256', mac);
        // Boolean verified = Crypto.verifyHMac('HmacSHA256', Blob.valueOf(signatureData), Blob.valueOf(secretKey), mac);
         System.debug('@@@verified'+mac);
         String signature = EncodingUtil.convertToHex(mac);
         System.debug('@@@docBody'+signature);
         return signature;
  }
 }

Thanks in Advance!!

Hi ,
I have a requirement like this ,I have a custom object which related to account,opportunity when a value of a field in custom object is changed from one to another i need to send an email with pdf as attachment.
The attached pdf should contains 4 tables :
1)Account Information
2)Custom Object Information
3)Opportunity Information
4)Opportunity Product Information
Can you help me how to achieve this i already tried but not getting desired result.
Thanks,
Kiran