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

CRM plugin exception

$
0
0
IPluginExecutionContext context = localContext.PluginExecutionContext;
            IOrganizationService service = localContext.OrganizationService;
            Entity Emaildetails = (Entity)context.InputParameters["Target"];
            QueryExpression qe = new QueryExpression();
            qe.EntityName = "incident";
            qe.ColumnSet = new ColumnSet();
            qe.ColumnSet.Columns.Add("statecode");
            qe.ColumnSet.Columns.Add("title");
            EntityCollection ec = service.RetrieveMultiple(qe);
            int i = ec.Entities.Count;
            foreach (Entity act in ec.Entities)
            {
               int j = string.Compare(Emaildetails.Attributes["name"].ToString(), act["title"].ToString());
                if (j == 0)
                {
                    OptionSetValue statecode = (OptionSetValue)act["statecode"];
                    int k = string.Compare(statecode.Value.ToString (), "1");
                    if (k == 0)
                    {

                        Guid mailrecipient = new Guid("ad8deb61-0da8-e211-b893-e06995a2cf26");
                        Guid sender = new Guid("ad8deb61-0da8-e211-b893-e06995a2cf26");
                        string subject = "test";
                        string body = "test body";
                        Guid regarding = new Guid("813943be-11a8-e211-b893-e06995a2cf26");
                        EntityReference from = new EntityReference("systemuser", sender);
                        Entity e_from = new Entity("activityparty");
                        e_from.Attributes.Add("partyid", from);
                        EntityCollection ec_FromParty = new EntityCollection();
                        ec_FromParty.EntityName = "systemuser";
                        ec_FromParty.Entities.Add(e_from);
                        EntityReference to = new EntityReference("systemuser", mailrecipient);
                        Entity e_to = new Entity("activityparty");
                        e_to.Attributes.Add("partyid", to);
                        EntityCollection ec_ToParty = new EntityCollection();
                        ec_ToParty.EntityName = "systemuser";
                        ec_ToParty.Entities.Add(e_to);
                       EntityReference regardingRecord = new EntityReference("incident", regarding);
                        Entity email = new Entity();
                        email.LogicalName = "email";
                        email.Attributes.Add("from", ec_FromParty);
                        email.Attributes.Add("to", ec_ToParty);
                        email.Attributes.Add("subject", subject);
                        email.Attributes.Add("description", body);
                        email.Attributes.Add("regardingobjectid", regardingRecord);
                        Guid email_Id = service.Create(email);
                        SendEmailRequest sendEmail = new SendEmailRequest();
                        sendEmail.EmailId = email_Id;
                        sendEmail.IssueSend = true;
                        sendEmail.TrackingToken = "";
                        SendEmailResponse response = (SendEmailResponse)service.Execute(sendEmail);

The above code i have used trigger a mail when new account was created. when execution it shown exception as below

When  download the log file it shown as below

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: The entity with a name = 'Incident' was not found in the MetadataCache.Detail:
<OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
  <ErrorCode>-2147217150</ErrorCode>
  <ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
  <Message>The entity with a name = 'Incident' was not found in the MetadataCache.</Message>
  <Timestamp>2013-04-18T10:47:35.8075583Z</Timestamp>
  <InnerFault i:nil="true" />
  <TraceText>

[accounttocasecheck.Plugins: accounttocasecheck.Plugins.accounttocase]
[d5be1b56-e6a7-e211-b863-e06995a2cf26: accounttocase]
Entered accounttocasecheck.Plugins.accounttocase.Execute(), Correlation Id: a2c765d9-45b4-489d-9e35-dabc7bbe9450, Initiating User: 4634a487-48a3-e211-a056-e06995a2cf26
accounttocasecheck.Plugins.accounttocase is firing for Entity: account, Message: Create, Correlation Id: a2c765d9-45b4-489d-9e35-dabc7bbe9450, Initiating User: 4634a487-48a3-e211-a056-e06995a2cf26
Exception: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: The entity with a name = 'Incident' was not found in the MetadataCache. (Fault Detail is equal to Microsoft.Xrm.Sdk.OrganizationServiceFault)., Correlation Id: a2c765d9-45b4-489d-9e35-dabc7bbe9450, Initiating User: 4634a487-48a3-e211-a056-e06995a2cf26
Exiting accounttocasecheck.Plugins.accounttocase.Execute(), Correlation Id: a2c765d9-45b4-489d-9e35-dabc7bbe9450, Initiating User: 4634a487-48a3-e211-a056-e06995a2cf26

 
 [closedcasealert.Plugins: closedcasealert.Plugins.closecasealert]
 [d401f795-5aa7-e211-880a-e06995a2cf26: closecasealert]
 Entered closedcasealert.Plugins.closecasealert.Execute(), Correlation Id: a2c765d9-45b4-489d-9e35-dabc7bbe9450, Initiating User: 4634a487-48a3-e211-a056-e06995a2cf26
 closedcasealert.Plugins.closecasealert is firing for Entity: email, Message: Create, Correlation Id: a2c765d9-45b4-489d-9e35-dabc7bbe9450, Initiating User: 4634a487-48a3-e211-a056-e06995a2cf26
 Exception: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: The entity with a name = 'Incident' was not found in the MetadataCache. (Fault Detail is equal to Microsoft.Xrm.Sdk.OrganizationServiceFault)., Correlation Id: a2c765d9-45b4-489d-9e35-dabc7bbe9450, Initiating User: 4634a487-48a3-e211-a056-e06995a2cf26
 Exiting closedcasealert.Plugins.closecasealert.Execute(), Correlation Id: a2c765d9-45b4-489d-9e35-dabc7bbe9450, Initiating User: 4634a487-48a3-e211-a056-e06995a2cf26

</TraceText>
</OrganizationServiceFault>

 

Please help me


Ravin Singh D


Viewing all articles
Browse latest Browse all 9244

Trending Articles



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