0
我有一個簡單的觸發器,當我的自定義對象上的SD_Action__c字段爲特定值時,該觸發器應該創建新機會。代碼沒有錯誤,但是當我嘗試更新沙箱或生產中的字段時沒有任何反應。我錯過了什麼讓m.SD_Action__c=='Generate Opportunity'
這個偉大的機會?Salesforce Apex在自定義對象字段更改後創建商機
trigger MDwinning on MD_Meeting__c (after update) {
List <Opportunity> oppToInsert = new List <Opportunity>();
for (MD_Meeting__c m : Trigger.new) {
if (m.SD_Action__c == 'Generate Opportunity') {
Opportunity o = new Opportunity();
// o.Owner = m.Sales_Director__c,
o.Market_Developer__c = m.Market_Developer__c;
//o.Account = m.Account__c;
oppToInsert.add(o);
}//end if
}//end for o
try {
insert oppToInsert;
} catch (system.Dmlexception e) {
system.debug (e);
}
}
這裏是我的測試類:
@isTest (SeeAllData = true)
public with sharing class MDwinningTest {
static testMethod void MDwinningTest() {
MD_Meeting__c m = new MD_Meeting__c(
Account__c = 'test Account',
Desired_Meeting__c = 'Call',
Name = 'Meeting name',
Sales_Director__c = 'SD Name',
Market_Developer__c = 'MD Name',
Meeting_Date__c = Date.today(),
Contact__c = 'Test Contact',
Title__c = 'Boss',
Functional_Role__c = 'eCommerce - VP',
Contact_Email__c = '[email protected]',
SD_Action__c = 'Generate Opportunity',
Primary_URL__c = 'http://www.google.com/'
);
insert m;
}
}