• JosherPack
  • NEWBIE
  • 25 Points
  • Member since 2015
  • Salesforce Engineer
  • FamilySearch


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies
Use Case: I have users that need to be admins in the sandbox, but not in production.  I have written a SandboxPostCopy apex class to:
  1. Make them active in the sandbox
  2. Update their Profile to System Administrator
  3. Change their Sandbox email to their real email
I got the class, and the test to work, when I hard coded individuals names and emails.  I am writing this new class to do the same thing by simply checking a custom field I created on their user account called Make Sandbox Admin.

My class and test are below.  The test passes, but shows 0% code coverage.  As I am new to apex development, any help with this will be greatly appreciated.


global class AfterSandboxRefresh implements SandboxPostCopy {
  global void runApexClass(SandboxContext context) {

    //Pull System Administrator Profile
        Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];       
        
  //Pull Users to Make Sandbox Admin
        List<User> listOfUsers = new List<User>();

    List<User> UsersToUpdate = [SELECT Id,Email, FederationIdentifier
                    FROM User
                   WHERE Make_Sandbox_Admin__c = True];

    For (User u : UsersToUpdate) {
      u.ProfileId = p.Id;
            u.isActive  = True;
                String e1 = u.email;
              String e2 = e1.remove('@example.com');
              String target = '=';
              String replacement = '@';
              String e3 = e2.replace(target, replacement);
            u.Email = e3;
      listOfUsers.add(u);            
    }
  Update(listOfUsers);
    }
}




@isTest
class AfterSandboxRefreshTest
{
  @isTest
  static void testSandboxPostCopyScript() 
  {
  
    //Pull System Administrator Profile
        Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];       
        
  //Pull Users to Make Sandbox Admin
        List<User> listOfUsers = new List<User>();

    List<User> UsersToUpdate = [SELECT Id,Email, FederationIdentifier
                    FROM User
                   WHERE Make_Sandbox_Admin__c = True];

    For (User u : UsersToUpdate) {
      u.ProfileId = p.Id;
            u.isActive  = True;
                String e1 = u.email;
              String e2 = e1.remove('@example.com');
              String target = '=';
              String replacement = '@';
              String e3 = e2.replace(target, replacement);
            u.Email = e3;
      listOfUsers.add(u);            
    }
  Update(listOfUsers);
    
    
    Test.startTest();
    
      // Using any Ids as orgId and sandboxId for test, e.g. Account Ids 
      // Id possible pass valid id
      Test.testSandboxPostCopyScript(
        new SandboxRefresh(), 
        '00Dj0000001srun', 
        '00Dm00000008k1D', 
        'MySandboxName'
      ); 
      
    Test.stopTest();
    
  }
}
 
1) I used use Module3RegistrationHandler.cls as registration handler.
2) I selected Google as login capability for Partners ( cf screenshot below)
However, the challenge fails with the following message :
Challenge Not yet complete... here's what's wrong:  Could not find a login to your community using Google.
Anybody can help ?
Thanks :-)
"Login & Registration" page
Use Case: I have users that need to be admins in the sandbox, but not in production.  I have written a SandboxPostCopy apex class to:
  1. Make them active in the sandbox
  2. Update their Profile to System Administrator
  3. Change their Sandbox email to their real email
I got the class, and the test to work, when I hard coded individuals names and emails.  I am writing this new class to do the same thing by simply checking a custom field I created on their user account called Make Sandbox Admin.

My class and test are below.  The test passes, but shows 0% code coverage.  As I am new to apex development, any help with this will be greatly appreciated.


global class AfterSandboxRefresh implements SandboxPostCopy {
  global void runApexClass(SandboxContext context) {

    //Pull System Administrator Profile
        Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];       
        
  //Pull Users to Make Sandbox Admin
        List<User> listOfUsers = new List<User>();

    List<User> UsersToUpdate = [SELECT Id,Email, FederationIdentifier
                    FROM User
                   WHERE Make_Sandbox_Admin__c = True];

    For (User u : UsersToUpdate) {
      u.ProfileId = p.Id;
            u.isActive  = True;
                String e1 = u.email;
              String e2 = e1.remove('@example.com');
              String target = '=';
              String replacement = '@';
              String e3 = e2.replace(target, replacement);
            u.Email = e3;
      listOfUsers.add(u);            
    }
  Update(listOfUsers);
    }
}




@isTest
class AfterSandboxRefreshTest
{
  @isTest
  static void testSandboxPostCopyScript() 
  {
  
    //Pull System Administrator Profile
        Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];       
        
  //Pull Users to Make Sandbox Admin
        List<User> listOfUsers = new List<User>();

    List<User> UsersToUpdate = [SELECT Id,Email, FederationIdentifier
                    FROM User
                   WHERE Make_Sandbox_Admin__c = True];

    For (User u : UsersToUpdate) {
      u.ProfileId = p.Id;
            u.isActive  = True;
                String e1 = u.email;
              String e2 = e1.remove('@example.com');
              String target = '=';
              String replacement = '@';
              String e3 = e2.replace(target, replacement);
            u.Email = e3;
      listOfUsers.add(u);            
    }
  Update(listOfUsers);
    
    
    Test.startTest();
    
      // Using any Ids as orgId and sandboxId for test, e.g. Account Ids 
      // Id possible pass valid id
      Test.testSandboxPostCopyScript(
        new SandboxRefresh(), 
        '00Dj0000001srun', 
        '00Dm00000008k1D', 
        'MySandboxName'
      ); 
      
    Test.stopTest();
    
  }
}
 
How do I check my API usage, I am not sure what is making all the calls and I am getting this notification everyday now. The monitoring report does not give me enough information to fix this issue.

"Your organization has made 13783 API calls within the last 24 hours. This is 92% of your organization's 24-hour API call limit of 15000 calls. You will receive this notice once every 24 hours until your organization's API usage drops below 85% of your 24-hour call limit (12750 calls).

For more detail on your organization's API usage, please review the API Usage Report under the Reports tab.

If you wish to review or change your notifications, the settings can be found in Setup under Administration Setup > Monitoring > View API Usage Notifications.

This email and any attachments thereto may contain private, confidential, and privileged material for the sole use of the intended recipient. Any unauthorized use, copying, or distribution of this email or its attachments is strictly prohibited. If you are not the intended recipient of this email, please delete this email and contact the sender immediately."