List<Opportunity> op = [
SELECT Id,AccountId, External_Id__c, StageName, Sales_Office__c,
Held_or_Purchased_Model_Lookup__c, Subdivision__c, Lot__c,
Hold_Expiry_Date__c, Sales_Agent_Lookup__c, Real_Estate_Agent__c
FROM Opportunity
WHERE External_Id__c =: externalId
];
Purchased_Home__c purchasedHome = new Purchased_Home__c (
Account_Name__c = op.AccountId,
External_ID__c = op.External_Id__c,
Sales_Office__c = op.Sales_Office__c,
Model__c = op.Held_or_Purchased_Model_Lookup__c,
Subdivision__c = op.Subdivision__c,
Lot__c = op.Lot__c,
Sales_Agent__c = op.Sales_Agent_Lookup__c,
Real_Estate_Agent__c = op.Real_Estate_Agent__c
);
insert purchasedHome;
code above works, but below doesn't work...
List <Co_Buyer__c> cobuyer = [
SELECT First_Name__c, Last_Name__c, Home_Email__c, External_Id__c,Opportunity__c , Purchased_Home__c
FROM Co_Buyer__c where id =: op.id
];
for(Co_Buyer__c c : cobuyer){
c.id = purchasedHome.Id;
}
update cobuyer;
record of Purchased_Home__c
is created from opportunity record, when certain conditions are met.
Co_Buyer__c
is related list of op, and also needs to be created as purchasedhome's related list when purchasedHome record is created.
I'm having problem with related list part. When PurchasedHome record is created, cobuyers related list does not create with the purchased home record.
Thank you in advance.
op.FieldName
whereasop
is declared as aList<Opportunity>
.List<Opportunity> op
and then you are usingop.Id
,op.External_Id__c
, etc. elsewhere in your code, which will not compile. Can you make sure this is the exact code?