Saturday, 30 May 2020

Integration Errors & Fixes


1.error=redirect_uri_mismatch&error_description=redirect_uri%20must%20match%20configuration
Updated connected app callback URL with the callback URL from Auth provider.

2.We can't authorize you because of an OAuth error. For more information, contact your Salesforce administrator. 1800 : There was a problem in setting up your remote access
Log off all the open source and target orgs and try to authenticate again.

Scenario :
If any changes in Auth Provider,When you try to save named credentials with latest changes while authenticating you may get this error if the target org is already open.

3.The authentication provider didn't provide a refresh token. If the access token expires, your org won't be able to access this named credential.
Go To --> Authentication Provider --> Default Scopes - Provide value [refresh_token full]in this and save and save Named Credentials

4.System.HttpResponse[Status=Unauthorized, StatusCode=401]
Authentication Status in Named credentials should be Authenticated for the Target org user [Integration user]
Verify the credentials.


Friday, 29 May 2020

Lightning Web Components Errors & Fixes

1. SFDX: Create Project.

Error :
09:47:54.651 sfdx force:project:create --projectname
HelloWorldLightningWebComponent --outputdir c:\LWC --template standard
ERROR running force:project:create:  Command failed with
exit code 1: npm root -g --prefix c:\LWC\.yo-repository --loglevel error
'npm' is not recognized as an internal or external command,
operable program or batch file.
09:47:57.138 sfdx force:project:create --projectname
HelloWorldLightningWebComponent --outputdir c:\LWC --template standard
 ended with exit code 1

Fix : Update the CLI
VS Code --> Terminal --> SFDX Update

2. SFDX: Update
Error :  Channel "stable" not found.
Fix : Close the visual studio and open again try to execute the command,It solved for me.

3. SFDX: Scratch Org Creation
Error :  running force:org:create:  Error authenticating with the refresh token due to:                   expired access/refresh token
Fix : First Authenticate the Dev Hub login & Then try to create scratch org
sfdx force:auth:web:login -d -a DevHub sfdx force:org:create -d 30 -s -a eslwc -f config/project-scratch-def.json

4. Handling Server Errors Example Implementation

Error :  No Module named markup://c:ldsUtils found :[markup://c:accountList]

Fix :      First deploy the “ldsUtils” to source org and then try to deploy “accountList”

5. Set Up Jest Testing Framework
Error : npm ERR! request to https://registry.npmjs.org/@salesforce%2fsfdx-lwc-jest failed, reason: self signed certificate in certificate chain
while executing "sfdx force:lightning:lwc:test:setup"
Fix : Execute below command 1st
npm config set strict-ssl false

5. How to retrieve component from Salesforce to Visual Studio ?
Ex: Retrieve boatMap component from Salesforce to VS
sfdx force:source:retrieve -m LightningComponentBundle:boatMap

To get project specific :

sfdx force:source:retrieve -p C:\LWC\BoatSearch-LWC-SP\force-app\main\default\lwc -u vscodeOrg


To get all the LWC comp :

sfdx force:source:retrieve -m LightningWebComponentBundle


Tuesday, 21 April 2020

SOQL Injection Best Practice

SOQL Injection :
SOQL Injection takes the user inputs for the values used in dynamic queries. 

Risk :
Always risk malicious users can send different values or commands to fetch their expected data & Crash the data /Update the data.

Preventing Steps:
1.Salesforce platform level already taken care and provided only SOQL queries, no update / delete. This reduces the risk to some extent compare to other query platforms.
2. But still with SOQL queries also has the risk, So it is very much important to validate the provided input to avoid SOQL Injection Vulnerability.
·       Always best practice to write static queries with bind variables 
·       If needed to use the dynamic queries based on the requirement then must use the “String.escapeSingleQuotes” to the passing values

Ex:
Different Scenario, what could be the fix to avoid the SOQL Injection Vulnerability?
Whitelisting to fix this :

//In case fetching the field names & object names from other source metadata /label/etc
String Field1;
String Field2;
String objName;
String accId = ‘xxxxxxxx’; // Account Id to pass
String strQuery;

if(Field1!=NULL && Field2!=NULL && objName!=NULL )
                {
                    strQuery = 'SELECT ' +  Field1+','+ Field2+' ' + ' FROM '+ objName +
                        ‘ WHERE Id = \''+ String.escapeSingleQuotes(accId) + '\'' +' AND '+' '+ Field2+' '+'!=0' ; 
                }

Fix :

//Compare with the exact names instead of !=NULL

if(Field1 == ‘Name’ && Field2 == ‘AccountNumber’  && objName == ‘Account’ )             
  {
                    strQuery = 'SELECT ' +  Field1+','+ Field2+' ' + ' FROM '+ objName +
                        ‘ WHERE Id = \''+ String.escapeSingleQuotes(accId) + '\'' +' AND '+' '+ Field2+' '+'!=0' ; 
                }

Friday, 8 November 2019

Custom Metadata Loader


Why do you need Custom Metadata Loader ?
Data Loader doesn't support to load the Custom Metadata as of today(Nov 2019),So we have workaround using Custom Metadata Loader can load or update bulk data up 200 records with a single call.

Quick steps to set up Custom Metadata Loader ?
1.Download the zip file & Extract and create new zip file with only below components.


