• Temesgennn
  • NEWBIE
  • 30 Points
  • Member since 2021

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

Hi There,


I have been tasked to handle a test for release updates which is (Make Flows Respect Access Modifiers for Legacy Apex Actions). I am new to development and this is my first release updates testing, no idea where to start or what to do. 

How can assess the impact of this release update?
Ensure that all your @AuraEnabled Apex code explicitly controls sharing behavior using the with sharing or without sharing keywords. If all your @AuraEnabled code explicitly sets sharing behavior, this update has no effect.

Any help would be much appreciated, Thank you.

We did a minor modification to our code in the If/Else statement in our class, now I am trying to reach 100% test coverage. As you can see in my test class below, i inserted a new contact as coTeacher and a new class as newCLass and populated the fields with the new contact Ids in newClass, but my test coverage is still at 84%, I am getting the following error:
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_FILTER_VALIDATION_EXCEPTION, This person is not a qualified instructor. Please select a qualified instructor.: [Instructor__c]
What am I missing? any help would be much appreciated.

public class ClassSelectorController {
  public List<Class__c> classes { get; set; }
  String dayFormat = 'MM/DD';
  public Id classId { get; set; }
  public String userEmail { get; set; }
  public String userProfileId;
  public Profile gwCommunityProfile;
  public Id classType { get; set; }

  public ClassSelectorController() {
    userEmail = UserInfo.getUserEmail();
    userProfileId = UserInfo.getProfileId();
    gwCommunityProfile = [
      SELECT Id, Name
      FROM Profile
      WHERE Name = 'GW Community User'
      LIMIT 1
    ];
    System.debug(gwCommunityProfile);
    System.debug(gwCommunityProfile.Id);
    System.debug(userProfileId);
    getClasses();
  }
  public void getClasses() {
    // Limit visibility to GW community user
    if (userProfileId != gwCommunityProfile.Id) {
      classes = [
        SELECT
          id,
          name,
          class_nights__c,
          start_date__c,
          end_date__c,
          status__c,
          class__c,
          instructor__r.email,
          RecordTypeId
        FROM class__c
        WHERE status__c = 'Active'
      ];
      System.debug(classes);
    } else {
      classes = [
        SELECT
          id,
          name,
          class_nights__c,
          start_date__c,
          end_date__c,
          status__c,
          class__c,
          instructor__r.email,
          RecordTypeId
        FROM class__c
        WHERE
          status__c = 'Active'
          AND (instructor__r.Email = :userEmail
          OR Co_Teacher__r.Email = :userEmail
          OR Teachers_Assistant__r.Email = :userEmail)
      ];
      System.debug(classes);
    }
  }

  public Pagereference newPage() {
    Id cohortRecordTypeId = Schema.SObjectType.class__c.getRecordTypeInfosByName()
      .get('Cohort')
      .getRecordTypeId();
    String url = '/apex/BWRoster?id=' + classId;
    if (classType == cohortRecordTypeId) {
      url += '&type=Cohort';
    }

    return new PageReference(url);
  }
}


Test Coverage

@isTest
public class ClassSelectorTest {
    
