Back to Top

Custom Login Component

Posted on TimeMarch 30, 2026

 Apex:

public without sharing class RIDOSCustomLoginController {

    @AuraEnabled
    public static String loginUser(String usernameInput, String password, String startUrl) {
        if (String.isBlank(usernameInput)) {
            throw new AuraHandledException('Username is required.');
        }
        if (String.isBlank(password)) {
            throw new AuraHandledException('Password is required.');
        }

        String finalUsername = usernameInput.trim();

        if (finalUsername.contains(' ')) {
            throw new AuraHandledException('Username should not contain spaces.');
        }

        if (!finalUsername.contains('@')) {
            finalUsername = finalUsername + System.Label.RIDOSEmail;
        }

        String targetUrl = String.isBlank(startUrl) ? '/s/' : startUrl;

        try {
            PageReference loginResult = Site.login(finalUsername, password, targetUrl);

            if (loginResult != null) {
                return loginResult.getUrl();
            }

            throw new AuraHandledException('Your login attempt has failed. Make sure the username and password are correct.');
        } catch (Exception e) {
            throw new AuraHandledException('Your login attempt has failed. Make sure the username and password are correct.');
        }
    }
}

LWC: Js:
import { LightningElement, track } from 'lwc';
import loginUser from '@salesforce/apex/RIDOSCustomLoginController.loginUser';

export default class RidosCustomLoginPage extends LightningElement {
    @track username = '';
    @track password = '';
    @track errorMessage = '';
    @track isLoading = false;

    get buttonLabel() {
        return this.isLoading ? 'Logging in...' : 'Log in';
    }

    handleUsernameChange(event) {
        this.username = event.target.value;
        this.errorMessage = '';
    }

    handlePasswordChange(event) {
        this.password = event.target.value;
        this.errorMessage = '';
    }

    async handleLogin() {
        this.errorMessage = '';

        const trimmedUsername = this.username ? this.username.trim() : '';

        if (!trimmedUsername) {
            this.errorMessage = 'Username is required.';
            return;
        }

        if (trimmedUsername.includes(' ')) {
            this.errorMessage = 'Username should not contain spaces.';
            return;
        }

        if (!this.password) {
            this.errorMessage = 'Password is required.';
            return;
        }

        this.isLoading = true;

        try {
            const redirectUrl = await loginUser({
                usernameInput: trimmedUsername,
                password: this.password,
                startUrl: '/s/'
            });

            window.location.href = redirectUrl;
        } catch (error) {
            this.errorMessage =
                error && error.body && error.body.message
                    ? error.body.message
                    : 'Invalid username or password.';
        } finally {
            this.isLoading = false;
        }
    }
}


Html:

<template>
    <div class="login-wrapper">

        <!-- 🔴 Error message on top -->
        <template if:true={errorMessage}>
            <div class="error-message-top">
                {errorMessage}
            </div>
        </template>

        <!-- Username -->
        <div class="input-box">
            <lightning-icon
                icon-name="utility:user"
                size="x-small"
                alternative-text="Username"
                class="input-icon">
            </lightning-icon>

            <input
                class="custom-input"
                type="text"
                placeholder="Username"
                value={username}
                oninput={handleUsernameChange} />
        </div>

        <!-- Password -->
        <div class="input-box">
            <lightning-icon
                icon-name="utility:lock"
                size="x-small"
                alternative-text="Password"
                class="input-icon">
            </lightning-icon>

            <input
                class="custom-input"
                type="password"
                placeholder="Password"
                value={password}
                oninput={handlePasswordChange} />
        </div>

        <!-- Button -->
        <button class="login-btn" onclick={handleLogin} disabled={isLoading}>
            {buttonLabel}
        </button>

    </div>
</template>


CSS:

.login-wrapper {
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
    padding: 1rem 0;
}

.input-box {
    display: flex;
    align-items: center;
    height: 60px;
    border: 1px solid #c9c9c9;
    border-radius: 4px;
    background: #ffffff;
    margin-bottom: 22px;
    padding: 0 16px;
    box-sizing: border-box;
}

.input-icon {
    margin-right: 12px;
    --sds-c-icon-color-foreground-default: #000000;
    flex-shrink: 0;
}

.custom-input {
    border: none;
    outline: none;
    width: 100%;
    font-size: 1.1rem;
    color: #8b8b8b;
    background: transparent;
}

.custom-input::placeholder {
    color: #8b8b8b;
    opacity: 1;
}

.login-btn {
    width: 100%;
    height: 58px;
    border: none;
    border-radius: 4px;
    background: #002f5f;
    color: #ffffff;
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
}

.login-btn:hover {
    background: #002a54;
}

.login-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.error-message {
    margin-top: -8px;
    margin-bottom: 16px;
    color: #c23934;
    font-size: 0.95rem;
}

.error-message-top {
    margin-bottom: 16px;
    padding: 10px;
    background: #fdecea;
    border: 1px solid #f5c6cb;
    color: #c23934;
    border-radius: 4px;
}


Important Operator

