Salesforce Cookies #11 ( Salesforce Admin Special )

Is there a way to mass-check Checkboxes when updating a Profile’s Object’s Field-Level Security?

Of course, there is. You can do it through your browser’s console. You just need the following Javascript code snippet which will do the job for you.

For the Edit Permission
var checkboxes = document.querySelectorAll(".displayedCol input");
for (var i = 0; i < checkboxes.length; i++) {
For the Read Permission Only
var checkboxes = document.querySelectorAll(".readonlyCol input");
for (var i = 0; i < checkboxes.length; i++) {

Running JS code snippet in the Google Chrome for updating the field-level permissions

  1. First, navigate to the Field-Level security page for profile and click on Edit button so you can perform the check and uncheck
  2. Now from the Chrome menu > More Tools > Select ‘Developer Tools’ and Click on the Console tab / Press Ctrl+Shift+J.
  3. Copy and Past the above JS code in the console editor and hit the return key.
  4. Save the changes


Salesforce Cookies #10

Creating a dynamic SOQL which includes all the fields

I have seen this question several times on developer forums and I thought it could be another addition to Salesforce cookies. If you are wondering how can you query all the fields of an object then you can use the following code snippet.

Map&lt;String,Schema.SObjectField&gt; mapFields = Account.getSObjectType().getDescribe().fields.getMap(); 
List&lt;String&gt; fieldNames = new List&lt;String&gt;();
for( String fieldName : mapFields.keySet() ) {
     fieldNames.add( fieldName );
     // For relationship fields
     if( Schema.DisplayType.Reference == mapFields.get(fieldName).getDescribe().getType() )
     fieldNames.add( mapFields.get(fieldName).getDescribe().getRelationshipName() + '.Name' ); 
String query = 
    ' SELECT ' + 
    String.join( fieldNames, ',' ) + 
    ' FROM Account ' +
    ' WHERE ' + 
    ' Id = :recorId ';
List&lt;Account&gt; lstRecords = Database.query( query );

This is quite similar to SQL query which uses wildcard characters – SELECT * FROM Table.