Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Account with ID = [id] does not exist, even I don't call any accounts?

Posted on by 15

Hi,

I'm writing a console app to upload file .csv into CRM. Here is my code:

var hundredData = File.ReadAllLines(@"..\..\Data\ImportList100Data.csv");

            var dataList = from detailData in hundredData
                            let data = detailData.Split(';')
                            select new
                            {
                                GroupName = data[0],
                                ProjectNumber = data[1],
                                Name = data[2],
                                Members = data[3],
                                Customer = data[4],
                                ProjectStatus = data[5],
                                StartDate = data[6],
                                EndDate = data[7]
                            };
            var list = dataList.ToList();

            int totalData = list.Count();
            int successUpd = 0;
            int successCreate = 0;
            log.Info("There are "   (totalData - 1)   " items to be processed");

            var systemUser = getSystemUser(crmSvc);
            for (int i = 1; i < list.Count(); i  )
            {

                var data = list[i];
                DateTime startDate = DateTime.Parse(data.StartDate);
                DateTime endDate = DateTime.Parse(data.EndDate);
                int optSet;
                switch (data.ProjectStatus.ToString())
                {
                    case "New":
                        optSet = 283630000;
                        break;
                    case "Planned":
                        optSet = 283630001;
                        break;
                    case "In Progress":
                        optSet = 283630002;
                        break;
                    case "Finished":
                        optSet = 283630003;
                        break;
                    default:
                        throw new Exception("Invalid choice");
                }
                var visa = addMem(crmSvc, data.Members);

                var proj = getProjID(context, data.ProjectNumber.ToString());
                elca_Project newProject = new elca_Project();

                newProject.new_ProjectGroup = QueryGroup(context, data.GroupName);
                newProject.elca_name = data.Name.ToString();
                newProject.elca_Customer = data.Customer.ToString();
                newProject.elca_StartDate = startDate;
                newProject.elca_EndDate = endDate;
                newProject.elca_ProjectStatus = new OptionSetValue(optSet);
                newProject.elca_Members = visa;
                newProject.OwnerId = systemUser;

                try
                {
                    if (proj != null)
                    {
                        newProject.Id = proj.Id;

                        crmSvc.Update(newProject);
                        successUpd  ;
                        log.Info("Item "   i   "/"   (totalData - 1)   ": Project was updated");
                    }
                    else
                    {
                        newProject.elca_ProjectNumber = data.ProjectNumber.ToString();

                        crmSvc.Create(newProject);
                        successCreate  ;
                        log.Info("Item "   i   "/"   (totalData - 1)   ": Project was created");
                    }
                }
                catch(Exception e)
                {
                    log.Error("Item "   i   "/"   (totalData - 1)   ": Failed with error "   e.Message, e);
                }
            }

And get systemuser:

static EntityReference getSystemUser(CrmServiceClient crmSvc)
        {
            WhoAmIRequest systemUserRequest = new WhoAmIRequest();
            WhoAmIResponse systemUserResponse = (WhoAmIResponse)crmSvc.Execute(systemUserRequest);
            Guid userId = systemUserResponse.UserId;

            return new EntityReference("systemuser", userId);
        }

But I get the error like this even I don't call any account. How to fix it?

pastedimage1631880233895v1.png

Thanks a lot.

  • AndyArndt Profile Picture
    AndyArndt 110 on at
    RE: Account with ID = [id] does not exist, even I don't call any accounts?

    I'm glad you found and fixed the problem. Tracking things down like that can be tricky.

  • Suggested answer
    Huong Gau Profile Picture
    Huong Gau 15 on at
    RE: Account with ID = [id] does not exist, even I don't call any accounts?

    Thanks for all of your answer.

    I've found out the problem that there is a unexpected relationship between the project and account, so I just delete and it works well

  • Huong Gau Profile Picture
    Huong Gau 15 on at
    RE: Account with ID = [id] does not exist, even I don't call any accounts?

    Yah it's string and I've already get it.

  • Huong Gau Profile Picture
    Huong Gau 15 on at
    RE: Account with ID = [id] does not exist, even I don't call any accounts?

    It's just to get a string, I've put breakpoint but no rows throw exception, when I try to show the csv in console it's all ok but the error still exist

  • AndyArndt Profile Picture
    AndyArndt 110 on at
    RE: Account with ID = [id] does not exist, even I don't call any accounts?

    One more thing. What data type is your elca_Members field on the elca_Project entity?

  • AndyArndt Profile Picture
    AndyArndt 110 on at
    RE: Account with ID = [id] does not exist, even I don't call any accounts?

    The systemuser part looks right to me. What does your addMem() method do? If you've stepped through the code with breakpoints, what line is throwing the exception? Are any rows getting added to the elca_Project entity, or are all input lines from the csv failing?

  • Huong Gau Profile Picture
    Huong Gau 15 on at
    RE: Account with ID = [id] does not exist, even I don't call any accounts?

    Actually the Customer is just a text field, but the Owner is an entity reference and I have post the code to retrieve the ownerid, can you please check it if I have any mistakes? Because I try finding which related to Account but there is not

  • AndyArndt Profile Picture
    AndyArndt 110 on at
    RE: Account with ID = [id] does not exist, even I don't call any accounts?

    One thing to look at is it seems that you have a "Customer" data type in your entity. The Customer data type can reference a Contact or an Account. If there's something else in this process/code that assumes a Contact or an Account, that could be the issue. For example it might be looking to find an account by id in the customer field, but the GUID is really for a Contact.

  • Huong Gau Profile Picture
    Huong Gau 15 on at
    RE: Account with ID = [id] does not exist, even I don't call any accounts?

    Thank you but I still get that problems after disabling all my plugins, can I try some thing else?

  • Suggested answer
    Flydancer Profile Picture
    Flydancer 1,332 on at
    RE: Account with ID = [id] does not exist, even I don't call any accounts?

    Have you checked if there is a plugin running on the entity you're trying to update? Try disabling it

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans