+ Start a Discussion
Priyanka ChandrakanthPriyanka Chandrakanth 

updating query lead fields from opportunity

Opportunity opp1 = [select field1__c,(Select field2__c,id From Leads__r) from Opportunity where id='006q0000xxxxxx'];
opp1.Leads__r.field2__c = 'text';
update opp1;

Above logic throws the following error. Can anyone help me in achieving the above logic?

Error:
Line: 2, Column: 1
Invalid foreign key relationship: Opportunity.Leads__r


Thanks in advance!
Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Hello,

By default Opportunity is not related to Lead object. Have you created a custom field for lead in Opportunity object? 

Regards.
 
Priyanka ChandrakanthPriyanka Chandrakanth
No, there is not any field of lead on Opportunity, but I thought if we are able to query the lead fields from Opp SOQL, then by using above logic we should also be able to perform DML operations???
Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Hello,

Please refer to this thread: 
http://salesforce.stackexchange.com/questions/28557/select-statements-in-a-multi-join-soql-query (http://salesforce.stackexchange.com/questions/28557/select-statements-in-a-multi-join-soql-query" target="_blank)

Regards.

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