    static testMethod void testGetClassesGWProfile() {    
        
        Profile gwCommunityProfile = [SELECT Id FROM Profile WHERE Name = 'GW Community User' LIMIT 1];
        Contact teacher = new Contact(FirstName = 'Teacher', LastName = 'Teaher', Email = 'teacher@teacher.com');
        insert teacher;

        Contact coTeacher = new Contact(FirstName = 'co-teacher', LastName = 'co-teacher', Email = 'co-teacher@co-teacher.com');
        insert coTeacher;

         // Contact assistant = new Contact(FirstName = 'assistant', LastName = 'asistant', Email = 'assistant@assistant.com');
         // insert assistant;


        // User gwCommunityUser = new User(FirstName='Teacher', LastName='Teacher', ContactId = teacher.Id, Email='teacher@teacher.com', ProfileId= gwCommunityProfile.Id);
        // insert gwCommunityUser;
    
        // System.debug(gwCommunityUser);

        class__c newClass = new class__c(name = 'Test Class', Instructor__c = teacher.Id, Co_Teacher__c = coTeacher.Id,
        class_nights__c = 'Monday / Wednesday', start_date__c = date.today() - 10, end_date__c = date.today() + 45);
        insert newClass;

        

        ClassSelectorController pc = new ClassSelectorController();
        pc.userEmail = 'teacher@teacher.com';
        
        pc.userProfileId = gwCommunityProfile.Id;
        
        pc.getClasses();
        
        System.assertEquals(1, pc.classes.size());
    }
 @isTest
  public static void testURLIsCohort(){
    String CohortRecordTypeId = Schema.SObjectType.class__c.getRecordTypeInfosByName().get('Cohort').getRecordTypeId();
    class__c newClass = new class__c(name = 'Test Class', RecordTypeId = CohortRecordTypeId, class_nights__c = 'Monday / Wednesday', start_date__c = date.today() - 10, end_date__c = date.today() + 45);
    insert newClass;
    
    CLassSelectorController gwClass = new ClassSelectorController();
    gwClass.classId = newClass.Id;
    gwClass.classType = newClass.RecordTypeId;
    PageReference rosterPage = gwClass.newPage();
    System.assertEquals('/apex/BWRoster?id='+newClass.Id + '&type=Cohort',rosterPage.getUrl());
        
        
    }
}

​​​​​​​

Hi all,

Is it possible to display a spinner while a visualforce component is loading in our Org? We created a visualforce page and used it as a component to display a table for our users. I have tried some solutions but no success so far, my code and solution could be totally wrong i am new to this.

Thank you very much for your help, this is my code:
 

<apex:page standardController="Class__c" extensions="ClassAttendanceTableController" lightningStylesheets="true">

    <head>
        <apex:slds />
    </head>
    <apex:form>
        <style>
                .spinnerBg{
                    width: 100%;
                    height: 100%;
                    position: absolute;
                    background-color: #000;
                    opacity: 0.2;
                    z-index: 999999;
                }
                .spinner{
                    width: 100%;
                    height: 100%;
                    position: absolute;
                    background-image: url("/img/loading32.gif");
                    background-size: 16px;
                    background-repeat: no-repeat;
                    background-attachment: fixed;
                    background-position: center;
                    z-index: 9999999;
                    opacity: 1;
                }
   </style>
   
    <apex:actionStatus id="spinnerStatus">    
                    <apex:facet name="start">
                     <div class="spinnerBg" />
                    <div class="spinner" />
                </apex:facet>
    </apex:actionStatus>
   
     <apex:commandButton action="{!save}" value="Save" status="spinnerStatus" reRender="theForm"/>
        <table class="slds-table slds-table_cell-buffer slds-table_bordered slds-table_col-bordered slds-scrollable" >
            <thead>
                <tr class="slds-line-height_reset">
                    <th scope="col">
                        <div class="slds-truncate" title="Student Name">Student</div>
                    </th>
                    <apex:repeat value="{!attendanceDates}" var="date">
                        <th scope="col">
                            <div class="slds-truncate">
                                <apex:outputText value="{0, date, MMMM d',' yyyy}">
                                    <apex:param value="{!date}" />
                                </apex:outputText>
                            </div>
                        </th>
                    </apex:repeat>
                </tr>
            </thead>
            
            <tbody>
                <apex:repeat value="{!attendanceNames}" var="name">
                    <tr>
                        <td data-label="Student Name" scope="row" class="slds-truncate">
                            <apex:outputText value="{!name}" />
                            <apex:repeat value="{!attendanceRecords}" var="records">
                                <apex:outputPanel rendered="{!name == records.Student__r.name}">
                                    <td data-label="Present">
                                        <apex:inputField value="{!records.Present__c}" id="present" />
                                    </td>
                                </apex:outputPanel>
                            </apex:repeat>
                        </td>
                    </tr>
                </apex:repeat>
                
            </tbody>
            
        </table>
    </apex:form>
    
