What happens when the user is inactivated or deactivated in Salesforce?

You can’t delete a user, but you can deactivate an account so a user can no longer log in to Salesforce.

If an user is inactivated,

1. He will not be able to login.
2. Report will not run, if he/she is set as running user.
3. Web to lead and web to case will not work, if he is set as the default creator.
4. User license of the inactivates user will be free for other user.
5. Deactivated users lose access to any records that were manually shared with them, or records that were shared with them as team members. Users higher in the role hierarchy relative to the deactivated users also lose access to those records.
6. Deactivated users are removed from the default opportunity and account teams of other users. The deactivated users' default opportunity and account teams are not removed.
7. If a user on an account team has Read/Write access (Account Access, Contact Access, Opportunity Access, and Case Access) and is deactivated, the access will default to Read Only if the user is reactivated.
8. If you deactivate users in an organization where opportunity splitting is enabled, they aren’t removed from any opportunity teams where they’re assigned a split percentage.

This is mainly done, when the user leaves the organization.

Salesforce help article - https://help.salesforce.com/articleView?id=users_deactivate_considerations.htm&type=5

Accounts records deletion consideration in Salesforce

1. You cannot delete Accounts if it has cases related to it.

2. If you delete the Account, it's related Assets will also gets deleted.

3. Deletes related Contacts.

4. You cannot delete Accounts if it has closed won opportunities related to it. If all the opportunities related to it are open, then the account can be deleted.

