• dwright-glgroup
  • NEWBIE
  • 5 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 6
    Replies

Is it possible to write apex code to see if the current user has 'read all access' (not just accessibility, which is 'read' access to records he or his subordinates own).
To check for read access to Account objects, for example, you do this:

boolean mayAccessAccounts = Schema.sObjectType.Account.isAccessible();

Is it necessary to check the user's profile for the 'read all access' capability (I assume there is code to do that but I haven't found any), and also check the various permission sets for him to see if any of them have it?   Seems like a simpler API should exist...
 

Hello,

 

  I've enabled shared activities in my sandbox and would like to create a page to allow creating one.  I need my own page/controller extension because I want to show more information on the page.

 

Once you've enabled Shared Activities the standard Salesforce page, accessed by clicking Log Call button in a contact's "Activity History" related list, provides a multi-select control.  I got the single-select functionality by including the following in my form:

 

         <apex:inputField id="name" label="Name" value="{!theTask.WhoId}" />

 

  Does anyone know of what I should include on my page to get the multiple selection of contacts control?

 

Thanks,

Dave

Does anyone have an example you're willing to share of creating a task from Apex code and attaching multiple contacts?

 

Hello, I wrote my 3rd trigger in order to update the first contact of an account anytime there is a change on the account.

It seems to work properly but... not with bulk changes on accounts. Could anyone kindly have a look and give me some hints?

Thanks!


trigger UpdateFirstContactOfAccount on Account (after update) {

  System.debug('UpdateFirstContactOfAccount BEGIN');

if(limitrecursion.runtwice()){

  System.debug('UpdateFirstContactOfAccount RECURSIONLIMIT PASSED');

  //aa
  Set<Id> AccIDs = new Set<Id>();
  //for(Contact con: Trigger.new) AccIDs.add(con.AccountId);
  for(Account acc: Trigger.new) {
      System.debug('added id to AccIDs: ' + acc.id);
      AccIDs.add(acc.Id);
  }

 

    // Fetch all the Contacts for these Accounts, selecting only the oldest one of each Account
    List<Contact> Cons = new List<Contact>([
        select
             Id, AccountId
             from Contact
             where AccountId = : AccIDs ORDER BY CreatedDate ASC NULLS LAST LIMIT 1
    //         where AccountId in : AccIDs

     ]);

    // Build a Map, keyed by AccID, of Lists of the related Cons
    Map<Id, List<Contact>> acMap = new Map<Id, List<Contact>>();
    for (Contact c: Cons) {
       if (acMap.containsKey(c.AccountId)) {
            List<Contact> clist2;
            clist2 = acMap.get(c.AccountId);
            clist2.add(c);
            acMap.put(c.AccountId, clist2);
       } else {

            System.debug('added id to acMap: acc ' + c.AccountId + ' contact ' + c.Id);

            List<Contact> clist1 = new List<Contact>();
            clist1.add(c);
            acMap.put(c.AccountId, clist1);
       }
    }



List<Account> ACCS = new List<Account>();

for(Id aid: AccIDs)
{
  if (acMap.containsKey(aid)) {

           for (Contact cc: acMap.get(aid)) {
             System.debug('Account ID' + aid + ' included');
                ACCS.add(
                     New Account(
                        First_Contact__c = cc.Id ,
                        id=aid)
                );
           }
  }
  else
  {
  //remove first contact
  System.debug('Account ID' + aid + ' not included');
  ACCS.add(
                     New Account(
                        First_Contact__c = Null ,
                        Id=aid)
                );
 
  }
}
      
       update ACCS; 










}
else
{
System.debug('UpdateFirstContactOfAccount STOPPED BECAUSE OF REC LIMIT');
}


}
  • October 17, 2014
  • Like
  • 0

Is it possible to write apex code to see if the current user has 'read all access' (not just accessibility, which is 'read' access to records he or his subordinates own).
To check for read access to Account objects, for example, you do this:

boolean mayAccessAccounts = Schema.sObjectType.Account.isAccessible();

Is it necessary to check the user's profile for the 'read all access' capability (I assume there is code to do that but I haven't found any), and also check the various permission sets for him to see if any of them have it?   Seems like a simpler API should exist...
 

Does anyone know a way for my Apex code to determine the difference in being logged in as a standard Salesforce user, versus an Admin user that logged in and in their admin session logged in as that user?

 

Thanks,

David Wright, Gerson Lehrman Group

 

Does anyone have an example you're willing to share of creating a task from Apex code and attaching multiple contacts?

 

My Salesforce profile called 'Sales'  has no CRUD access to a custom object called Global_Opportunity__c.  But when I run the following test code:

 

@isTest
2 private class TestGlobalOpportunityTrigger {

3     static testMethod void salesPersonCantCreateGlobalOpportunity() {

4         User salesUser = [SELECT id FROM User where Profile.Name = 'Sales' AND IsActive=true LIMIT 1];

5         Global_Opportunity__c go = new Global_Opportunity__c(Amount__c = 120000);
6         try {
7           System.runAs(salesUser) {
8           insert go;
9           System.assert(false, 'Sales user was unexpectedly able to create Global_Opportunity id=' + go.Id);

10       }
11    }
12   catch(DmlException excep) {
13       System.debug('got expected excep: ' + excep.getMessage());
14    }

15  }

16 }

 

Instead of failing the insert as expected and exeecuting line 13, the system executes line 9.

I tried setting the sharing mode to Public Read-only access but this did not solve the problem.

Any ideas?

 

Thanks,

David Wright