Skip to content

Instantly share code, notes, and snippets.

@ViktorMants
Created September 16, 2020 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ViktorMants/a2512f4411725c53f183cf53ec778ce8 to your computer and use it in GitHub Desktop.
Save ViktorMants/a2512f4411725c53f183cf53ec778ce8 to your computer and use it in GitHub Desktop.
Content Document Statistica
var userIds = []
var queryUsersCallBack = (res) => {
console.log(res.records.length)
console.log(res.done)
console.log(res.queryLocator)
for (let user of res.records) {
userIds.push(user.Id)
}
if (res.done != 'true') {
sforce.connection.queryMore(res.queryLocator, queryUsersCallBack)
}
}
sforce.connection.query('SELECT Id FROM User', queryUsersCallBack)
var currentIndex = 0
var step = 1000
var docsByIds = {}
var retrieveDocs = (res) => {
if (!res) {
var tempUserIds = []
for (let index = currentIndex; index < currentIndex + step; index++) {
tempUserIds.push(userIds[index])
}
currentIndex += step
sforce.connection.query('SELECT Id, ContentDocument.FileType, ContentDocument.ContentSize, ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId IN (\'' + tempUserIds.join('\',\'') + '\')', retrieveDocs)
} else {
for (let record of res.records) {
docsByIds[record.ContentDocumentId] = record.ContentDocument
}
if (res.done != 'true') {
sforce.connection.queryMore(res.queryLocator, retrieveDocs)
} else {
retrieveDocs()
}
}
}
var analitica = {}
for (let key of Object.keys(docsByIds)) {
let doc = docsByIds[key]
let item = !!analitica[doc.FileType] ? analitica[doc.FileType] : {}
let c0unt = !!item['c0unt'] ? item['c0unt'] : 0
c0unt++;
item['c0unt'] = c0unt
let size = !!item['size'] ? item['size'] : 0
size += (doc.ContentSize * 1);
item['size'] = size
analitica[doc.FileType] = item
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment