La presente iniciativa tiene como propósito poder compartir el conocimiento y como poder entender la plataforma Salesforce, de esta manera poder ser mas resolutivo y escalar el negocio.
Creo que lo mejor es entender que salesforce es una plataforma hecha por “capas”, en donde cada una cumple un rol específic para el uso del usuario final.
AQQAQAAQAQ
La base de la infraestructura Salesforce, de puede resumir de la siguiente manera:
Para mostrar algún ejemplo, veremos una instancia de Salesforce que se pueden utilizar en Trailhead.
library(salesforcer)
library(tidyverse)
library(shiny)
library(shinydashboard)
library(ggplot2)
library(shinyWidgets)
library(listviewer)
library(DT)
library(reactable)
library(png)
library(jsonlite)
## https://adeelk93.github.io/collapsibleTree/
library(collapsibleTree)
## ejemplso de shinywidgets -- shinyWidgetsGallery()
library(DBI)
library(purrr)
library(rsconnect)Profundizando las bases de datos de salesforces, estas serían objetos, en los cuales se clasifican en “Standar” vs “Custom”.
¿ Cuales son los principales objetos Standar de Salesforce?
Lead
Opportunity
Order
Contract
Case
Product
Asset
Quote
Pricebook
### LOGIN SALESFORCE
login_sf <- rforcecom.login(
username = "fgbahamondez@resilient-hawk-lctosl.com",
password = "Poder.2025wtXPi2xObhHWTADnepHZfqqqQ",
loginURL = "https://login.salesforce.com",
apiVersion = "61.0"
)¿Se puede leer todos los objetos (tablas) que tiene la Instancia ?
### LISTADO DE OBJETOS
listado_objetos <- salesforcer::sf_list_objects()
listado_objetos <- listado_objetos$sobjects
# Filtrar elementos que no estén vacíos
cleaned_list <- listado_objetos[map_lgl(listado_objetos, ~ length(.) > 0)]
### ahora transformar en data frame
objects_df <- map_dfr(cleaned_list, ~ as.data.frame(t(.)))
### SE MANTIENE LA LISTA EN COLUMNAS, AHORA ESAS LISTAS EXPANDIRLAS HACIA ABAJO.
expanded_df <- unnest(objects_df, where(is.list))
### cuantos son custom y cuales son standar?
expanded_df %>%
distinct(name, custom) %>%
group_by(custom) %>%
summarise(
Total = n()
)# describe metadata for the organization associated with the session
Org_Metadata <- salesforcer::sf_describe_metadata(verbose = TRUE)
Org_Metadata_Info <- Org_Metadata$metadataObjects
Org_Metadata_Info <- data.frame(Org_Metadata_Info)Necesito profundizar en el principal objeto
## DESCRIBIR COMO LISTA
Describe_Account <- salesforcer::sf_describe_objects(
object_names = "Account"
)
## VER EL JSON
listviewer::jsonedit(
listdata = Describe_Account
)
### VER LOS CAMPOS DE LA TABLA ACCOUNT
Account_fields <- sf_describe_object_fields(
object_name = "Account"
)
### EXPANDO HACIA ABAJAO
Account_fields_expanded <- unnest(Account_fields, where(is.list), names_sep = "_")
### SEGUNDA EXPANSION
Account_fields_expanded <- Account_fields_expanded %>%
unnest_wider(defaultValue, names_sep = "_")
### DESCARGAR CAMPOS ACCOUNT
fecha_hora_actual <- format(Sys.time(), "%Y-%m-%d_%H-%M-%S")
nombre_archivo <- paste0("Account/Account_fields_expanded", fecha_hora_actual, ".csv")
write.csv(Account_fields_expanded, file = nombre_archivo, row.names = FALSE)
### RELACION CON OTROS OBJETOS
Account_Relacion_objects <- Account_fields_expanded %>%
select(name, referenceTo, label) %>%
filter(!is.na(referenceTo)) %>%
arrange(name)
### Represent this tree:
### Ver la METADATA de ACCOUNT
Metadata_Account <- salesforcer::sf_read_metadata(
metadata_type = "CustomObject",
object_names = "Account"
)
listviewer::jsonedit(Metadata_Account)
### DESCARGAR JSON
Metadata_Account_json <- toJSON(Metadata_Account, pretty = TRUE)
fecha_hora_actual <- format(Sys.time(), "%Y-%m-%d_%H-%M-%S")
nombre_archivo <- paste0("Account/Metadata_Account", fecha_hora_actual, ".json")
write(Metadata_Account_json, file = nombre_archivo)Necesito profundizar en el principal objeto
## DESCRIBIR COMO LISTA
Describe_Lead <- salesforcer::sf_describe_objects(
object_names = "Lead"
)
## VER EL JSON
listviewer::jsonedit(
listdata = Describe_Lead
)
### VER LOS CAMPOS DE LA TABLA Lead
Lead_fields <- sf_describe_object_fields(
object_name = "Lead"
)
Lead_fields_expanded <- Lead_fields %>% unnest(cols = c(referenceTo), keep_empty = TRUE)
### SEGUNDA EXPANSION
Lead_fields_expanded <- Lead_fields_expanded %>%
unnest(cols = c(defaultValue), keep_empty = TRUE)
Lead_fields_expanded <- Lead_fields_expanded %>%
unnest(cols = c(defaultValue), keep_empty = TRUE)
Lead_fields_expanded <- Lead_fields_expanded %>%
unnest(cols = c(picklistValues), keep_empty = TRUE, names_sep = "_")
### DESCARGAR CAMPOS Lead
fecha_hora_actual <- format(Sys.time(), "%Y-%m-%d_%H-%M-%S")
nombre_archivo <- paste0("Lead/Lead_fields_expanded", fecha_hora_actual, ".csv")
write.csv(Lead_fields_expanded, file = nombre_archivo, row.names = FALSE)
### RELACION CON OTROS OBJETOS
Lead_Relacion_objects <- Lead_fields_expanded %>%
select(name, referenceTo, label) %>%
filter(!is.na(referenceTo)) %>%
arrange(name)
### Represent this tree:
collapsibleTree::collapsibleTree(Lead_Relacion_objects,
c("referenceTo","label","name"))
### Ver la METADATA de Lead
Metadata_Lead <- salesforcer::sf_read_metadata(
metadata_type = "CustomObject",
object_names = "Lead"
)
listviewer::jsonedit(Metadata_Lead)
### DESCARGAR JSON
Metadata_Lead_json <- toJSON(Metadata_Lead, pretty = TRUE)
fecha_hora_actual <- format(Sys.time(), "%Y-%m-%d_%H-%M-%S")
nombre_archivo <- paste0("Lead/Metadata_Lead", fecha_hora_actual, ".json")
write(Metadata_Lead_json, file = nombre_archivo)