如何从自定义主对象检索字段?

时间:2019-05-30 05:12:13

标签: salesforce apex soql

我试图编写一个自定义对象,并且必须从自定义对象Course Master(主)中检索一个与自定义相关的字段,以详细说明对象培训交易。这段代码显示错误

 List<List<String>> strList = new List<List<String>>();
    List<Training_deal__c> td = [select name,   Course_master__r.course__c from Training_deal__c];

    for(Training_deal__c t : td){
        List<String> tempList = new List<String>();
        tempList.add('Training Deals');
        tempList.add(t.name);
        tempList.add(t.course__c);
        strList.add(tempList);
    }

2 个答案:

答案 0 :(得分:0)

尝试一下

tempList.add(t.Course_master__r.course__c);

答案 1 :(得分:0)

我尝试过这样,并且运行正常

List<List<String>> strList = new List<List<String>>();
List<Training_deal__c> td = [select name,   Course_master__r.course__c from Training_deal__c];

for(Training_deal__c t : td){
    List<String> tempList = new List<String>();
    tempList.add('Training Deals');
    tempList.add(t.name);
    tempList.add(t.Course_master__r.course__c);
    strList.add(tempList);
}