为两个不同的对象设置相同值的测试类

时间:2019-05-28 21:13:50

标签: triggers salesforce apex

需要帮助对此代码部分进行测试类!如何在测试课程中做到这一点

我尝试创建帐户并等于另一个对象。

for (Account YieldU : AccountList){
           YieldU.Yield__c = a.Yield__c;
           YieldU.Yield2__c = a.Yield2__c;
          ...

3 个答案:

答案 0 :(得分:0)

您尝试执行的操作没有太多上下文,但是您必须创建帐户

Account acct = new Account();
acct.Yield__c = 50;
acct.Yield2__c = 60;
insert acct;

答案 1 :(得分:0)

据我了解,在您的代码中,“ a”也将是一个对象,因此请首先为该对象插入一条记录。

abc__c ab= new abc__c();
ab.Yield__c = 10;
ab.Yield2__c = 20;
insert ab;

Account acct = new Account();
acct.Yield__c = ab.Yield__c;
acct.Yield2__c = ab.Yield2__c;
insert acct;

答案 2 :(得分:0)

list<account> acclist = new list<account>();
    list<Gym__c> gmlist = new list<Gym__c>();
    Account acct = new Account();
    acct.Bike__c= abc;
    acct.m2_total__c = xyz;
    acct.m2_fitness_group__c = def;
    acct.active = true;
    insert acct;
    acclist.add(acct);
    for (account ac:acclist)
    {
        gym__c gm=new gym();
        gm.gym_id__c= ac.id;
        gm.bike__c = ac.bike__c;
        gm.m2_total__c = ac.m2_total__c;
        gm.m2_fitness_group__c = ac.m2_fitness_group__c;
        gm.active__c = ac.active__c;
        gmlist.add(gm);

    }
    insert gmlist;

if then also you did not get your result then please share your whole code with me.