Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help with error message -- Error: Column names errors.statusCode and errors.message must not be duplicated. #66

Closed
Pecners opened this issue Jul 24, 2020 · 3 comments
Assignees
Labels
bug Unintended behavior that should be corrected
Milestone

Comments

@Pecners
Copy link

Pecners commented Jul 24, 2020

First of all, love this package! I'm very grateful to the work you've put into this, it has helped me out immensely.

I'm trying to create campaign members for several campaigns via sf_create() (something I've done successfully before, by the way), but I'm getting an odd error message that says: Error: Column names errors.statusCode and errors.message must not be duplicated.

I tried it a few times, with both SOAP and REST, until I realized that some of the campaign members were being created with each pass since I didn't have all_or_none set to TRUE--but every time I get this error. I assume it's referring to the columns in the resultset table that is returned.

I've been working with salesforcer all afternoon, and have created new contacts and queried objects without problem until now.

To provide a little more info, I did try it with verbose = TRUE as well, and this is the bottom of that output, which was done in 3 batches:

{
      "attributes": {
        "type": "CampaignMember",
        "referenceId": "ref434"
      },
      "CampaignId": "7011Y000002a6vdQAA",
      "ContactId": "0031Y000067wRwdQAE",
      "Status": "Attended"
    },
    {
      "attributes": {
        "type": "CampaignMember",
        "referenceId": "ref435"
      },
      "CampaignId": "7011Y000002aKSpQAM",
      "ContactId": "0031Y000067wRwfQAE",
      "Status": "Attended"
    },
    {
      "attributes": {
        "type": "CampaignMember",
        "referenceId": "ref436"
      },
      "CampaignId": "7011Y000002N8OCQA0",
      "ContactId": "0031Y000067wRwgQAE",
      "Status": "Attended"
    },
    {
      "attributes": {
        "type": "CampaignMember",
        "referenceId": "ref437"
      },
      "CampaignId": "7011Y000002N8OCQA0",
      "ContactId": "0031Y000067wRwhQAE",
      "Status":Error: Column names `errors.statusCode` and `errors.message` must not be duplicated.

Running rlang::last_error() produces:

Run `rlang::last_error()` to see where the error occurred.
> rlang::last_error()
x
+-<error/tibble_error_column_names_must_be_unique>
| Column names `errors.statusCode` and `errors.message` must not be duplicated.
\-<error/vctrs_error_names_must_be_unique>
  Names must be unique.
Backtrace:
  1. salesforcer::sf_create(...)
  2. salesforcer:::sf_create_rest(...)
 10. purrr::map_df(., flatten_tbl_df)
 11. purrr::map(.x, .f, ...)
 12. salesforcer:::.f(.x[[i]], ...)
  6. rlist::list.flatten(.)
 14. tibble::as_tibble_row(.)
 22. tibble:::set_repaired_names(x, .name_repair)
 24. tibble:::repaired_names(...)
 27. vctrs::vec_as_names(...)
 29. vctrs:::validate_unique(names = names, arg = arg)
 30. vctrs:::stop_names_must_be_unique(names, arg)
 31. vctrs:::stop_names(...)
 32. vctrs:::stop_vctrs(class = c(class, "vctrs_error_names"), ...)
Run `rlang::last_trace()` to see the full context.

And finally, sessionInfo():

R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] lubridate_1.7.9   salesforcer_0.2.0 forcats_0.5.0     stringr_1.4.0     dplyr_1.0.0       purrr_0.3.4       readr_1.3.1       tidyr_1.1.0       tibble_3.0.3     
[10] ggplot2_3.3.2     tidyverse_1.3.0  

loaded via a namespace (and not attached):
 [1] tidyselect_1.1.0  haven_2.3.1       colorspace_1.4-1  vctrs_0.3.2       generics_0.0.2    base64enc_0.1-3   utf8_1.1.4        blob_1.2.1        XML_3.99-0.3     
