Skip to main content

#Trailhead Challenges1,679 人がディスカッション中

Hands-on challenges are the “secret sauce” of Trailhead. Before searching for solutions to superbadge challenges, review the Salesforce Certification Program Agreement and Policies. ** NOTE ** : If you were able to get a response that solved your issue, please mark it as the 'Best Answer' to help other Trailblazers. If the issue persists after 48 hours, create a Trailhead Help case at https://help.salesforce.com/s/support for further assistance.
Hiroyuki Tokiya が「#Trailhead」で質問

Trailheadの「Apex と .NET の基本 > 実行コンテキストの理解」のChallengeに挑戦していたのですが、チェック時に『「AccountTrigger」トリガは正しく機能していません。トリガによって BillingState と ShippingState の値が一致する Account レコードが挿入されることを確認してください。』といったメッセージで合格になりません。 

※テストクラスは成功しています。 

 

このChallengeで [ Setting ] > [ State and Country/Territory Picklists ] は有効にする必要がある?と思われ有効化しています。 

AIに聞いたりネットで調べたりしましたが、BillingStateやShippingStateで 国 / 州コード (2文字) が使えなかったりで、全然上手くいかず恥ずかしながら1日を費やしてしまいました。。。 

 

自分が作成したApexクラス等は以下になります。 

もうこの単元は諦めようと思っていますが、何かご助言いただけますと幸いです。 

 

▼テストクラス

public withBillingState sharing class AccountTriggerHandler {

public static void CreateAccounts(List<Account> accts) {

for (Account a : accts) {

a.ShippingState = a.BillingState;

}

}

}

▼トリガー

trigger AccountTrigger on Account (before insert) {

if (Trigger.isBefore && Trigger.isInsert) {

AccountTriggerHandler.CreateAccounts(Trigger.New);

}

}

▼テストクラス

@isTest

public class AccountTriggerTest {

@isTest static void TestCreateNewAccountInBulk() {

List<Account> accts = new List<Account>();

for(Integer i = 0; i < 200; i++) {

Account acct = new Account(Name = 'Test Account ' + i);

acct.BillingCountry = 'United States'; // USだと不可のため

acct.BillingState = 'California'; // CAだと不可のため

accts.add(acct);

}

Test.startTest();

insert accts;

Test.stopTest();

List<Account> verifyAccts = [

SELECT BillingState,ShippingState FROM Account WHERE Id IN :accts

];

for (Account ac : verifyAccts){

System.assertEquals('California', ac.ShippingState);

}

}

}

#Trailhead  #Trailhead Challenges

4 件の回答
  1. 2月25日 21:19

    @Hiroyuki Tokiya さん 

     

    使いいているプレイグランドで他のモジュールも実施していませんか? 

    「はい」であれば、おそらく以前のチャレンジで設定したものが、このトリガーの動きを妨げていると思います。 

     

    一番簡単なのは、新しいプレイグランドで試すことだと思います。 

0/9000