• Ashish2802
  • 25 Points
  • Member since 2015
  • Salesforce Technical Consultant
  • Capgemini

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
  • 0
I am trying to make an Apex callout to Netsuite which is using OAuth1 Authentication. It uses HMAC-SHA256 to generate signature using consumer secret and token secret. 
It is giving me Invalid Login Attempt error with 403 Forbidden error code.
Here is my Apex code.
public static void getResponse(){
        Netsuite_API__mdt netObj = [Select MasterLabel, Consumer_Key__c, Access_Token__c, Consumer_Secret__c, Endpoint_URL__c, Realm__c, Token_Secret__c From Netsuite_API__mdt Where MasterLabel = 'Restlet'];
        String content = '{"createdDate1": ["3/4/2021 12:03 pm"], "createdDate2": ["3/4/2021 12:08 pm"], "lastModifiedDate1": ["3/4/2021 12:03 pm"], "lastModifiedDate2": ["3/4/2021 12:08 pm"]}';
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        HttpResponse response = new HttpResponse();
        request.setHeader('Content-Type', 'application/json');
        request = Restlet_Integration.signRequest(request, netObj.Consumer_Key__c, netObj.Consumer_Secret__c, netObj.Realm__c, netObj.Access_Token__c, netObj.Token_Secret__c);
        	response = http.send(request);
        	System.debug(response.getStatusCode() + response.getStatus());
        catch(System.CalloutException e){
        	System.debug(response.getStatusCode() + response.getStatus());
            System.debug('Callout Error =' + e);
    public static HttpRequest signRequest(HttpRequest req, String consumerKey, String consumerSecret, String realm, String access_token, String tokenSecret){
        String nonce = String.valueOf(Crypto.getRandomLong());
        String timeStamp = String.valueOf(DateTime.now().getTime() / 1000);
        Map<String, String> parameters = new Map<String, String>();
        parameters.put('realm', realm);
        parameters.put('oauth_consumer_key', consumerKey);
        parameters.put('oauth_token', access_token);
        parameters.put('oauth_signature_method', 'HMAC-SHA256');
        parameters.put('oauth_timestamp', timeStamp);
        parameters.put('oauth_nonce', nonce);
        String signature = generateSignature(consumerSecret, tokenSecret);
        String header = generateHeader(signature, parameters);
        System.debug('Header =' + header);
        req.setHeader('Authorization', header);
        return req;
    private static String generateSignature(String consumerSecret, String tokenSecret){
        String nonceKey = String.valueOf(Crypto.getRandomInteger());
        String secretKey = consumerSecret + '&' + tokenSecret;
        Blob sign = Crypto.generateMac('HmacSHA256', Blob.valueOf(nonceKey), Blob.valueOf(secretKey));
        System.debug('Signature =' +  EncodingUtil.convertToHex(sign));
        return EncodingUtil.convertToHex(sign);
    private static String generateHeader(String signature, Map<String, String> parameters){
        String header = 'OAuth ';
        for(String key : parameters.keySet()){
            header = header + key + '="' + parameters.get(key) + '", ';
        return header + 'oauth_signature="' + signature + '"';

I am trying to execute a RESTful Parameterized Search using Workbench on Knowledge Articles. 
For a relatively small search String i am getting less number of records than a bigger search String, however it should be other way around. 

Eg :  - /services/data/v49.0/parameterizedSearch?q='sail'&sobject=Knowledge__kav&Knowledge__kav.where=language='en_US'+and+publishStatus='online'+and+Crew_Support__c=true  - This is returning around 5 records.

While -  /services/data/v49.0/parameterizedSearch?q='sailor'&sobject=Knowledge__kav&Knowledge__kav.where=language='en_US'+and+publishStatus='online'+and+Crew_Support__c=true - This is returning around 15 records.

Can anyone explain the reason behind this ?
I have a lightning component which has started giving below compile error for User.ContactId Field referenced in the apex controller.

Failed to save VV_Circles.cmp : Invalid definition for null: VV_BookingsController: SELECT ID, ContactId FROM User LIMIT 1 ^ ERROR at Row:1:Column:12 No such column 'ContactId' on entity 'User'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

The lightning component was working fine till Spring 19 release was rolled out in the Development sandbox. 

This issue has also impacted the Community Builder Page where this component is being used and causing internal server error in Community Builder.
An internal server error has occurred Error ID: 1138818950-215153 (403527751)

Please provide your suggestions for this issue.
Hi ,
I am displaying a wrapper list in lightning component data table and I want to implement sorting on specific columns in the table. I tried using Comparable interface in apex controller, but it's not working for me.

Can anyone help with sample code for the same ?
Hello, I have a requirement to update roles on partner user record using trigger where the user records will be created using bulk upload process.
I am stuck with the Role id assignment as it requires querying the UserRoleID using the Role Name based on conditions.

Below is my code snippet.

    public static void updatePartnerUserRoles(Set<Id> userIds){
        String roleName = '';
        List<User> updatedUsers = new List<User>();
        for(User u : [Select Id, Contact.Agent_Type__c,  Account.Name From User Where Id IN : userIds]){
            if(u.Contact.Agent_Type__c == 'Admin'){
                roleName = u.Account.Name + ' Partner Manager';
                u.UserRoleId = [Select Id From UserRole Where Name = :roleName LIMIT 1].Id;
            else if(u.Contact.Agent_Type__c == 'Non-Admin'){
                roleName = u.Account.Name + ' Partner User';
                u.UserRoleId = [Select Id From UserRole Where Name = :roleName LIMIT 1].Id;
The code snippet has a SOQL query inside for Loop and I am not able to figure out an alternative solution.
I have a requirement to display visualforce chart as an inline Visualforce page on Opportunity Detail Page.
The chart will be plotted based on the values of some custom fields on opportunity.
The issue is when the values are updated, the chart is not getting refreshed. 

How can I refresh the inline visualforce chart on the click of Standard Save Button on Opportunity ?
Hello - I have a list of records in a lightning component and i want to display the notes for each record using accordion. Please share if there is any in-built accordion component in lightning or how it can be done with a sample piece of code. 

I am new to front end development, so please guide me how to proceed on this.
Hi ,
I am trying to solve the Getting Started with Hybrid Development Trailhead Challenge using Android Studio instead of using Android ADT plugin for Eclipse. 
I am able to create the project using Cordova , but the problem is instead of fetching Salesforce SDK plugins, cordova is fetching Java Whitlelist Plugins.
Hence, its not allowing me to complete the challenge.