Giter VIP home page Giter VIP logo

sfhcks's Introduction

Salesforce H@cks

This repo is a lose collection of Salesforce stuff I find useful enough to keep.
Likely it will mostly contain anonymous Apex scripts, but let's see where this is going.
I have an other Salesforce related repo for the command line stuff

ON / OFF Switches

The purpose of my on-/off switch scripts was a full sandbox replacement project.
We basically loaded production org backup into a partial sandbox via multiple etl jobs.
The last things you need in such a situation are data validations and sorts of triggers.
My scripts step 1&2 are deactivating most of that stuff and keep note of what was active.
When you're done with the load, execute step 3 to easily switch back on all elements.
The below shown method works with validation rules, process builder and workflow rules.
Apex triggers wont work unfortunately as they can't be updated by the tooling api.

Method:

  • STEP1: Query vr, pb or wfr via tooling api -> store their meta data in cases.
  • STEP2: Loop through those cases, switch active elements off via tooling api.
  • STEP3: Loop again through those cases, switch prior activated elements back on via tooling api.

Start and End of each step are marked within the scripts.
Execute them one-by-one when they are needed.

// START STEP 1 -> "QUERY FLOW DEFINITIONS, STORE FD DATA"
// END STEP 1

NOTE: You could run into troubles if you've active trigger, routing or validation logic set on the case object.
If you have a lot of rules in your org you might hit api call limits.
I believe if you have more than 100 elements (total, active + inactive) some script refactoring would be required.

Direct links to ON/OFF switch for element:
Process Builder
Validation Rules
Workflow Rules

PermissionSetAssignment

PermissionSetAssignment assignes Permission Sets from one user to an other.
Just place source and target user IDs in the script and execute anonymous.

String sourceUserId = ''; // <-- Place Id of user WITH permissions here (active or inactive user)
String targetUserId = ''; // <-- Place Id of user WITHOUT permissions here (only active user)

The script queries all permission set assignments of the source user โ€ฆ and adds those which are missing to the source user.
It is currently written to take only one source and one target user. This could easily be upgraded.

ObjectNameAndLabel

This sends you an email with api names & labels of all objects in your org. Replace the email address variable in the script with your recipients:

String emailRecipients = '[email protected]'; // <-- PLACE RECIPIENT(S) HERE

The script comes with a plain text and a html version.
I have used the html version as a quick way to get that data in a table format.
Just copy the mail body into a text editor >> save as .html file >> open in browser

From there, copy it into Excel or wherever you need it.

EmailAlertRecipients

Had to find all email alerts which where sending mails to a certain public group.
Wrote this anonymous apex script to find a recipent with help of the tooling api.

sfhcks's People

Contributors

heikokramer avatar sfdcschwabe avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.