5. It deletes Contracts (if they're not activated).

6. You cannot delete an account which has related Service Contracts.

NOTE:
You don’t need the Delete permission on any associated records that are included in the deletion.

How to test Batch Apex result in Test class in Salesforce?

The call to Database.executeBatch should be included within the Test.startTest and Test.stopTest block. The job executes after the call to Test.stopTest. Any asynchronous code included within Test.startTest and Test.stopTest is executed synchronously after Test.stopTest.

Sample Batch Apex:


  1. global class AccountBatch Implements Database.Batchable <sObject> {  
  2.   
  3.     global Database.queryLocator start( Database.BatchableContext bc ) {  
  4.       
  5.         String SOQL = 'SELECT Id, Industry FROM Account';  
  6.         return Database.getQueryLocator(SOQL);  
  7.           
  8.     }  
  9.   
  10.     global void execute( Database.BatchableContext bc, List < Account > listAccounts ) {  
  11.       
  12.         for ( Account objAct : listAccounts ) {  
  13.           
  14.             objAct.Industry = 'Energy';  
  15.               
  16.         }  
  17.       
  18.         update listAccounts;  
  19.           
  20.     }  
  21.   
  22.     global void finish( Database.BatchableContext bc ) {  
  23.       
  24.         AsyncApexJob a = [ SELECT Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CreatedById    
  25.                              FROM AsyncApexJob    
  26.                             WHERE Id =: bc.getJobId() ];    
  27.         Messaging.SingleEmailMessage batchEmail = new Messaging.SingleEmailMessage();    
  28.         batchEmail.setTargetObjectId( a.CreatedById );    
  29.         batchEmail.setSubject( 'Asset Delete Batch ' + a.Status );    
  30.         batchEmail.setPlainTextBody( 'Jobs processed ' + a.JobItemsProcessed + ' with '+ a.NumberOfErrors + ' failures.' );    
  31.         batchEmail.setSaveAsActivity( false );    
  32.         Messaging.sendEmail( new Messaging.SingleEmailMessage[] { batchEmail } );   
  33.           
  34.     }  
  35.   
  36. }  

Sample Test class:


  1. @isTest  
  2. private class AssetDeleteBatchTest {  
  3.       
  4.     static testMethod void testAssetsDel() {  
  5.           
  6.         List < Account > insertAcc = new List< Account >();  
  7.         for ( Integer a = 0; a < 3; a++ ) {  
  8.           
  9.             Account acc = new Account( Name = 'Test Account' + String.valueOf( a ), Industry = 'Biotechnology' );  
  10.             insertAcc.add( acc );  
  11.                   
  12.         }  
  13.         insert insertAcc;  
  14.           
  15.         Test.startTest();  
  16.         AccountBatch obj = new AccountBatch();  
  17.         Database.executeBatch( obj );  
  18.         Test.stopTest();  
  19.           
  20.         /* 
  21.             Once Test.stopTest() hits, the batch job runs synchronously. 
  22.             Once the batch job execute method is completed, the below codes are executed. 
  23.         */  
  24.         List < Account > listAccounts = [ SELECT Id FROM Account WHERE Industry = 'Energy' ];  
  25.         system.assertEquals( 3, listAccounts.size() );  
  26.           
  27.     }  
  28.       
  29. }  


Download SQL Server Management Studio (SSMS)

To download Download SQL Server Management Studio (SSMS), check the below link

https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms

Note:
Download the current General Availability (GA) version of SSMS.


@isTest(isParallel=true) annotation in Salesforce

Use the @isTest(isParallel=true) annotation to indicate test classes that can run in parallel and aren’t restricted by the default limits on the number of concurrent tests. This makes the execution of test classes more efficient, because more tests can be run in parallel.

This annotation overrides the default settings that disable parallel testing. A test class that doesn’t have this annotation is restricted by the default limits on the number of concurrent tests.

Tests that are started from the Salesforce user interface (including the Developer Console) run in parallel. Parallel test execution can speed up test run time. Sometimes, parallel test execution results in data contention issues, and you can turn off parallel execution in those cases. In particular, data contention issues and UNABLE_TO_LOCK_ROW errors might occur in the following cases:

1. When tests update the same records at the same time. Updating the same records typically occurs when tests don’t create their own data and turn off data isolation to access the organization’s data.

2. When a deadlock occurs in tests that are running in parallel and that try to create records with duplicate index field values. A deadlock occurs when two running tests are waiting for each other to roll back data, which happens if two tests insert records with the same unique index field values in different orders.

You can prevent receiving those errors by turning off parallel test execution in the Salesforce user interface - http://www.infallibletechie.com/2018/08/how-to-disable-parallel-apex-testing-in.html

Syntax:


How to show different colors for buttons in lighting datatable in Salesforce?

Sample Code:

Component:


  1. <aura:component implements = "force:appHostable"    
  2.                 controller = "AccountListController">    
  3.         
  4.     <aura:attribute type = "object[]" name = "acctList"/>    
  5.     <aura:attribute name = "mycolumns" type = "List"/>    
  6.         
  7.     <aura:handler name = "init" value="{!this}" action="{!c.onInit}"/>    
  8.         
  9.     <lightning:datatable aura:id = "acctTable"  
  10.                          data = "{! v.acctList }"     
  11.                          columns = "{! v.mycolumns }"     
  12.                          keyField = "Id"    
  13.                          hideCheckboxColumn = "true"  
  14.                          onrowaction = "{! c.viewRecord }"/>    
  15.         
  16. </aura:component>  

Controller:

  1. ({    
  2.       
  3.     onInit : function( component, event, helper ) {    
  4.           
  5.         component.set( 'v.mycolumns', [    
  6.             {label: 'Account Name', fieldName: 'Name', type: 'text', editable:'true'},    
  7.             {label: 'Industry', fieldName: 'Industry', type: 'text'},                  
  8.             {label: 'Type', fieldName: 'Type', type: 'Text'},  
  9.             {type: "button", typeAttributes: {  
  10.                 label: 'View',  
  11.                 name: 'View',  
  12.                 title: 'View',  
  13.                 disabled: false,  
  14.                 value: 'view',  
  15.                 iconPosition: 'left',  
  16.                 variant: { fieldName: 'buttonColor'}  
  17.             }}   
  18.         ]);    
  19.         helper.fetchAccounts( component );  
  20.           
  21.     },  
  22.       
  23.     viewRecord : function( component, event, helper ) {  
  24.           
  25.         var recId = event.getParam( 'row' ).Id;  
  26.         var actionName = event.getParam( 'action' ).name;  
  27.         var viewRecordEvent = $A.get( "e.force:navigateToURL" );  
  28.         viewRecordEvent.setParams({  
  29.             "url""/" + recId  
  30.         });  
  31.         viewRecordEvent.fire();  
  32.           
  33.     }  
  34.       
  35. })  

Helper:

  1. ({  
  2.       
  3.     fetchAccounts : function( component ) {  
  4.           
  5.         var action = component.get( "c.fetchAccts" );  
  6.         action.setCallback(this, function( response ) {    
  7.               
  8.             var state = response.getState();   
  9.             if ( state === "SUCCESS" )   {  
  10.                   
  11.                 var records = response.getReturnValue();  
  12.                 for ( var i = 0; i < records.length; i++ ) {  
  13.                       
  14.                     if ( records[ i ].Industry === "Energy" )  
  15.                         records[ i ].buttonColor = 'white';  
  16.                     else if ( records[ i ].Industry === "Electronics" )  
  17.                         records[ i ].buttonColor = 'brand';  
  18.                     else if ( records[ i ].Industry === "Biotechnology" )  
  19.                         records[ i ].buttonColor = 'destructive';  
  20.                     else if ( records[ i ].Industry === "Construction" )  
  21.                         records[ i ].buttonColor = 'success';  
  22.                     else   
  23.                         records[ i ].buttonColor = 'neutral';  
  24.                       
  25.                 }  
  26.                 component.set( "v.acctList", records );     
  27.                   
  28.             }  
  29.               
  30.         });    
  31.         $A.enqueueAction(action);   
  32.           
  33.     }  
  34.       
  35. })  

Apex Class:

  1. public class AccountListController {    
  2.         
  3.     @AuraEnabled    
  4.     public static List < Account > fetchAccts() {    
  5.             
  6.         return [ SELECT Id, Name, Industry, Type, CreatedDate FROM Account LIMIT 100 ];    
  7.             
  8.     }      
  9.         
  10. }  

Output: