• Rhythm Sharma
  • NEWBIE
  • 10 Points
  • Member since 2022

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

Hi All,
 
I have this error:
 
System.CalloutException: Failed to create certificate java.security.cert.CertificateException: Could not decode the client certificate. Please ensure that it is a base64 representation of a PKCS12 file: toDerInputStream rejects tag type 45
 
I am integrating ADP into Salesforce using rest, I am trying to get access token from ADP.
Code - 

public class getAccessToken {

    public static void getToken() {

        HttpRequest request = new HttpRequest();

        HttpResponse response = new HttpResponse();

        Http http = new Http();

        // Set the request URL

        String authEndpoint = 'https://accounts.adp.com/auth/oauth/v2/token';

        request.setEndpoint(authEndpoint);

        // Set the request method

        request.setMethod('POST');

        // Set the request headers

        request.setHeader('Content-Type', 'application/x-www-form-urlencoded');

        // Set the request body

        String payload = 'grant_type=client_credentials' +

            '&client_id=437134191f47' +

            '&client_secret=49651ff0-70b6baac';

        request.setBody(payload);

        // Retrieve the AFHMutualSSLCert key file from static resource

        StaticResource staticResourceAFHMutualSSLCert = [SELECT Body FROM StaticResource WHERE Name = 'AFHMutualSSLCert'];

        String AFHMutualSSLCertContent = staticResourceAFHMutualSSLCert.Body.toString();

        system.debug('AFHMutualSSLCertContent: '+AFHMutualSSLCertContent);

        // Convert the AFHMutualSSLCertContent key to Base64-encoded string

        Blob AFHMutualSSLCertKeyBlob = Blob.valueOf(AFHMutualSSLCertContent);

        String AFHMutualSSLCertKeyBase64 = EncodingUtil.base64Encode(AFHMutualSSLCertKeyBlob);

        system.debug('AFHMutualSSLCertKeyBase64: '+AFHMutualSSLCertKeyBase64);

        // Retrieve the private key file from static resource

        StaticResource staticResourcePrivateKey = [SELECT Body FROM StaticResource WHERE Name = 'AFHPrivateKey'];

        String privateKeyContent = staticResourcePrivateKey.Body.toString();

        system.debug('privateKeyContent: '+privateKeyContent);

        // Convert the private key to Base64-encoded string

        Blob privateKeyBlob = Blob.valueOf(privateKeyContent);

        String privateKeyBase64 = EncodingUtil.base64Encode(privateKeyBlob);

        system.debug('privateKeyBase64: '+privateKeyBase64);

         request.setClientCertificate(AFHMutualSSLCertKeyBase64, privateKeyBase64);

        system.debug('request: '+request.getBody());

        // Send the request and get the response

        response = http.send(request);

        system.debug('response: '+response);

        // Parse the response

        if (response.getStatusCode() == 200) {

            // Successful response

            Map<String, Object> responseMap = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());

            String accessToken = (String) responseMap.get('access_token');

            System.debug('Access Token: ' + accessToken);

            // Use the access token for further API requests

        } else {

            // Error handling for failed request

            System.debug('Error: ' + response.getBody());

        }

    }

}
Hello Everyone, I am integrating ADP into Salesforce but for this, I have to get an access token from ADP, I tried but not getting an access token. so if anyone has worked on this please let me know.

#salesforce
I have an object called myObject__c and when I create a new field, I want to get the field's name on runtime in apex. How can we do this?
Hello Everyone. I have integrated google calendar events and now i am working on getting Gmail data of user like, inbox messages, send messages etc. Do anyone have any idea how can i do this using REST API ? 
what should we do if we are getting data through API in controller class and we want to show data on aura page ?  
Hello Everyone, I am integrating ADP into Salesforce but for this, I have to get an access token from ADP, I tried but not getting an access token. so if anyone has worked on this please let me know.

#salesforce
I have an object called myObject__c and when I create a new field, I want to get the field's name on runtime in apex. How can we do this?
Hi all can someone help me with lightning component.
Actually I want to display the list which is returned from my apex class . Please tell me the solution