English 中文(简体)
ELFAFE APEX - 相关物体的试验上下文返回无效
原标题:Salesforce APEX - Test context returning null for related objects

当写入测试时, 方法我无法获取相关的联系人字段。 在下面的例子中, 我期望最终的主张会恢复为真实 。 我测试的代码效果很好, 选择只有在测试时才会失败 。

SOQL 查询中为何不返回联系人信息?

static testMethod void FailTest()
{
        Contact client = new Contact(FirstName= TestFirst1 , LastName= TestFirst , BirthDate = Date.parse( 01/01/1986 ), Gender__c =  Male );
        insert client;
        Opportunity opp = new Opportunity(Name =  Test Opp  + Math.random(), CloseDate=Date.Today(), StageName= ASR - Case Design , Product_Types__c= UL , Face_Amount_Applied_For__c=500, Estimated_Target_Premium__c=1000, X1st_Client__r = client);
        insert opp;

        Opportunity selectOpp = [Select o.X1st_Client__r.LastName From Opportunity o WHERE o.Id = :opp.Id LIMIT 1];

        system.assertNotEquals(opp.X1st_Client__r.LastName, null); //true
        system.assertNotEquals(opp.Name, null); //true
        system.assertNotEquals(selectOpp.Name, null); //true
        system.assertNotEquals(selectOpp.X1st_Client__r.LastName, null); //false, should be true
}
最佳回答

我认为问题可能是您将机会与客户记录联系起来的方式。 您有 X1st_ Client__r = 客户, 我认为您可能真正想要做的是 X1st_ Client__c = 客户端. ID。 我认为插入 DML 时不会考虑 X1st_ Client__r 所代表的对象 。 我认为插入时只注意 X1st_ Client__c 值 。

问题回答

暂无回答




相关问题
run unit tests and coverage in certain python structure

I have some funny noob problem. I try to run unit tests from commandline: H:PROpyEstimator>python src estpython est_power_estimator.py Traceback (most recent call last): File "src est...

How to unit-test an enterprise symfony project?

I´m working on a huge project at my work. We have about 200 database tables, accordingly a huge number of Models, Actions and so on. How should I begin to write tests for this? My biggest problem ...

Code Coverage Tools & Visual Studio 2008 Pro

Just wondering what people are using for code coverage tools when using MS Visual Studio 2008 Pro. We are using the built-in MS test project and unit testing tool (the one that come pre-installed ...

Unit testing. File structure

I have a C++ legacy codebase with 10-15 applications, all sharing several components. While setting up unittests for both shared components and for applications themselves, I was wondering if there ...

Unit Testing .NET 3.5 projects using MStest in VS2010

There s a bug/feature in Visual Studio 2010 where you can t create a unit test project with the 2.0 CLR. https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=483891&wa=...

Unit Test for Exceptions Message

Is there a simple (Attribute-driven) way to have the following test fail on the message of the exception. [TestMethod()] [ExpectedException(typeof(ArgumentException))] public void ExceptionTestTest() ...

热门标签