2.Use workbench to deploy this zip file,Refer for quick steps

3.Setup || Permission Set || Custom Metadata Loader || Manage Assignments || Add Assignments --> Give permission to the users who requires this feature.


4.Now you can see the "Custom Metadata Loader" in app picker,Select that app --> Select Custom Metadata Loader tab.


5.Click on the Create Remote Site Setting button of the page.


6.Configure the data load csv file to upload,Take reference of the sample.csv file from the above downloaded zip.


Error : Cannot create a new component with the namespace: XXX. Only components in the same namespace as the organization can be created through the API.

Reason : Your org enabled/created custom domain
Solution : Setup || Remote Site Settings || New Remote Site


Remote Site Name
c_mdapi
Don’t change, provide as it is
Remote Site URL
Copy the page url where your getting that error

Active
True




Tuesday, 1 October 2019

REST API - Connected App,Auth.Provider,Named Credentials

Use Case :There is S2S connection established between 2 orgs, Opportunity is published from one org to another org,Due to S2S Connection User does not have user context ,Because of this expected CPQ functionality is not triggering even though the field update is happened  through S2S.


Workaround / Solution : Use REST API to update the specific field on the opportunity instead of S2S.

What are the steps to implement this requirement ?
1.Opportunity Update Service Creation. - REST Service Provider.
       

            @RestResource(urlMapping='/OppUpdate/*')
            global with sharing class OppUpdateREST 
            {
             @httpput
             global Static String UpdateOpp(String oppId,Boolean IsPrivate)
             {
                try
                 {
                    Opportunity objOpp = new Opportunity();
                    objOpp = [select id,IsPrivate from Opportunity where id=:oppId]; 
                    objOpp.IsPrivate= IsPrivate; 
                    update objOpp; 
                    return 'Success';
                 }
               catch(Exception ex)
                 {
                    return ex.getMessage();
                 }                 
              }
            }

       
 

2.Opportunity Update Call Out - REST Service Consumer
       
    @future(callout=true)
    public static void Opp_Update(String oppId,Boolean UpdateIsPrivate)
    {
        String jsonstr = '{"oppId" : "' + oppId + '","IsPrivate" : ' + UpdateIsPrivate +'}';
        Http http = new Http();
        HttpRequest req = new HttpRequest();
        req.setHeader('Content-Type','application/json');          
        req.setBody(jsonstr);
        req.setMethod('PUT'); //To Update the record   
        req.setEndpoint('callout:Opp_Update'); //Named Credential   
        HttpResponse resp = http.send(req);
        if (resp.getStatusCode() == 200) // Success
        {
            System.debug(resp.getBody());            
        }
        else 
        {
            System.debug('The status code returned was not expected: ' +   resp.getStatusCode() + ' ' + resp.getStatus());
        }           
    }
       
 

3.Required below configuration with respect to the service provider & consumer.


4.Connected App - Creation in Service Provider
Go to Setup | Create | Apps | Connected Apps

Note 1 : As of now enter any url as call back url & Make sure to update it with Auth.Provider callback url once created in Service Consumer.
Note 2 : It's manual step to create,Can't deploy from sandbox to sandbox


5.Share the “Consumer Key”,”Consumer Secret” with Service Consumer Auth.Provider.


6. After saving connected app → click on “Manage”  → “Edit Policies”



7.Save the connected app configurations & Share the details with web service consumer.



8. Auth. Providers -
Creation in Service Consumer
Go to Setup | Security Controls| Auth. Providers

Note 1 : This can be deployed,After deployment can edit the details highlighted below.
Note 2 : Callback URL is not editable,Copy this and update it in the “Service Provider” connected App as created above.
You will get Salesforce Login window 1st time to authenticate the integration user while saving this.



9 Named Credentials :
Go to Setup | Security Controls| Named Credentials


Note 1 : This can be deployed,After deployment can edit the details highlighted below.
URL [End point] & Authentication Provider [Created In The Above Steps]
Note 2 : While saving this, Validate with  integration user & Verify “Authentication Status,''Should be Authenticated.



10.Profile Permissions :  Provide access to the web service class for the integration user who's need to authenticate


Friday, 27 September 2019

Deployment Through WorkBench


1.Create the "package.xml"  which needs to be deployed,If you already created changeset and here is the link to generate "package.xml" from change set Refer

2.Login to the workbench to retrieve the components.[Source Sandbox]




3.Login to the workbench to deploy the components.[Target Sandbox]

Note : 1.Use the 'Check Only' option to validate this deployment without making changes.
If validation is success then can deploy
2.The zip file should be in this folder structure Package_Name\unpackaged\Files




Thursday, 19 September 2019

Data Loader With Zulu Open JDK 11 Installation


Data Loader version 45 and above now require users to install Zulu OpenJDK where as prior versions required Java Runtime Environment (JRE).

Please find the below steps for successful installation :

1.Download the “.msi” file as highlighted below.
Note : Download as per the latest version

2.Download the data loader from Salesforce.



3.After download,unzip and execute - “install.bat”

4.Create new folder / Allow in the default folder to install.


5.After successful installation ,You will get like below.

6.After installing the icon on the desktop.

7.Finally,Data Loader is ready to work.


For more details ,Please refer