Skip to main content
Hi All, I need some help with

Myobject__c c = new MyObject__c();

c.put('carrier__c', 'xyz'); // This works

c.put('Name__r.lastName__c', null); // THIS DOES NOT WORK when I view it through my VF page I get invalid field. For some reason REFERENCE to another field from other object does not work 

In developer console when I run query like Select Name__r.lastName__c From Myobject__c where id..... I can access Name__r.lastName__c
2 answers
  1. May 20, 2017, 11:18 PM
    Hello Mastram,

    To bind values using relationship fields you should use the putSObject method instead. 

    Here is an example:

    Interaction__c test = new Interaction__c();

    test.put('Points__c', 43);

    test.putSObject('Contact__r', new Contact( LastName='contact'));

    system.debug(test.Contact__r.LastName);

    Please refer to:

    https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_sobject.htm⌗apex_methods_system_sobject (http://​https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_sobject.htm⌗apex_methods_system_sobject)

    Hope to have helped!

    Regards.

    Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.

     
0/9000