How do I update a custom entity in crm 2011 online plugin code?

Can anyone tell me why this code doesn't work in an 2011 online plugin? What I'm trying to do is update a collection of custom entities. It throws the following error on the service.Execute(...). Another way to achieve this much appreciated...

Unexpected exception from plug-in (Execute): : System.InvalidCastException: Specified cast is not valid.

EntityCollection CustomEntitiesNeedingSync = service.RetrieveMultiple(RelevantCustomEntitiesQuery);

foreach (Entity currentCustomRecord in CustomEntitiesNeedingSync.Entities)
{
   UpdateRequest theUpdateRequest = new UpdateRequest();
   theUpdateRequest.Target = currentCustomRecord;
   service.Execute(currentCustomRecord);               
}

Answers


You have to execute the request - not the record.

foreach (Entity currentCustomRecord in CustomEntitiesNeedingSync.Entities)
{
   UpdateRequest theUpdateRequest = new UpdateRequest();
   theUpdateRequest.Target = currentCustomRecord;
   service.Execute(theUpdateRequest);               
}

Need Your Help

jsr 303 validate a number and auto initialize to 0

java bean-validation

in my domain class I have an integer which is being populated from

PostgreSQL aggregate or window function to return just the last value

sql postgresql aggregate-functions

I'm using an aggregate function with the OVER clause in PostgreSQL 9.1 and I want to return just the last row for each window. The last_value() window function sounds like it might do what I want -...