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

Fail on: Object Description and Fields Description #16

Closed
bazarnov opened this issue Mar 4, 2019 · 3 comments
Closed

Fail on: Object Description and Fields Description #16

bazarnov opened this issue Mar 4, 2019 · 3 comments
Assignees
Labels
bug Unintended behavior that should be corrected could not reproduce Could not be reproduced
Milestone

Comments

@bazarnov
Copy link

bazarnov commented Mar 4, 2019

Hi, I'm using the sf_describe_object() and sf_describe_object_fields() quite frequently in order to retrieve the list of fileds and how they are related and connected to every other object in our SalesForce. Recently I started to had this issue while trying to retrieve the object's fields using sf_describe_object_fields()

# INPUT
obj.fields  <- sf_describe_object_fields(object_name = "Case")

# OUTPUT gives me the Error
Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE,  : 
  arguments imply differing number of rows: 1, 0

Assuming that there are some fields that have unequal number of rows, therefore it could not convert the list to data.frame on the step of retrieving the Object description itself.

Any Idea of how to workaround this error?

@StevenMMortimer
Copy link
Owner

@bazarnov Use the sf_describe_objects() function to get the fields as a list and then format them as a data.frame however it works for you. I'd be curious to know what's causing the error for you in the parsing so that I can adjust it.

Here is the code to get you started. Run the first two lines, then inspect the list as to which of the fields is causing the error with as.data.frame().

obj_dat <- sf_describe_objects(object_names = 'Case', api_type = "SOAP")[[1]]
obj_fields_list <- obj_dat[names(obj_dat) == "fields"]

# this is the current code that's failing for you
obj_fields_list  %>% map_df(as.data.frame, stringsAsFactors=FALSE)

@bazarnov
Copy link
Author

bazarnov commented Mar 12, 2019

Hi, this is what was able to find out that after this line:
obj_fields_list <- obj_dat[names(obj_dat) == "fields"]

I got the list of lists with different number of unit in each (might differ from object to object), therefore the map_df doesn't apply it's magic in this case, however I was able to extract and built my own function in order to parse the information I need to use in my case:

This is the function for getting object list (result as data.frame):

collect_sf_objects <- function(){
  require(salesforcer)
  require(tidyverse)

  obj_dat <- sf_list_objects()

  label <- c()
  name <- c()
  custom <- c()
  queryable <- c()
  retrieveable <- c()
  #Looping over the list and extracting the Variables
  for (i in 1:length(obj_dat$sobjects)) {
    label[i] <- obj_dat$sobjects[[i]]$label                    #for labels
    name[i] <- obj_dat$sobjects[[i]]$name                      #for field names as they are
    custom[i] <- obj_dat$sobjects[[i]]$custom                  #was object customly created? TRUE/FALSE
    queryable[i] <- obj_dat$sobjects[[i]]$queryable            #is object available for querying?
    retrieveable[i] <- obj_dat$sobjects[[i]]$retrieveable      #is object available for retrieving a content?
  }

This is the function for getting object's fields (result as data.frame):

collect_sf_object_fields <- function(obj){
  require(salesforcer)
  require(tidyverse)

  obj_dat <- sf_describe_objects(object_names=obj,api_type="SOAP")[[1]]

  obj_fields <- obj_dat[names(obj_dat)=="fields"]

  label <- c()
  name <- c()
  type <- c()

  for (i in 1:length(obj_fields)) {
    label[i] <- obj_fields[[i]]$label   #for labels
    name[i] <- obj_fields[[i]]$name     #for field names as they are
    type[i] <- obj_fields[[i]]$type     #what type of info each field has
  }

  df <- data.frame('Label'=label,'Field_Name'=name,'Data_Type'=type,stringsAsFactors=F)
  return(df)
}

For now, my needs are covered, once you decide to deal with the area with map_df in your function, please add this to the ChangeLog) I'll be very glad to use your functions.

@StevenMMortimer StevenMMortimer self-assigned this May 14, 2019
@StevenMMortimer StevenMMortimer added bug Unintended behavior that should be corrected could not reproduce Could not be reproduced labels May 14, 2019
@StevenMMortimer StevenMMortimer added this to the 0.1.3 milestone May 14, 2019
@StevenMMortimer
Copy link
Owner

@bazarnov The function sf_describe_object_fields() has been updated in the latest CRAN version of the package (0.1.3). It is more robust to the nested structure when describing a field. I can't guarantee it will work for your org's objects, but it would help if you let me know whether or not it has fixed the issue for you. Thanks!

Example pulling the picklist options from the "Status" field on the Case object

case_fields <- sf_describe_object_fields(“Case”)

# show the “Status” field picklist options
case_fields %>% 
  filter(label == “Status”) %>% 
  .$picklistValues

[[1]]
# A tibble: 4 x 4
  active defaultValue label     value    
  <lgl>  <lgl>        <chr>     <chr>    
1 TRUE   TRUE         New       New      
2 TRUE   FALSE        Working   Working  
3 TRUE   FALSE        Escalated Escalated
4 TRUE   FALSE        Closed    Closed  

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 could not reproduce Could not be reproduced
Projects
None yet
Development

No branches or pull requests

2 participants