</apex:page>

Hi There,


I have been tasked to handle a test for release updates which is (Make Flows Respect Access Modifiers for Legacy Apex Actions). I am new to development and this is my first release updates testing, no idea where to start or what to do. 

How can assess the impact of this release update?
Ensure that all your @AuraEnabled Apex code explicitly controls sharing behavior using the with sharing or without sharing keywords. If all your @AuraEnabled code explicitly sets sharing behavior, this update has no effect.

Any help would be much appreciated, Thank you.

We did a minor modification to our code in the If/Else statement in our class, now I am trying to reach 100% test coverage. As you can see in my test class below, i inserted a new contact as coTeacher and a new class as newCLass and populated the fields with the new contact Ids in newClass, but my test coverage is still at 84%, I am getting the following error:
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_FILTER_VALIDATION_EXCEPTION, This person is not a qualified instructor. Please select a qualified instructor.: [Instructor__c]
What am I missing? any help would be much appreciated.

public class ClassSelectorController {
  public List<Class__c> classes { get; set; }
  String dayFormat = 'MM/DD';
  public Id classId { get; set; }
  public String userEmail { get; set; }
  public String userProfileId;
  public Profile gwCommunityProfile;
  public Id classType { get; set; }

  public ClassSelectorController() {
    userEmail = UserInfo.getUserEmail();
    userProfileId = UserInfo.getProfileId();
    gwCommunityProfile = [
      SELECT Id, Name
      FROM Profile
      WHERE Name = 'GW Community User'
      LIMIT 1
    ];
    System.debug(gwCommunityProfile);
    System.debug(gwCommunityProfile.Id);
    System.debug(userProfileId);
    getClasses();
  }
  public void getClasses() {
    // Limit visibility to GW community user
    if (userProfileId != gwCommunityProfile.Id) {
      classes = [
        SELECT
          id,
          name,
          class_nights__c,
          start_date__c,
          end_date__c,
          status__c,
          class__c,
          instructor__r.email,
          RecordTypeId
        FROM class__c
        WHERE status__c = 'Active'
      ];
      System.debug(classes);
    } else {
      classes = [
        SELECT
          id,
          name,
          class_nights__c,
          start_date__c,
          end_date__c,
          status__c,
          class__c,
          instructor__r.email,
          RecordTypeId
        FROM class__c
        WHERE
          status__c = 'Active'
          AND (instructor__r.Email = :userEmail
          OR Co_Teacher__r.Email = :userEmail
          OR Teachers_Assistant__r.Email = :userEmail)
      ];
      System.debug(classes);
    }
  }

  public Pagereference newPage() {
    Id cohortRecordTypeId = Schema.SObjectType.class__c.getRecordTypeInfosByName()
      .get('Cohort')
      .getRecordTypeId();
    String url = '/apex/BWRoster?id=' + classId;
    if (classType == cohortRecordTypeId) {
      url += '&type=Cohort';
    }

    return new PageReference(url);
  }
}


Test Coverage

@isTest
public class ClassSelectorTest {
    
