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
MaggieSumitMaggieSumit 

Invalid field ObjectA__cId for SObject ObjectB__c

    public void addQuestion(){
        lstQuestion.add(new ObjectB__c(ObjectA__cId = Current_obj_Id));
       
        isEdit = true;
    
        } 
User-added image
User-added image
Best Answer chosen by MaggieSumit
Naresh YadavNaresh Yadav
Hi Sumit

Please make small change in your code.

public void addQuestion(){
        lstQuestion.add(new ObjectB__c(ObjectBLookup__c = Current_obj_Id));
       
        isEdit = true;
    
        } 

You are using wrong name for lookup. In ObjectB the lookup name for objectA is ObjectBLookup__c. And you are using ObjectA__cId instead of ObjectBLookup__c

Let me know if it helps you out.
Peace.

All Answers

Rohit K SethiRohit K Sethi
Hi Sumit 

lstQuestion.add(new ObjectB__c(ObjectA__cId = Current_obj_Id));
Bolded statement is wrong.

Use Following sy
lstQuestion.add(new ObjectB__c(ObjectA__c = Current_obj_Id));
                                 OR
lstQuestion.add(new ObjectB__c(ObjectA__c.id = Current_obj_Id));

Thanks.
Naresh YadavNaresh Yadav
Hi Sumit

Please make small change in your code.

public void addQuestion(){
        lstQuestion.add(new ObjectB__c(ObjectBLookup__c = Current_obj_Id));
       
        isEdit = true;
    
        } 

You are using wrong name for lookup. In ObjectB the lookup name for objectA is ObjectBLookup__c. And you are using ObjectA__cId instead of ObjectBLookup__c

Let me know if it helps you out.
Peace.
This was selected as the best answer