[10] rlang_0.4.7       pillar_1.4.6      glue_1.4.0        withr_2.2.0       DBI_1.1.0         dbplyr_1.4.4      modelr_0.1.8      readxl_1.3.1      lifecycle_0.2.0  
[19] munsell_0.5.0     gtable_0.3.0      cellranger_1.1.0  rvest_0.3.5       zip_2.0.4         curl_4.3          fansi_0.4.1       broom_0.7.0       Rcpp_1.0.5       
[28] openssl_1.4.2     scales_1.1.1      backports_1.1.8   jsonlite_1.7.0    mime_0.9          fs_1.4.2          hms_0.5.3         askpass_1.1       stringi_1.4.6    
[37] rlist_0.4.6.1     grid_3.6.1        cli_2.0.2         tools_3.6.1       magrittr_1.5      crayon_1.3.4      pkgconfig_2.0.3   ellipsis_0.3.1    data.table_1.13.0
[46] xml2_1.3.2        reprex_0.3.0      assertthat_0.2.1  httr_1.4.2        rstudioapi_0.11   R6_2.4.1          compiler_3.6.1   
@StevenMMortimer
Copy link
Owner

@Pecners Appreciate the heads up. Can you do me a favor and create the records one at a time by looping over the rows of your input tbl_df? I'd be curious to know what records and failing and why.

Example

result <- NULL
for(i in 1:nrow(input_data)){
  this_result <- sf_create(input_data[i,], object="OBJECT_NAME_HERE")
  result <- bind_rows(result, this_result)
}

@StevenMMortimer StevenMMortimer added the question or help Clarification or help may suffice to resolve label Jul 24, 2020
@StevenMMortimer StevenMMortimer added bug Unintended behavior that should be corrected and removed question or help Clarification or help may suffice to resolve labels Jul 27, 2020
@StevenMMortimer StevenMMortimer added this to the 0.2.1 milestone Jul 27, 2020
@StevenMMortimer
Copy link
Owner

@Pecners Thanks again for pointing out the issue. The problem is that, for some reason, when the creation of a CampaignMember fails, two different error messages are returned, not just one. This means that I had to wrap the error in list() to have it be one single element to put into each row.

If you install from GitHub using remotes::install_github("StevenMMortimer/salesforcer"), the problem should be fixed. I'll probably release the package again on CRAN within the week before making a larger announcement about all the other added features. Appreciate the help in working out the kinks.

The example below shows how the new code will behave when you receive an error while creating records. In this case I have the Contact Ids, but I forgot to specify the Campaign Id.

library(dplyr, warn.conflicts = FALSE)
library(salesforcer)
sf_auth()

n <- 3
new_campaign_members <- tibble(CampaignId = rep("", n), 
                               ContactId = c("0033s000013ZHX9AAO", 
                                             "0033s000013ZHXAAA4", 
                                             "0033s000013ZHXBAA4"),
                               Status = rep("Attended", n))
created_records <- sf_create(new_campaign_members, object_name="CampaignMember", api_type="REST")

created_records
#> # A tibble: 3 x 2
#>          success         errors 
#>            <lgl>         <list> 
#> 1          FALSE     <list [2]>     
#> 2          FALSE     <list [2]>
#> 3          FALSE     <list [2]>

created_records$errors[1][[1]]
#> [[1]]
#> [[1]]$statusCode
#> [1] "REQUIRED_FIELD_MISSING"
#> 
#> [[1]]$message
#> [1] "Attempted to add a campaign member where either the member id '0033s000013ZHX9' or the campaign id 'null' is null."
#> 
#> [[1]]$fields
#> list()
#> 
#> 
#> [[2]]
#> [[2]]$statusCode
#> [1] "REQUIRED_FIELD_MISSING"
#> 
#> [[2]]$message
#> [1] "Attempted to add a campaign member where either the member id '0033s000013ZHX9' or the campaign id 'null' is null."
#> 
#> [[2]]$fields
#> list()

Created on 2020-07-26 by the reprex package (v0.3.0)

@Pecners
Copy link
Author

Pecners commented Jul 27, 2020

Awesome, thanks for following up -- and sorry, I didn't see you response before I signed off for the weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unintended behavior that should be corrected
Projects
None yet
Development

No branches or pull requests

2 participants