[Salesforce]Failed to run tests synchronously.: Your query request was running for too long.

Handling the error “Failed to run tests synchronously.: Your query request was running for too long.” when running a test class

Summary
Test classes failing with QUERY_TIMEOUT Failed to run tests synchronously when running in synchronous mode

Login to the org which has quite number of managed package apex classes.
Run the Apex Test Class from Developer Console in Sync Mode
You may notice below exception when running the apex test class:
Error Message:

“QUERY_TIMEOUT Failed to run tests synchronously: Your query request was running for too long”

Workaround
As a workaround, please try to run the test class in asynchronous mode.

[Salesforce] How to use HAVING in SOQL statements

SOQL statement HAVING

HAVING allows you to enter filtering conditions for the results grouped by GROUP BY.

It is similar to WHERE in that it is a filtering condition, but WHERE is before grouping and HAVING is after grouping.

The following sample groups by the lead source of the opportunity and displays the amount by lead source where the number of records with the same value is 1 or more.

AggregateResult[] results = [SELECT LeadSource, SUM(Amount) summary 
                               FROM Opportunity 
                               GROUP BY LeadSource 
                               HAVING Count(LeadSource) > 1];
for(AggregateResult ar: results){
  System.debug('LeadSource='+ ar.get('LeadSource') 
                   + ':Amount='+ ar.get('summary'));
}

Debugging Results

LeadSource=LeadSource1:Amount=2
LeadSource=LeadSource2:Amount=3

[Salesforce]JSENCODE

JSENCODE

Encode text strings and merge field values ​​for use in JavaScript by inserting an escape character, such as a backslash (), before unsafe JavaScript characters, such as an apostrophe (‘).

The JavaScript runs when the page loads and displays the alert.

<script>var ret = "foo";alert('xss');//";</script>

In this case, use the JSENCODE function to prevent JavaScript from being executed. Example

<script>var ret = "{!JSENCODE($CurrentPage.parameters.retURL)}";</script>

[Salesforce]CANNOT_EXECUTE_FLOW_TRIGGER

CANNOT_EXECUTE_FLOW_TRIGGER

Error details when executing test class

System.DmlException: Insert failed. First exception on row 0; first error:
CANNOT_EXECUTE_FLOW_TRIGGER,
This record cannot be saved due to a failure in the "Campaign Create, Member Status Auto Set" process.
Please report the following details to your Salesforce system administrator:
Salesforce has no records that match the deletion criteria.
Salesforce has no records that match the deletion criteria. : []

One of the solutions is as follows:

@isTest(SeeAllData=true)
※May be effective in some cases.