Posts

How to show details on selecting checkbox in LWC

Image
....HTML.... < template >     < lightning-card title = "Apply for leave" icon-name = "custom:custom14" >     < div class = "slds-m-around_medium" >         < lightning-input type = "checkbox" label = "Multiple day" onchange = {handleChange1} >         </ lightning-input >         < template if:true = {areDetailsVisible1} >     < div class = "slds-text-heading_small slds-m-bottom_medium" >         < lightning-input type = "date"   label = "Start date" name = "startDate" >         </ lightning-input >         < lightning-input type = "date" label = "End date" name = "emailAddress" >         </ lightning-input >     </ div >         </ template >     </ div >     < div ...

Create new opportunity and display in the list.

    component     <aura:component controller="saveRecordClass">       <aura:attribute name="homePage"  type="String"/>     <aura:attribute name="accountsData" type="Opportunity[]"/>     <aura:attribute name="newRec" type="boolean" default="false"/>      <aura:attribute name="showList" type="boolean" default="true"/>     <aura:attribute name="data" type="Object"/>     <aura:attribute name="columns" type="List"/>     <aura:attribute name="recordId" type="String"/>     <aura:attribute name="updatedRecord" type="Object[]" />       <aura:handler name="init" value="{!this }" action="{!c.doInit }"/>      <aura:if isTrue="{!v.showList}">         <lightning:card>             <aura:set attribute=...

Dependent picklist in Aura

Image
 ....Component.... <aura:component controller="MinorAssignment" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >     <aura:attribute name="fName" type="string"/>     <aura:attribute name="lName" type="string"/>     <aura:attribute name="email" type="string"/>     <aura:attribute name="phn" type="string"/>     <aura:attribute name="selectedBusinessVertical" type="String"/>     <aura:attribute name="selectedDivisionVertical" type="String"/>     <aura:attribute name="selectedAreaOfDivision" type="String"/>     <aura:attribute name="availableDivisionOfVertical" type="List"/>     <aura:attribute na...

Write a trigger to count number of contacts associated with an account with it's test class.

Whenever new contact is created for an Account update the field Number of contacts(a custom field of type Integer/Number)with the number of contacts. It should also update the count when contact is deleted /removed from Account. The respective count would be increased/Decreased accordingly. ....Trigger.... trigger CountContacts on Contact (after insert, after update, after delete) { list<contact> conList = new list<contact>(); list<account> accList = new list<account>(); set<ID> accIDs = new set<ID>(); if(trigger.isInsert || trigger.isUpdate) { for(contact con : trigger.new) { if(String.isNotBlank(con.accountId)) { accIds.add(con.accountId); } } } if(trigger.isDelete) { for(contact con : trigger.old) { accIDs.add(con.AccountId); } } if(accIDs.size()>0) { conList = [select name, id, acc...

Write a trigger and it's Test class on Account when Account is update check all opportunity inside the account.

Update all Opportunities Stage to close lost if an opportunity created date is greater than 30 days from today and stage not equal to close won. ....Trigger.... trigger UpdateOpportunities on Account (after update) { Set<Id> accountIds = new Set<Id>(); for(Account a:Trigger.new){ accountIds.add(a.Id); } DateTime day30=system.now()-30; List<Opportunity> oppListToUpdate=new List<Opportunity>(); List<Opportunity> oppList = [Select Id, AccountId, StageName, CreatedDate, CloseDate from Opportunity where AccountId in :accountIds]; if(oppList.size()>0) { for(Opportunity opp : oppList) { if(opp.CreatedDate < day30 && opp.StageName!='Closed Won') { opp.CloseDate = system.today(); opp.StageName = 'Closed Lost'; oppListToUpdate.add(opp); update opp; } } }...

Write a trigger with its test class for only system admin user should be able to delete the task.

....Trigger.... trigger DeleteCheck on Task (before delete) { Id profileid=Userinfo.getProfileId(); profile profilname=[select Name from Profile where id=:profileid]; for(Task accountDuplicate:Trigger.old) { if(profilname.Name!='System Administrator') { accountDuplicate.addError('No Access for Deletion'); } } } . ...Test Class.... @istest public class DeleteCheckTest  {     @istest     static  void TestAccountTrigger(){         Task Tcc = new Task();         Tcc.Subject =  'Email';         Tcc.Priority =  'Low';         Tcc.Status = 'in progress';         insert Tcc;                  Id profileid=Userinfo.getProfileId();         profile profilname=[select Name from Profile where id=:pro...

Populate Description field with the user first name who creates or updates the record by using userInfo standard keyword , and also does not allow user to delete the record. Write it's Test class also.

Example : If user is Test User "Author Last updated by user firstName (use userInfo to fetch firstname)" ....TRIGGER.... trigger PopulateDescription on Account (before insert, before update, before delete){ If(trigger.isInsert) { for(Account Acc: Trigger.new){ Acc.Description = 'Account Created by '+ userInfo.getFirstName(); } } else If(trigger.isUpdate) { for(Account Acc: Trigger.new){ Acc.Description = 'Account Last updated by '+ userInfo.getFirstName(); } } if(Trigger.isDelete&&Trigger.isbefore){ for(Account Rec:trigger.old) { Rec.adderror('You Cannot Delete the Account Record'); } } } ....Test Class.... public class PopulateDescriptionTest { @isTest public static void populatedescription(){ Account acc = new Account(); acc.Name = 'Test'; ...