    static testMethod void testGetClassesGWProfile() {    
        
        Profile gwCommunityProfile = [SELECT Id FROM Profile WHERE Name = 'GW Community User' LIMIT 1];
        Contact teacher = new Contact(FirstName = 'Teacher', LastName = 'Teaher', Email = 'teacher@teacher.com');
        insert teacher;

        Contact coTeacher = new Contact(FirstName = 'co-teacher', LastName = 'co-teacher', Email = 'co-teacher@co-teacher.com');
        insert coTeacher;

         // Contact assistant = new Contact(FirstName = 'assistant', LastName = 'asistant', Email = 'assistant@assistant.com');
         // insert assistant;


        // User gwCommunityUser = new User(FirstName='Teacher', LastName='Teacher', ContactId = teacher.Id, Email='teacher@teacher.com', ProfileId= gwCommunityProfile.Id);
        // insert gwCommunityUser;
    
        // System.debug(gwCommunityUser);

        class__c newClass = new class__c(name = 'Test Class', Instructor__c = teacher.Id, Co_Teacher__c = coTeacher.Id,
        class_nights__c = 'Monday / Wednesday', start_date__c = date.today() - 10, end_date__c = date.today() + 45);
        insert newClass;

        

        ClassSelectorController pc = new ClassSelectorController();
        pc.userEmail = 'teacher@teacher.com';
        
        pc.userProfileId = gwCommunityProfile.Id;
        
        pc.getClasses();
        
        System.assertEquals(1, pc.classes.size());
    }
 @isTest
  public static void testURLIsCohort(){
    String CohortRecordTypeId = Schema.SObjectType.class__c.getRecordTypeInfosByName().get('Cohort').getRecordTypeId();
    class__c newClass = new class__c(name = 'Test Class', RecordTypeId = CohortRecordTypeId, class_nights__c = 'Monday / Wednesday', start_date__c = date.today() - 10, end_date__c = date.today() + 45);
    insert newClass;
    
    CLassSelectorController gwClass = new ClassSelectorController();
    gwClass.classId = newClass.Id;
    gwClass.classType = newClass.RecordTypeId;
    PageReference rosterPage = gwClass.newPage();
    System.assertEquals('/apex/BWRoster?id='+newClass.Id + '&type=Cohort',rosterPage.getUrl());
        
        
    }
}

​​​​​​​

Hi all,

Is it possible to display a spinner while a visualforce component is loading in our Org? We created a visualforce page and used it as a component to display a table for our users. I have tried some solutions but no success so far, my code and solution could be totally wrong i am new to this.

Thank you very much for your help, this is my code:
 

<apex:page standardController="Class__c" extensions="ClassAttendanceTableController" lightningStylesheets="true">

    <head>
        <apex:slds />
    </head>
    <apex:form>
        <style>
                .spinnerBg{
                    width: 100%;
                    height: 100%;
                    position: absolute;
                    background-color: #000;
                    opacity: 0.2;
                    z-index: 999999;
                }
                .spinner{
                    width: 100%;
                    height: 100%;
                    position: absolute;
                    background-image: url("/img/loading32.gif");
                    background-size: 16px;
                    background-repeat: no-repeat;
                    background-attachment: fixed;
                    background-position: center;
                    z-index: 9999999;
                    opacity: 1;
                }
   </style>
   
    <apex:actionStatus id="spinnerStatus">    
                    <apex:facet name="start">
                     <div class="spinnerBg" />
                    <div class="spinner" />
                </apex:facet>
    </apex:actionStatus>
   
     <apex:commandButton action="{!save}" value="Save" status="spinnerStatus" reRender="theForm"/>
        <table class="slds-table slds-table_cell-buffer slds-table_bordered slds-table_col-bordered slds-scrollable" >
            <thead>
                <tr class="slds-line-height_reset">
                    <th scope="col">
                        <div class="slds-truncate" title="Student Name">Student</div>
                    </th>
                    <apex:repeat value="{!attendanceDates}" var="date">
                        <th scope="col">
                            <div class="slds-truncate">
                                <apex:outputText value="{0, date, MMMM d',' yyyy}">
                                    <apex:param value="{!date}" />
                                </apex:outputText>
                            </div>
                        </th>
                    </apex:repeat>
                </tr>
            </thead>
            
            <tbody>
                <apex:repeat value="{!attendanceNames}" var="name">
                    <tr>
                        <td data-label="Student Name" scope="row" class="slds-truncate">
                            <apex:outputText value="{!name}" />
                            <apex:repeat value="{!attendanceRecords}" var="records">
                                <apex:outputPanel rendered="{!name == records.Student__r.name}">
                                    <td data-label="Present">
                                        <apex:inputField value="{!records.Present__c}" id="present" />
                                    </td>
                                </apex:outputPanel>
                            </apex:repeat>
                        </td>
                    </tr>
                </apex:repeat>
                
            </tbody>
            
        </table>
    </apex:form>
    
</apex:page>