[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.

ビオレ UV アクアリッチ ウォータリーホールドクリーム(50.0g)【ビオレシーズン】
価格:1,430円(税込、送料無料) (2025/4/21時点) 楽天で購入

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

테스트 클래스 실행 시 “Failed to run tests synchronously.: Your query request was running for too long.” 오류 대응

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] SOQL 문의 HAVING 사용법

SOQL 문의 HAVING

HAVING에서는 GROUP BY로 그룹화한 결과에 대해 좁혀 조건을 넣을 수 있습니다.

좁힌 조건이라는 의미에서는 WHERE와 비슷하지만, WHERE에서는 그룹핑하기 전, HAVING은 그룹핑한 후입니다.

다음 샘플은 기회의 리드 소스로 그룹화하고 동일한 값의 레코드 수가 1 이상인 리드 소스별 금액을 표시합니다.

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'));
}

디버그 결과

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

USBハブ 3.0 4ポート USB3.0 USBポート 増設 HUB おすすめ 固定 簡単接続 機能安定 5Gbps 高速データ スマホ充電 コンパクト 軽量 画像転送
価格:1,000円(税込、送料無料) (2025/4/18時点) 楽天で購入

[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]SOQL文のHAVINGの使い方

SOQL文のHAVING

HAVINGではGROUP BYでグルーピングした結果に対して、絞込みの条件を入れることが出来ます。

絞込み条件という意味ではWHEREと似ていますが、WHEREではグルーピングする前、HAVINGはグルーピングした後です。

次のサンプルは商談のリードソースでグルーピングし、同じ値のレコード数が1以上のリードソース別金額を表示します。

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'));
}

デバッグの結果

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

[Salesforce]JSENCODE

JSENCODE

백슬래시 () 등의 이스케이프 문자를 아포스트로피 (‘) 등의 안전하지 않은 JavaScript 문자의 전에 삽입해, JavaScript 로 사용하는 텍스트 캐릭터 라인이나 편지 병합 항목치를 encode 합니다.

페이지를 로드할 때 JavaScript가 실행되고 경고가 표시됩니다.

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

이 경우 JavaScript가 실행되지 않도록 JSENCODE 함수를 사용하십시오.

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

[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] Visualforce에서 outputLink 누를 때 새 탭에서 표시

Visualforce에서 outputLink를 누르면 새 탭으로 표시

<apex:outputLink value="{!URLFOR('/' + targetObject.Id)}" target="_blank" id="TargetObjectId">{!targetObject.Name}</apex:outputLink>