• Holly Havelka 17
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
Hi everyone,

I have created a controller, but now need to add in FLS and CRUD enforcement.  I have checked the documentation, but have not found anything around enforcing FLS and CRUD for returning a public static list.

Can someone help me figure out how to add in the right FLS and CRUD security?

Here is my controller:
public with sharing class AllContactOppsController{
    public static Map<Id, String> recordtypemap {get;set;}
    
    @AuraEnabled    
    public static List<Object> myOpps(String currentRecordId) {
        List<OpportunityContactRole> oppresults = [SELECT Contact.name, Role, OpportunityId, Opportunity.CloseDate, Opportunity.allcontactopps__Record_Url__c, Opportunity.Amount,Opportunity.Name, Opportunity.StageName, Opportunity.Type FROM OpportunityContactRole WHERE contact.accountid=:currentRecordId]; 
        return oppresults;
    }
    
    @AuraEnabled        
    public static List<String> fetchRecordTypeValues(){
        List<Schema.RecordTypeInfo> recordtypes = Opportunity.SObjectType.getDescribe().getRecordTypeInfos();    
        recordtypemap = new Map<Id, String>();
        for(RecordTypeInfo rt : recordtypes){
            if(rt.getName() != 'Master')
            recordtypemap.put(rt.getRecordTypeId(), rt.getName());
        }        
        return recordtypemap.values();
    }
    
    @AuraEnabled
    public static Id getRecTypeId(String recordTypeLabel){
        Id recid = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get(recordTypeLabel).getRecordTypeId();        
        return recid;
    }   
}
Thanks,
Holly


 
Hello all,

Having an issue with my first test class failing.  Need help on setting a specific time in my mock data for the test to not fail.

Here is my class:
public class DateHelper {
  public static Long GetTimeStampFromDate(Date inputDate) {
    Long timeStamp = 0;
    DateTime dt;

    if (inputDate == null)
      return timeStamp;

    dt = Datetime.newInstance(
      inputDate.year(),
      inputDate.month(),
      inputDate.day()
    );

    timeStamp = dt.getTime();

    return timeStamp;
  }
}
Here is my test class:
@isTest
public class DateHelperTests {
  @isTest
  static void GivenAValidDateInput_GetTimeStampFromDate_ShouldReturnValidTimeStamp() {
    //Arrange
    Date inputDate = Date.newInstance(2019, 10, 21);
    Long expectedResult = long.valueOf('1571630400000');

    //Act
    Long actualResult = DateHelper.GetTimeStampFromDate(inputDate);

    System.assert(expectedResult == actualResult);
  }

  @isTest
  static void GivenNullDateInput_GetTimeStampFromDate_ShouldReturnZero() {
    //Arrange
    Long expectedResult = 0;

    //Act
    Long actualResult = DateHelper.GetTimeStampFromDate(null);

    System.assert(expectedResult == actualResult);
  }
}
Any help is much appreciated!

 
Hi everyone,

I have created a controller, but now need to add in FLS and CRUD enforcement.  I have checked the documentation, but have not found anything around enforcing FLS and CRUD for returning a public static list.

Can someone help me figure out how to add in the right FLS and CRUD security?

Here is my controller:
public with sharing class AllContactOppsController{
    public static Map<Id, String> recordtypemap {get;set;}
    
    @AuraEnabled    
    public static List<Object> myOpps(String currentRecordId) {
        List<OpportunityContactRole> oppresults = [SELECT Contact.name, Role, OpportunityId, Opportunity.CloseDate, Opportunity.allcontactopps__Record_Url__c, Opportunity.Amount,Opportunity.Name, Opportunity.StageName, Opportunity.Type FROM OpportunityContactRole WHERE contact.accountid=:currentRecordId]; 
        return oppresults;
    }
    
    @AuraEnabled        
    public static List<String> fetchRecordTypeValues(){
        List<Schema.RecordTypeInfo> recordtypes = Opportunity.SObjectType.getDescribe().getRecordTypeInfos();    
        recordtypemap = new Map<Id, String>();
        for(RecordTypeInfo rt : recordtypes){
            if(rt.getName() != 'Master')
            recordtypemap.put(rt.getRecordTypeId(), rt.getName());
        }        
        return recordtypemap.values();
    }
    
    @AuraEnabled
    public static Id getRecTypeId(String recordTypeLabel){
        Id recid = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get(recordTypeLabel).getRecordTypeId();        
        return recid;
    }   
}
Thanks,
Holly


 
Hello all,

