Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 9244

Getting errors in plugin when recordset is empty

$
0
0

Just updated code and I'm getting an error when the FetchXML query returns no records. 

This is what I have:

                //Start A
                string estimatedvalue_sum = string.Format(@" <fetch distinct='false' mapping='logical' aggregate='true'> <entity name='opportunity'> <attribute name='estimatedvalue' alias='estimatedvalue_sum' aggregate='sum' /> <filter type='and'><condition attribute='statecode' operator='eq' value='2' /><condition attribute='new_servicecontract' operator='eq' value='{0}' uiname='' uitype='' /></filter></entity></fetch>", a.Id);

                EntityCollection estimatedvalue_sum_result = service.RetrieveMultiple(new FetchExpression(estimatedvalue_sum));

                if (estimatedvalue_sum_result != null)
                {
                    foreach (var c in estimatedvalue_sum_result.Entities)
                    {
                        totalAmount = ((Money)((AliasedValue)c["estimatedvalue_sum"]).Value).Value;
                    }

                    //updating the field on the account
                    Entity acc = new Entity("wse_servicecost");
                    acc.Id = a.Id;
                    acc.Attributes.Add("new_caseanalysisopenbalance", new Money(totalAmount));
                    service.Update(acc);

                }

Does anyone know how to correct this?

 



Viewing all articles
Browse latest Browse all 9244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>