Posts

Showing posts from 2016

How to check/select all fields checkboxes at Field Level Security of Object in Profiles

Many times, we come across such a situation when we are in a hurry or deployment on head or more than 100 fields to be checked for field-level security. This happens mostly at the time of deployment or UAT is going on. In large organizations, objects have more than 100 fields, and checking and unchecking all of them become a nightmare for a Developer/Admin/tester/QA. It gives pain to hands as well, because we click hundreds of times. Why not have such scripts, which make this job easy and handy. I am writing down the JavaScript code snippet, which will help us to do this job. Js for marking all field check/uncheck at Field Level Security of an object at Profile Level.  The below code is Not applicable for Enhanced Profile User Interface. To mark all check-box true for Visible column 1 2 3 4 5 var arrayVisible = document .getElementsByClassName( 'displayedCol' ); for (i = 0 ;i < arrayVisible.length;i ++ ){ if (arrayVisible[i][ 'firstElementChild'

How to change/update the profile of a User in Salesforce from apex code

It's my first blog writing, so ignore all the grammatical errors here :) A user profile update is not allowed through apex code generally and it through error  FIELD_INTEGRITY_EXCEPTION, Cannot change profile for current user: Profile ID. It can be achieve by Http callout. How to do this, its pretty simple. There are 2 way to do this: 1st:  If we have community or a site enabled in our sf org. It's  3-4 step process. Create a visualforce page and assign a controller to it. Make this page public through guest user permissions. Define an action in apex:page tag.  which will be called when ever this page executes In controller : action: write the code to update the profileId. It works. 1 2 3 4 5 6 7 8 9 10 public void callPublicSite (){ String remoteURL = ' https: //testing.force.com/ProfileUpdate?userId=' userId+'&profileId='+profileIdToUpdate; HttpRequest httpRequest = new HttpRequest(); httpRequest. setM