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
Antonio ManenteAntonio Manente 

Dynamic sObject Lookup assignment

I'm creating a quote object dynamically, and everything works fine but I'm stuck trying to assign my lookup relationship to account. I can't find any docs on this and was wondering if anyone has done something similar. Here's an example of what I'm trying to do:
 
Schema.SObjectType quoType = Schema.getGlobalDescribe().get('quote');
 sObject quo = quoType.newSObject(); 

//This works just fine 
quo.put('Email', 'generic@email.com');

 //I've tried different variations of this, none seem to work 
quo.put('AccountId' , SOME_ID); 
quo.put('Account', SOME_ID);


Any help is greatly appreciated, thanks in advance!
Best Answer chosen by Antonio Manente
pconpcon
This is because the AccountId field is not editable.  You have to set the OpportunityId field and then it will pull the AccountId field from the Opportunity.
 
quo.put('OpportunityId', oppId);

 

All Answers

pconpcon
This is because the AccountId field is not editable.  You have to set the OpportunityId field and then it will pull the AccountId field from the Opportunity.
 
quo.put('OpportunityId', oppId);

 
This was selected as the best answer
Antonio ManenteAntonio Manente
Thanks pcon! It works as expected.