Posted on TimeMarch 6, 2026

 Nullish coalescing operator


-> The nullish coalescing (??) operator is a logical operator that returns its right-hand side operand when its left-hand side 

operand is null or undefined, and otherwise returns its left-hand side operand.

## Syntaxt: leftExpr ?? rightExpr


Documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing#assigning_a_default_value_to_a_variable



###Nullish coalescing assignment (??=)


-> The nullish coalescing assignment (??=) operator, also known as the logical nullish assignment operator, 

only evaluates the right operand and assigns to the left if the left operand is nullish (null or undefined).


## Syntaxt: x ??= y


-> Exmaple: 


const a = { duration: 50 };


a.duration ??= 10;

console.log(a.duration);

// Expected output: 50


a.speed ??= 25;

console.log(a.speed);

// Expected output: 25


Documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_assignment


Optional chaining (.)

-> The optional chaining (?.) operator accesses an object's property or calls a function. If the object accessed or function called using this operator 

is undefined or null, the expression short circuits and evaluates to undefined instead of throwing an error.


### Syntax: 


obj.val?.prop

obj.val?.[expr]

obj.func?.(args)



Example:


const adventurer = {

  name: 'Alice',

  cat: {

    name: 'Dinah',

  },

};


const dogName = adventurer.dog?.name;

console.log(dogName);

// Expected output: undefined


console.log(adventurer.someNonExistentMethod?.());

// Expected output: undefined



### Description: The ?. operator is like the . chaining operator, except that instead of causing an error if a reference is nullish (null or undefined), 

the expression short-circuits with a return value of undefined. When used with function calls, it returns undefined if the given function does not exist.


###

By using the ?. operator instead of just ., JavaScript knows to implicitly check to be sure obj.first is not null or undefined 

before attempting to access obj.first.second. If obj.first is null or undefined, the expression automatically short-circuits, returning undefined.

const nestedProp = obj.first?.second;


Documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining



Ternary Operator 

###Syntax:    condition ? exprIfTrue : exprIfFalse


###Description: Besides false, possible falsy expressions are: null, NaN, 0, the empty string (""), and undefined. 

If condition is any of these, the result of the conditional expression will be the result of executing the expression exprIfFalse.


### Conditional chains: 


The ternary operator is right-associative, which means it can be "chained" in the following way, 

similar to an if … else if … else if … else chain:


function example() {

  return condition1 ? value1

    : condition2 ? value2

    : condition3 ? value3

    : value4;

}


Documentations: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_operator


GitHub learning

 1. The local and remote repositories only interact when you run one of the four network commands in Git: git clone, git fetch, git pull, and git push.

2. You can't create commits without these settings, so set them yourself using your command line application:


   git config --global user.name "First Last"

   and then enter,

   git config --global user.email "you@email.com"

   

  Note: You won't see any confirmation that this worked, but as long as you don't see an error, you're set!



3. Configure autocrlf

   Next, we set core.autocrlf (autocrlf stands for auto carriage return line feed). Different systems handle line endings and line breaks differently. If you open a file created on another operating system and do not have this config option set, Git will think you made changes to the file based on the way your operating system handles the line endings.


   For Windows users enter:


   git config --global core.autocrlf true


4. git checkout myfeaturebranch for swith into myfeaturebranch.

5. Let’s take another look at our repository status: git status.



IMPORTANT =>


1. first checkout (switch branch) 2. git pull (for retrive) 3. git merge origin/RBKQA (for merge all files in current branch) 4. make changes

5. staged your changes 6. commit & push. 


Done! 


Additional - 


git reset --merge => Abort the merge and return to the previous state.


Note: 


1. Sometime if you are not using correct feature branch then it will give you error. for merging 

Test Class | Test Apex Related Interview Questions


Why we test-> To save time, to become better at our craft, and to build better software.


Why we create test data-> Naturally, the data in your production org changes over time and will be different from the data in your developer environment. 

When your tests run, either in a developer environment or in production, they have access only to the data in that org. 

So if you write tests using existing data, you can end up with deployment problems, because the data available in one environment isn’t always available in another environment.


->  Test.startTest() and Test.stopTest() => Any code between those two calls executes with a refreshed set of governor limits.


Create data-> 3 methods-> TestFactory class, @TestSetup & csv file.


Apex is by default with sharing or without sharing?

 By default, Apex classes are without sharing, meaning they run in "system context" and ignore the current user’s record-level sharing rules, permissions, and field-level security. They have full access to all data, although they still respect organization-wide defaults.


Key Details regarding Default Behavior:


  • Without Sharing (Default): If neither with sharing nor without sharing is declared, the class runs in system mode, ignoring user sharing rules.
  • Inheritance: If an undeclared class is called by a with sharing class, it inherits that strict context.
  • Triggers: Triggers are also without sharing by default, running in system context.
  • Security Risk: Because the default is insecure, it is highly recommended to explicitly declare with sharing to enforce security rules.
  • AuraEnabled: @AuraEnabled classes can sometimes behave differently, but generally, they follow the same rules, necessitating explicit declaration.