Loading
メール配信ドメイン検証状況の確認方法のご案内続きを読む
ただいま大変多くのお問い合わせをいただいており、ご連絡までにお時間を頂戴しております続きを読む
Salesforce 組織の設定および管理
目次
絞り込み条件を選択

          結果がありません
          結果がありません
          検索のヒントをいくつかご紹介します

          キーワードの入力ミスがないか確認する。
          より一般的な検索語を使用する。
          絞り込み条件を減らして、検索範囲を広げる。

          Salesforce ヘルプ全体を検索
          アーカイブ Apex テスト

          アーカイブ Apex テスト

          本番環境で作業する前に、Archive Apex in the Archive アプリケーションの Apex クラス・ラッパーでテストを実行します。

          MockHttpResponseGenerator.cls

          次のコードは、コールアウトの疑似を示しています。MockHttpResponseGenerator クラスは、HttpCalloutMock Apex インタフェースを実装します。

          @isTest
          global class MockHttpResponseGenerator implements HttpCalloutMock {
          public String fakeResponseJson;
          public integer statusCode;
          String redirectHeader;
          
          public MockHttpResponseGenerator(String fakeResponseJson,Integer statusCode){
          this.statusCode = statusCode;
          this.fakeResponseJson = fakeResponseJson;
          this.redirectHeader = '/example/test';
          
          }
          
          public HTTPResponse respond(HTTPRequest req) {
          HTTPResponse res = new HTTPResponse();
          res.setBody(this.fakeResponseJson);
          res.setStatusCode(this.statusCode);
          res.setHeader('Location',  this.redirectHeader);
          return res;
          }
          }

          SearchSdkTest.cls

          このコードは、MockHttpResponseGenerator クラスを使用して疑似 HTTP を設定することで、SF_Archive.ArchiverAccessorのグローバル検索機能をテストします。このテストでは、検索操作で期待される JSON データと状況コードが返されることを確認します。

          @isTest
          public with sharing class searchSdkTest {
          
          @isTest
          private static void searchSdk() {
          // Define a JSON string to be used as the mock response body
          String jsonBody = '{"records": [{"CaseNumber":"01916767", "Id":"500Xx000000XXXXXX"}], "total_result_count": 1, "scroll_id":"-1" }';
          
          // Set up the mock HTTP response using the predefined JSON body and HTTP 200 status code
          SF_Archive.ArchiverAccessor.setMock((HttpCalloutMock) new MockHttpResponseGenerator(jsonBody, SF_Archive.ArchiverAccessorResponse.HTTP_200_OK));
          
          // Insert a test archive configuration
          insert createTestArchiveConfiguration();
          
          // Create a list to hold search filters
          list<SF_Archive.SearchFilter> request1 = new list<SF_Archive.SearchFilter>();
          
          // Create a new search filter with the name 'test' and add it to the list
          SF_Archive.SearchFilter filter1 = new SF_Archive.SearchFilter('Name', 'test');
          request1.add(filter1);
          
          // Start the test context
          Test.startTest();
          
          // Perform a global search using the archiver accessor and capture the response
          SF_Archive.ArchiverAccessorResponse res = SF_Archive.ArchiverAccessor.performArchiverGlobalSearch('Account', request1);
          
          // Stop the test context
          Test.stopTest();
          
          // Assert that the response status code is HTTP 200 OK
          system.assertEquals(SF_Archive.ArchiverAccessorResponse.HTTP_200_OK, res.getStatusCode());
          
          // Assert that the response body matches the predefined JSON body
          system.assertEquals(res.getBody(), jsonBody);
          }
          
          private static SF_Archive_Configuration__c createTestArchiveConfiguration(){
          return createTestArchiveConfiguration('https://example');
          }
          public static SF_Archive_Configuration__c createTestArchiveConfiguration(String url){
          SF_Archive_Configuration__c ac = new SF_Archive_Configuration__c();
          ac.Name = 'SF_URL';
          ac.SF_URL__c = url;
          ac.SF_API_Name__c='SF_URL';
          return ac;
          }
          }
           
          読み込み中
          Salesforce Help | Article