/ Published in: C#

How to transfer related entities (Annotation, Opportunity) between two accounts
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// Transfer Opportunities private void TransferOpportunities(OrganizationServiceContext orgContext, Account sourceAccount, Account destinationAccount) { var opportunities = orgContext.OpportunitySet.Where(o=>o.CustomerId != null && o.CustomerId.Id == sourceAccount.Id); if (opportunities != null) { foreach (var opportunity in opportunities) { // or var er = destinationAccount.ToEntityReference(); opportunity.CustomerId = er; orgContext.UpdateObject(opportunity); } } } // Transfer Annotations private void TransferNotes(OrganizationServiceContext orgContext, Account sourceAccount, Account destinationAccount) { var notes = orgContext.AnnotationSet.Where(a => a.ObjectId.Id == sourceAccount.Id); if (notes != null) { foreach (var note in notes) { note.ObjectId = er; note.ObjectTypeCode = Account.EntityLogicalName; orgContext.UpdateObject(note); } } }
Comments
