Resolving Salesforce Lightning Web Components(LWS) errors(Trailhead example)

Lightning Web Components are launched few months back and already there are many write-ups/blogs to create your first few components. I’ve also recently jumped the bandwagon but faced lots of some challenges during set up and creating my first ‘Hello World’ component. On searching, I’m finding there is not much help available yet if you come across any failure.

I’m writing this blog so that others can benefit, if they face any such issue, which I’ve faced. Please note, as of now I’ve started doing trailhead module for this :

Your First lightning web component

First Error:

After installing  Salesforce CLI, I opened command prompt(same can be done, using ‘New terminal’ option on top bar-> Terminal option) – Typed ‘sfdx’ and as I expected, It gave :

‘sfdx’ is not recognized as an internal or external command,
operable program or batch file.

  • Now, nothing mentioned in trailhead, what to do, in case you fail such issue:
  • Resolving this is simple – all you’ve to do is to ‘edit’ path  in environmental variables and add path of ‘bin’ folder of Salesforce CLI. You can use path variable, mentioned in either User/System environmental variable(s). To edit environment variable,  type ‘edit env’ in Windows search and it will open screen, where you can edit it.
  •  Generally, bin folder is located in following location :C:\Program Files\Salesforce CLI\bin. Copy this path and paste in path of Environment variable as mentioned above.

Second Error :

Cannot find Lightning Component Bundle helloWorld
  • I faced this problem, when I was deploying components to an Org, which already has hello world (Aura) component available. Note that, it seems presence of even aura component with same Name, hinders deployment of LWC.
  • Preferably create new ‘Trailhead Org’, when you’re starting working on LWC.

Third Error : This weird error came from piece of code in helloWorld.html

        value={greeting}       onchange={changeHandler}     >
  • If you notice,  in example, there are no double quotes(“”) around {greeting} and {changeHandler}. But on saving in VScode ,it was automatically adding quotes and because of compilation errors was coming.
  • To resolve this, I’ve to open the folder(again named helloWorld) , containing helloWorld.html file, using windows explorer(note: not from inside VSCode etc). Modify it with notepad(any editor, apart from VSCode) to remove these quotes.
  • After that, then I again right clicked ‘default’ folder and used ‘SFDX:Deploy Source to Org’ and then it worked like a charm!

Fourth Error : This happened while running below command :

Starting SFDX: Create a Default Scratch Org.
ERROR running force:org:create:  Must pass a username and/or OAuth options when creating an AuthInfo instance.
  • This means, that you’ve not set up DevHub Org properly. Scratch org needs DevHub to be set up properly.
  • As per my current understanding, this seems like Parent org for all the temporary scratch orgs. Ensure that, in atleast of your Trailhead(or Dev) org, DevHub(set up-> DevHub) is enabled
  • Then from terminal in VSCode running following commands:
    • sfdx force:auth:web:login -d
    • it should open browser. In that please enter credentials for org in which Debhub settings are enabled
    • You’ll see a message showing that you’ve successfully authorized yourself with org Id(<15/18 digit ID) of DevHub
    • Run next : sfdx force:auth:web:login -d -a DevHub

Another thing to Note: Make sure, you’ve authorized correct org(Trailhead Playground) using SFDC:Authorize an Org. if not sure, do it again.

Happy Coding! 🙂



Tips and Tricks : Salesforce Certified Sharing and Visibility Designer Exam (with Sample questions)

Today, I’ve passed Salesforce ‘Sharing and Visibility Designer Exam’. Phew! This was a little tough! In-spite of studying all the topics, Still I was finding difficulty answering many types of questions. And this is not without reasons!

  1. Firstly I found quite a few questions(5-6) with confusing answers choices. It seemed none was correct.
  2. Some questions seem to have multiple correct answers but you were forced to select one.
  3. Some were very very lengthy. Few took me more than 4-5 minutes. Considering, you’ve just, on an average of 2 minutes( 60 ques/120 min) to answer each question, This seems a pretty big number.

