1
我試圖通過頂點創建任務。測試工作說它是成功的。但是,當我從Task中導出數據時,沒有其他行。我無法判斷調試日誌中是否有任何錯誤。任務上沒有自定義驗證規則。請幫助並提供一種方法來解決SalesForce環境中的這種情況。Apex創建任務說成功,但數據庫沒有新記錄
下面是測試代碼:
@isTest(SeeAllData=true) class HelloWorldTestClass {
static testMethod void validateHelloWorld() {
Task newTask = new Task(Description = 'test task',
Priority = 'Normal',
Status = 'Not Started',
Subject = 'Other',
WhoId = '003P000000dnR35IAE',
WhatId = '001P000000Zc5G6',
Type = 'Internal Action',
ActivityDate = system.today());
insert newTask;
}
}
這裏的調試日誌:
26.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
13:24:30.080 (80288000)|EXECUTION_STARTED
13:24:30.080 (80360000)|CODE_UNIT_STARTED|[EXTERNAL]|01pP00000000ziy|HelloWorldTestClass.validateHelloWorld
13:24:30.080 (80837000)|METHOD_ENTRY|[2]|01pP00000000ziy|HelloWorldTestClass.HelloWorldTestClass()
13:24:30.080 (80852000)|METHOD_EXIT|[2]|HelloWorldTestClass
13:24:30.102 (102146000)|SYSTEM_METHOD_ENTRY|[15]|System.today()
13:24:30.102 (102204000)|SYSTEM_METHOD_EXIT|[15]|System.today()
13:24:30.102 (102294000)|DML_BEGIN|[23]|Op:Insert|Type:Task|Rows:1
13:24:30.115 (115312000)|ENTERING_MANAGED_PKG|APXTConga4
13:24:30.215 (215194000)|DML_END|[23]
13:24:30.267 (215259000)|CUMULATIVE_LIMIT_USAGE
13:24:30.267|LIMIT_USAGE_FOR_NS|(default)|
Number of SOQL queries: 0 out of 100
Number of query rows: 0 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 1 out of 150
Number of DML rows: 1 out of 10000
Number of code statements: 2 out of 200000
Maximum heap size: 0 out of 6000000
Number of callouts: 0 out of 10
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 100
Number of record type describes: 0 out of 100
Number of child relationships describes: 0 out of 100
Number of picklist describes: 0 out of 100
Number of future calls: 0 out of 10
13:24:30.267|LIMIT_USAGE_FOR_NS|APXTConga4|
Number of SOQL queries: 0 out of 100
Number of query rows: 0 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 0 out of 150
Number of DML rows: 0 out of 10000
Number of code statements: 2 out of 200000
Maximum heap size: 0 out of 6000000
Number of callouts: 0 out of 10
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 100
Number of record type describes: 0 out of 100
Number of child relationships describes: 0 out of 100
Number of picklist describes: 0 out of 100
Number of future calls: 0 out of 10
13:24:30.267|CUMULATIVE_LIMIT_USAGE_END
13:24:30.215 (215338000)|CODE_UNIT_FINISHED|HelloWorldTestClass.validateHelloWorld
13:24:30.215 (215346000)|EXECUTION_FINISHED
我在課堂開始處有@isTest(SeeAllData = true)。它應該允許測試方法訪問數據庫。我也在真正的非測試課上嘗試過這樣的方法,但這不行。這個問題似乎與測試無關。 但是,還是非常感謝回覆。 – user2030526
SeeAllData讓測試訪問現有數據,它沒有說明測試中所做的更改是否會被提交。 – superfell
@isTest(SeeAllData = true)是一個糟糕的做法,因爲它會在您的組織中查找記錄並提取它們,這可能會達到管理員限制,並且如果類被遷移並且記錄不存在,那麼測試將失敗。 – peevesy