You need to sign in to do that
Don't have an account?
rosh
test class? Please help me with class?
public with sharing class SFDCAccessControlException extends Exception {
/**
* ExceptionType - this enum defines the different types of access control exceptions.
*/
public enum ExceptionType {
/**
* This error is a generic error type.
*/
GENERIC,
/**
* This error type is an object level access violation.
*/
OBJECT_ACCESS_VIOLATION,
/**
* This error type is a field level access violation.
*/
FIELD_ACCESS_VIOLATION,
/**
* This error type is a sharing access violation.
*/
SHARING_ACCESS_VIOLATION,
/**
* This error type is a generic record not found error. This can be due to record does not exist, sharing violation, or other errors.
*/
NO_RECORD_FOUND,
/**
* This error type is a generic field not found error.
*/
FIELD_NOT_FOUND}
/**
* ExceptionReason - this enum defines the different reasons for the exception type.
*/
public enum ExceptionReason {
/**
* This is a generic reason.
*/
GENERIC,
/**
* This error is due to the user not having the create permission on the specific object/field/record.
*/
NO_CREATE,
/**
* This error is due to the user not having the read permission on the specific object/field/record.
*/
NO_READ,
/**
* This error is due to the user not having the update permission on the specific object/field/record.
*/
NO_UPDATE,
/**
* This error is due to the user not having the delete permission on the specific object/field/record.
*/
NO_DELETE}
private ExceptionType eType;
private ExceptionReason eReason;
private String eObject;
private String eField;
private String eText;
/**
* Constructor for SFDCAccessControlException.
* @param eText Error text
* @param eType ExceptionType for this error
* @param eReason ExceptionReason for this error
* @param eObject The object name this error was triggered on
* @param eField The field name this error was triggered on
*/
public SFDCAccessControlException(String eText, ExceptionType eType, ExceptionReason eReason, String eObject, String eField) {
this.eText = eText;
this.eType = eType;
this.eReason = eReason;
this.eObject = eObject;
this.eField = eField;
System.debug(this);
}
/**
* Get the exception type - Object Access Violation, Field Access Violation, etc.
* You might not want to expose the details of the exception to the users.
* Note : to avoid XSS, make sure to escape text before presenting it to the user.
*/
public ExceptionType getExceptionType() {
return this.eType;
}
/**
* Get the exception reason - no create, no update, etc.
* You might not want to expose the details of the exception to the users.
* Note : to avoid XSS, make sure to escape text before presenting it to the user.
*/
public ExceptionReason getExceptionReason() {
return this.eReason;
}
/**
* Get the object on which the exception occurred.
* You might not want to expose the details of the exception to the users.
* Note : to avoid XSS, make sure to escape text before presenting it to the user.
*/
public String getExceptionObject() {
return this.eObject;
}
/**
* Get the field on which the exception occurred.
* You might not want to expose the details of the exception to the users.
* Note : to avoid XSS, make sure to escape text before presenting it to the user.
*/
public String getExceptionField() {
return this.eField;
}
/**
* Get the error text.
* You might not want to expose the details of the exception to the users.
* Note : to avoid XSS, make sure to escape text before presenting it to the user.
*/
public String getText() {
return this.eText;
}
/**
* Get the error text.
* You might not want to expose the details of the exception to the users.
* Note : to avoid XSS, make sure to escape text before presenting it to the user.
*/
public override String getMessage() {
return this.eText + ':: ' + this.eReason + ' access violation for ' + this.getExceptionObject() + '.' + this.getExceptionField();
}
}
/**
* ExceptionType - this enum defines the different types of access control exceptions.
*/
public enum ExceptionType {
/**
* This error is a generic error type.
*/
GENERIC,
/**
* This error type is an object level access violation.
*/
OBJECT_ACCESS_VIOLATION,
/**
* This error type is a field level access violation.
*/
FIELD_ACCESS_VIOLATION,
/**
* This error type is a sharing access violation.
*/
SHARING_ACCESS_VIOLATION,
/**
* This error type is a generic record not found error. This can be due to record does not exist, sharing violation, or other errors.
*/
NO_RECORD_FOUND,
/**
* This error type is a generic field not found error.
*/
FIELD_NOT_FOUND}
/**
* ExceptionReason - this enum defines the different reasons for the exception type.
*/
public enum ExceptionReason {
/**
* This is a generic reason.
*/
GENERIC,
/**
* This error is due to the user not having the create permission on the specific object/field/record.
*/
NO_CREATE,
/**
* This error is due to the user not having the read permission on the specific object/field/record.
*/
NO_READ,
/**
* This error is due to the user not having the update permission on the specific object/field/record.
*/
NO_UPDATE,
/**
* This error is due to the user not having the delete permission on the specific object/field/record.
*/
NO_DELETE}
private ExceptionType eType;
private ExceptionReason eReason;
private String eObject;
private String eField;
private String eText;
/**
* Constructor for SFDCAccessControlException.
* @param eText Error text
* @param eType ExceptionType for this error
* @param eReason ExceptionReason for this error
* @param eObject The object name this error was triggered on
* @param eField The field name this error was triggered on
*/
public SFDCAccessControlException(String eText, ExceptionType eType, ExceptionReason eReason, String eObject, String eField) {
this.eText = eText;
this.eType = eType;
this.eReason = eReason;
this.eObject = eObject;
this.eField = eField;
System.debug(this);
}
/**
* Get the exception type - Object Access Violation, Field Access Violation, etc.
* You might not want to expose the details of the exception to the users.
* Note : to avoid XSS, make sure to escape text before presenting it to the user.
*/
public ExceptionType getExceptionType() {
return this.eType;
}
/**
* Get the exception reason - no create, no update, etc.
* You might not want to expose the details of the exception to the users.
* Note : to avoid XSS, make sure to escape text before presenting it to the user.
*/
public ExceptionReason getExceptionReason() {
return this.eReason;
}
/**
* Get the object on which the exception occurred.
* You might not want to expose the details of the exception to the users.
* Note : to avoid XSS, make sure to escape text before presenting it to the user.
*/
public String getExceptionObject() {
return this.eObject;
}
/**
* Get the field on which the exception occurred.
* You might not want to expose the details of the exception to the users.
* Note : to avoid XSS, make sure to escape text before presenting it to the user.
*/
public String getExceptionField() {
return this.eField;
}
/**
* Get the error text.
* You might not want to expose the details of the exception to the users.
* Note : to avoid XSS, make sure to escape text before presenting it to the user.
*/
public String getText() {
return this.eText;
}
/**
* Get the error text.
* You might not want to expose the details of the exception to the users.
* Note : to avoid XSS, make sure to escape text before presenting it to the user.
*/
public override String getMessage() {
return this.eText + ':: ' + this.eReason + ' access violation for ' + this.getExceptionObject() + '.' + this.getExceptionField();
}
}
The below articles give a good insight into how to get started with writing test classes
https://salesforce.stackexchange.com/questions/244788/how-do-i-write-an-apex-unit-test
https://salesforce.stackexchange.com/questions/244794/how-do-i-increase-my-code-coverage-or-why-cant-i-cover-these-lines
Hope this helps! Thanks
Priya Ranjan