Above problems, you’d normally face in any salesforce certification but considering, you don’t have any many sample questions set etc available for architect-level certifications, this has become pretty challenging.

Now coming to the main points:

What helped me to prepare for this certification:

  1. I would say  ‘official’ trail mix for this is all that you need: Architect-sharing-and-visibility
    • This pretty much covers everything ! if you can read everything twice, then that is sufficient as per my experience.
  2. To find what are important topics/concepts –  visit those, which are mentioned by these fellow bloggers in below posts. I’m not going to repeat them. These are what I faced in the exam today.

Now comes the most interesting part:

Few samples questions, which I’ve come across in today’s exam. Please note, don’t treat this as a dump because firstly, I don’t remember all the details of questions mentioned below. This is just to give you an idea what is expected from you in the exam.

  1.  In a platform based health application, large text area field is used by doctors to enter their notes. Business found that this field contains sensitive PII information and asked an architect to suggest a solution so that data remains encrypted in both ‘REST’ as well as in ‘Transit’.
    • Out of options given 2 were obviously not correct. Only contention was,  between the following 2 options:
      • Enable Platform encryption and makes notes field  as encrypted
      • Create a new encrypted field(Classic encryption) and move notes data to the new field.
    • It was tricky, as I was not considering option 1 because I was not sure in Platform encryption keeps data encrypted in both ‘Rest’ and ‘Transit’.
    • create new encrypted field also doesn’t seem correct as it has just 175 character limit and might not be sufficient to store large text area data.
    • This is the reason, I selected Platform encryption as the correct answer
    • Read the first line of this article and I think above is correct :
  2. A developer is creating a managed package for their internal org which makes call out to an external system. The architect wants that username and password (to call out external system) should be secured properly. Basic authentication is done to make a call out. Where should credentials be stored? Choose 3 options:
    • Protected custom settings
    • Protected custom metadata
    • named credentials
    • encrypted text field
    • I don’t remember ( as was not relevant)
      •  First 2 choices were obviously correct. I got confused in the next two ones. But since named credentials are still visible to anyone with ‘customize application’ permission, so I chose 3rd option as ‘encrypted text field’.(I may be wrong, please verify yourself)
  3. Find a vulnerability  in the following code snippet
    • <apex:outputText escape=”false”>
      Hello {!$CurrentPage.parameters.userName}

    • Again 4 choices were given, two were something different, not able to recall. We’ve to basically choose from either :
      • SOQL injection
      • XSS attack ( which was the correct answer as escape was set as false)
  4. Universal Container wants synchronization between an external ERP system and its Salesforce Org. The external system has thousands of Accounts & Contacts, while Salesforce has only contacts but no Account(s). The external system wants to run synchronization to update 100,000 Contacts in Salesforce.  In OWD setting in Salesforce-  Accounts are Private & Contacts are controlled by Account. How can architect design a solution so that Salespeople within Salesforce can view all the Contacts (not necessary for them to view ‘Accounts’)
    • Create a dummy Account. Run synchronization & link all  newly created/updated Contacts to that Account and create Sharing rule on Account
    • Create a dummy Account. Run synchronization & link all  newly created/updated Contacts to that Account and create Sharing rule on Contact
    • Run Synchronization and create(or update) both Accounts and Contacts and create sharing rule on Contact to share them to Salespeople
    • Run Synchronization and create(or update) both Account and Contacts and create sharing rule on Account to share them to Salespeople
      • This was a big question. But a key point is, when Contacts are controlled by Account, you can’t create sharing rules on Contact. So options 2nd and 3rd are straightforward to be ruled out.
      • Creating a dummy account for 100, 000 contacts could create locking issues and parent-child skew, so not much desirable.
      • Best seems to be last one – create both Account and Contact via synchronization and create Account sharing Rules
  5. A developer has created visual force page on the lead object using Standard Controller. How he can ensure user permissions(FLS) are enforced
    • First two options are related to using ‘isAccessible()’ etc on the appropriate Describe Field Result in associated apex controller.
    • One was obviously wrong, like using with Sharing/Without sharing keywords in apex controller.
    • Last option was something like :
      • <apex:outputText value="{!lead.Name}" 
                     rendered="{!$ObjectType.Lead.fields.Name.Accessible}" />
    • This seems correct as first two options can also be ruled out as ‘standard’ controller was used so apex code based checks are not appropriate
    • Please read this article wholeheartedly to grasp concepts
  6.  What is the required to remove permission to exports reports?
    • Remove export button option from report page layout
    • Remove manager permission from corresponding report folder
    • Remove export report permission from the user profile
    • Another(not able to recall ).
      • 3rd seems to be the correct answer
  7. UC has enabled the feature of Case teams in their Org, what are the options available to filter when creating List views. Select 2 options.
    • Groups
    • Roles
    • Queues
    • Teams
      • Seems, last two (Queues and Teams) are correct answers.
  8. What type of Grants are stored in Group membership tables? Choose two :
    • Inherent Grant
    • Group membership Grant
    • Implicit Grant
    • Explicit Grant
  9. (confusing one, able to recall just little bit). Basically, it was like- how to ensure manual sharing given on Account didn’t get deleted, when ownership changes
    • As usual, the first two options were not seemed to be related.
    • Set Sharing reason as ‘Manual’.
    • Set Custom sharing reason
      • Now, none seemed to be as correct.
      • If you set  Sharing reason was ‘Manual’ , manual sharing would get deleted. On the other hand, you can’t set custom sharing reason on Standard object(Account) as per my understanding.
      • Still, I selected the last one(Custom Sharing reason) as the correct reason.

