Skip to content

Instantly share code, notes, and snippets.

// Get the field describe result for the Name field on the Account object
Schema.DescribeFieldResult dfr = Schema.sObjectType.Account.fields.Name;
// Create a new account as the generic type sObject
sObject s = new Account();
// Verify that the generic sObject is an Account sObject
System.assert(s.getsObjectType() == Account.sObjectType);
// Get the sObject describe result for the Account object
Schema.DescribeSObjectResult dsr = Account.sObjectType.getDescribe();
/**
* @Description: This method returns a list of FieldSetMember as per the Object and Field Set Name
* @Arguments: NA
* @Return: List<Schema.FieldSetMember>
**/
private List<Schema.FieldSetMember> getFields() {
/** @Description: Account is the object and FieldSetName is the API Name of the FieldSet **/
return SObjectType.Account.FieldSets.FieldSetName.getFields();
}
/**
* @Description: This method takes in a list of Contacts as parameteres and creates individual lists for user fields
* @Arguments: List<String>
* @Return: void
**/
static void createCommunityUsers(List<Contact> contactList){
/** @Description: List variables to store user information.**/
List<String> str_contId = new List<String>();
List<String> str_alias = new List<String>();
//instantiate a new Contact
Contact con = new Contact();
con.LastName = 'testLastName';
con.Email = 'test101@salesforce.com';
//getch recordtypeId via schema call, recordtype should be referenced by Name and not Developer Name
con.RecordTypeId = Schema.SObjectType.Contact.RecordTypeInfosByName.get('Contact Record Type').RecordTypeId;
Database.insert(con);
//Fetch the Profile Id that will assigned to the user
List<Profile> profileList = [SELECT Id FROM Profile WHERE Name='Standard User'];
//Instantiate a user variable
User testUser = new User();
//if profilelist is not empty
if(!profileList.isEmpty()){
//Create user
testUser = new User(Alias = 'standt', Email='standarduser@testorg.com',
//Create a Map of roleId to User Ids
Map<Id, List<Id>> userRoleToUsersMap = new Map<Id, List<Id>>();
//SOQL to query and loop over all the users
for(User newUser : [SELECT UserRoleId FROM User LIMIT 50000]) {
//if userRoleToUsersMap already contains roleId
if(userRoleToUsersMap.containsKey(newUser.UserRoleId)) {
//fetch all the existing user ids for a roleId in a list
List<Id> usersId = userRoleToUsersMap.get(newUser.UserRoleId);
usersId.add(newUser.Id);
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>*</members>
<name>ApexClass</name>
</types>
<types>
<members>*</members>
<name>ApexTrigger</name>
</types>
@atulgupta31
atulgupta31 / Trailhead_SLDS_Listview_Data
Created March 11, 2016 22:30
Trailhead_SLDS_Listview_Data
<apex:page showHeader="false" standardStylesheets="false" sidebar="false" applyHtmlTag="false" applyBodyTag="false" docType="html-5.0">
<html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<head>
<title>Salesforce Lightning Design System Trailhead Module</title>
<!-- Make sure to update the Static Resource Name as per the static resource's name in your org -->
<apex:stylesheet value="{!URLFOR($Resource.REPLACE_WITH_NAME_OF_SLDS_STATIC_RESOURCE, 'assets/styles/salesforce-lightning-design-system-vf.css')}" />
</head>
@atulgupta31
atulgupta31 / Trailhead_SLDS_Listview
Last active March 11, 2016 21:58
Trailhead_SLDS_Listview
<apex:page showHeader="false" standardStylesheets="false" sidebar="false" applyHtmlTag="false" applyBodyTag="false" docType="html-5.0">
<html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<head>
<title>Salesforce Lightning Design System Trailhead Module</title>
<!-- Make sure to update the Static Resource Name as per the static resource's name in your org -->
<apex:stylesheet value="{!URLFOR($Resource.REPLACE_WITH_NAME_OF_SLDS_STATIC_RESOURCE, 'assets/styles/salesforce-lightning-design-system-vf.css')}" />
</head>