Having an issue with my first test class failing.  Need help on setting a specific time in my mock data for the test to not fail.

Here is my class:
public class DateHelper {
  public static Long GetTimeStampFromDate(Date inputDate) {
    Long timeStamp = 0;
    DateTime dt;

    if (inputDate == null)
      return timeStamp;

    dt = Datetime.newInstance(
      inputDate.year(),
      inputDate.month(),
      inputDate.day()
    );

    timeStamp = dt.getTime();

    return timeStamp;
  }
}
Here is my test class:
@isTest
public class DateHelperTests {
  @isTest
  static void GivenAValidDateInput_GetTimeStampFromDate_ShouldReturnValidTimeStamp() {
    //Arrange
    Date inputDate = Date.newInstance(2019, 10, 21);
    Long expectedResult = long.valueOf('1571630400000');

    //Act
    Long actualResult = DateHelper.GetTimeStampFromDate(inputDate);

    System.assert(expectedResult == actualResult);
  }

  @isTest
  static void GivenNullDateInput_GetTimeStampFromDate_ShouldReturnZero() {
    //Arrange
    Long expectedResult = 0;

    //Act
    Long actualResult = DateHelper.GetTimeStampFromDate(null);

    System.assert(expectedResult == actualResult);
  }
}
Any help is much appreciated!

 
Hi All,

Let me preface this with a disclaimer. I am fairly new to SalesForce development. But I have 11 years experience as a developer.

I am working on a LWC that calls an Apex controller.

The Apex controller runs a fairly simple SOQL query against a custom object Move_Type__c. It has a master detail relationship with another Custom object Move_Goal_Type__c (see below)

Move_Type & Move_Goal_Type

Here is the query: 
[SELECT Name, Id
FROM pursue02__Move_Type__c
WHERE pursue02__Move_Goal_Type__r.Id = :movegoalTypeId ]
The variable comes into the controller (MoveTypeController) as an Id through a method getMoveTypesByMoveGoalTypeId which is decorated with @AuraEnabled(cacheable=true)

When I execute anonynmous, it works as expected, I get a list of Move_Type__c records with the Name and Id.

When the LWC calls it, it returns an empty array. Now I have debugged the method System.debug(movegoalTypeId) and it shows the correct value. And I assigned the SOQL results to a variable and output that as well, it shows values in the debug logs.

I have also checked the network traffic via chrome developer tools and it's sending the value as expected:
message: {
    "actions": [
        {
            "id": "815;a",
            "descriptor": "aura://ApexActionController/ACTION$execute",
            "callingDescriptor": "UNKNOWN",
            "params": {
                "namespace": "pursue02",
                "classname": "MoveTypeController",
                "method": "getMoveTypesByMoveGoalTypeId",
                "params": {
                    "goalTypeId": "a013k00000aWHa6AAG"
                },
                "cacheable": true,
                "isContinuation": false
            }
        }
    ]
}
But as I said it returns an empty array:
"actions": [
        {
            "id": "815;a",
            "state": "SUCCESS",
            "returnValue": {
                "returnValue": [],
                "cacheable": true
            },
            "error": []
        }
    ],
We have checked the permissions on both Move_Type__c and Move_Goal_Type__c, and they all appear to be correct.

Any one know what we are doing wrong? I'm scratching my head on this one.

Any help would be greatly appreciated!