I’d keep adding more questions if I’m to recall. Till then wish you, all the best in your preparations!

Using Queueable interface to save page as PDF attachment

Sometimes, it is needed to save current visual force page content as PDF in Salesforce. This could be quite heavy depending upon how long the visual force page is.Ideally, it should be done with combination of @future(Callout = true) & Queueable interface which I’m describing below:

  1. Create a handler class which should have method to save current vf page into PDF attachment.

    public static void createPDFAttachment(IdcobjId, string PageName){

    Obj__c obj1; // object under which you’ve to save attachment
    //Using object, create name of attachment using your own logic and pass to queueable interface

    string attachmentName = ‘xyz’;
    try {
    myQueuebaleClass pdfGen= new myQueuebaleClass (objId, pageName, attachmentName);
    } catch (Exception e) {
    //log exceptions
    } finally {

    ////*****************Queueable Interface Class*********************

    public class myQueuebaleClass implements Queueable {

    public myQueuebaleClass(Id objId, String pageName, String attachmentName, ){        //Set member properties

    this.objId= objId;
    this.pageName = pageName;
    this.attachmentName = attachmentName;
    public void execute(QueueableContext context){

    //Building the page URL that will be used to generate the PDF of the form
    PageReference pdfPage = new PageReference(‘/apex/’ + pageName + ‘?ObjectId’ + ‘=’ + objId);

    //Instantiating a new attachment record
    Attachment attachmentObject = new Attachment();

    if (Test.IsRunningTest()) {
    attachmentObject.Body = Blob.valueOf(‘Test’);
    } else {
    //setting the content of the attachment by using Salesforce content and then setting the content type as PDF so that the attachment record is stored as PDF
    attachmentObject.Body = pdfPage.getContent();
    //flag to make sure the attachment record is accessible by the relevant users
    attachmentObject.IsPrivate = false;
    attachmentObject.ParentId = ApplicationId;

    //Query existing attachments of the object

    objects= [SELECT Id,
    (select Id, Description from Attachments)
    from obj__c
    WHERE Id = :objId For Update];

    List<Attachment> attachmentList = new List<Attachment>();
    for (Attachment att : objects[0].Attachments) {

    //If an attachment record exists, overwrite it with the new data.
    if (attachmentList.Size() == 1) {
    attachmentObject.Id = attachmentList[0].Id;

    // clean up multiple PDFs of the same form
    if (attachmentList.size() > 1) {
    // delete them all and start again
    delete attachmentList;
    upsert attachmentObject;