function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MariPMariP 

syntax to set a foreign key in a test class

Hi every body !

 

I need some help to finish my test class.

 

Y have a customer object (Int_Call_Plan__c), which has a lookup to object Account, through a customer field.

 

In the map to load the object via the data loader, I have this for the concerned field :

 

       KCODCLI=Call_Plan_Line_POS__r\:External_key__c

 

In my test class, I need to set this field. I have done this, I know it's wrong, but I can't find how to write it. I have tried others combinations (for example with the Id of Account I try to get after insert), without success for now.

 

public with sharing class Test_IntCallPlanResult2 {

static testMethod void testIntCallPlanResult2() {
        
        /*=====================
        ACCOUNT
        =======================*/
        Account testAccount1 = new Account();
        testAccount1.Name = 'TestAccount1';
        testAccount1.External_key__c = 'XXXPOS1';
        
        insert testAccount1;
        Account IdtestAccount1 = [select Id from Account where External_key__c ='XXXPOS1' limit 1];
                
        
        /*========================
        test IntCallPlan
        ==========================*/

        Int_Call_Plan__c intCallPlanNew1 = new Int_Call_Plan__c();
        intCallPlanNew1.Call_Plan_Name__c='TESTCPLR_RC';
        intCallPlanNew1.Call_Plan_Line_Order_Reminder_Top__c='0';
        intCallPlanNew1.Call_Plan_Line_Result_Top__c='0';
        intCallPlanNew1.Call_Plan_Line_POS__c='XXXPOS1';
        intCallPlanNew1.CPLR_Record_Type__c='FRLR_RC';
        
        upsert intCallPlanNew1;
      
  }   
}

 

Thanks for your help, anyone.. !

Marie

 

 

Best Answer chosen by Admin (Salesforce Developers) 
ngabraningabrani

Marie,

You may try these --

intCallPlanNew1.Call_Plan_Line_POS__c=testAccount1;

Or

intCallPlanNew1.Call_Plan_Line_POS__c=testAccount1.id;

 

 

Naveen

(www.astreait.com/wordpress)

All Answers

ngabraningabrani

Marie,

You may try these --

intCallPlanNew1.Call_Plan_Line_POS__c=testAccount1;

Or

intCallPlanNew1.Call_Plan_Line_POS__c=testAccount1.id;

 

 

Naveen

(www.astreait.com/wordpress)

This was selected as the best answer
MariPMariP

Thank you very much Naween,

 

 

 intCallPlanNew1.Call_Plan_Line_POS__c=testAccount1.Id;

That works very well !

Now I see it, it seems evident... ! I am still far to get the goods reflexes !

 

Thank you again. It's great to have you to help people beginner like me !

Marie