+ Start a Discussion
Sumit  61Sumit 61 

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 Sumit 61
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

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
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.