In addition to the GetAttributeAliasValue entity extension method we provide you with another handy method… The cloning of entity records.
This method will enable you to create a perfect clone of any entity record.
Here’s how it’s done!

Usage
Entity account = OrganizationService.Retrieve("account", Guid.Parse("6a7cb8d1-7038-ea11-a813-000d3a385a1c"), new ColumnSet(true));
Entity clone= account.Clone();
Guid cloneId = OrganizationService.Create(clone);
This can be used on both early as late bound entity records, as all of your generated classes will inherit from the Entity class!




[…] The other day I was in need of cloning Activities from a Lead to an existing Contact. As it seems, this is not standard behavior of CRM when qualifying to an Existing Contact only and NOT to an Opportunity. Of course I immediately thought of the cloning extension method that Wouter posted on our blog a while ago. I’m not going into details about it, instead you can find it here. […]
[…] The other day I was in need of cloning Activities from a Lead to an existing Contact. As it seems, this is not standard behavior of CRM when qualifying to an Existing Contact only and NOT to an Opportunity. Of course I immediately thought of the cloning extension method that Wouter posted on our blog a while ago. I’m not going into details about it, instead you can find it here. […]
Thanks for tip Michel. I actually have most of these methods in a ManagerBase class that i initiate for every plugin. implementation is a bit different, but the purpose is the same
Maybe you can use this:
public static class IPluginExecutionContextExtension { public static Entity RetrieveEntity(this IPluginExecutionContext context) { return (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) ? (Entity)context.InputParameters["Target"] : null; } public static EntityReference RetrieveEntityReference(this IPluginExecutionContext context) { return (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is EntityReference) ? (EntityReference)context.InputParameters["Target"] : null; } public static Entity RetrievePreImageEntity(this IPluginExecutionContext context, string preImageName) { return (context.PreEntityImages.Contains(preImageName) && context.PreEntityImages[preImageName] is Entity) ? (Entity)context.PreEntityImages[preImageName] : null; } public static Relationship RetrieveRelationship(this IPluginExecutionContext context) { return (context.InputParameters.Contains("Relationship") && context.InputParameters["Relationship"] is Relationship) ? (Relationship)context.InputParameters["Relationship"] : null; } public static EntityReferenceCollection RetrieveRelatedEntities(this IPluginExecutionContext context) { return (context.InputParameters.Contains("RelatedEntities") && context.InputParameters["RelatedEntities"] is EntityReferenceCollection) ? (EntityReferenceCollection)context.InputParameters["RelatedEntities"] : null; } }