There are situations where we need to get total number of records from an object with given criteria but the object is so big that query times out. The work around is to keep all the filters and apply additional filtering on CreatedDate for each year, get the count and sum it. This process is manual and we need to keep track of the each year count and this script simplifies it.
Last active
October 7, 2020 20:07
-
-
Save sfdcale/2ef0ed992eefe97778d2bdebd1591fe7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| FEED_ITEM_TYPES=("ContentPost" "TextPost" "ActivityEvent" "AdvancedTextPost" "AnnouncementPost" "ApprovalPost" "BasicTemplateFeedItem" "CanvasPost" "CollaborationGroupCreated" "CollaborationGroupUnarchived" "ContentPost" "CreatedRecordEvent" "DashboardComponentAlert" "DashboardComponentSnapshot" "LinkPost" "PollPost" "ProfileSkillPost" "QuestionPost" "ReplyPost" "RypplePost" "TextPost" "TrackedChange" "UserStatus" "AttachArticleEvent" "CallLogPost" "CaseCommentPost" "ChangeStatusPost" "ChatTranscriptPost" "EmailMessageEvent" "FacebookPost" "MilestoneEvent" "SocialPost") | |
| DATE_LOWER_BOUND="" | |
| DATE_BOUND_VALUES=("2011-12-31" "2012-12-31" "2013-12-31" "2014-12-31" "2015-12-31" "2016-12-31" "2017-12-31" "2018-12-31" "2019-12-31" "2020-12-31") | |
| for FEED_ITEM_TYPE in ${FEED_ITEM_TYPES[@]}; do | |
| TOTAL_COUNT=0 | |
| for DATE_UPPER_BOUND in ${DATE_BOUND_VALUES[@]}; do | |
| if [ -z "$DATE_LOWER_BOUND" ] | |
| then | |
| DATE_LOWER_BOUND="2000-12-31" | |
| fi | |
| TEMP_COUNT=`sfdx force:data:soql:query --query="SELECT COUNT() FROM FeedItem WHERE NetworkScope = '0DBASFSFSFDSDFA' AND Type = '$FEED_ITEM_TYPE' AND DAY_ONLY(CreatedDate) < $DATE_UPPER_BOUND AND DAY_ONLY(CreatedDate) > $DATE_LOWER_BOUND" --targetusername sandbox --json | jq ".result.totalSize"` | |
| DATE_LOWER_BOUND=$DATE_UPPER_BOUND | |
| TOTAL_COUNT=$((TOTAL_COUNT + TEMP_COUNT)) | |
| done | |
| echo "TOTAL COUNT OF $FEED_ITEM_TYPE : $TOTAL_COUNT" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment