Skip to main content
Commonmark migration
Source Link

On my lightning component I have function that calls to server side function to create a case

Controller.apxc

public class CommunityCaseFormController {

    @AuraEnabled
    public static Id createCase(Case c) {
        try {
            insert c;
        } catch (Exception e) {
            String message = e.getMessage();
            AuraHandledException auraError = new AuraHandledException(message);
            auraError.setMessage(message);
            throw auraError;                
        }
        
        return c.Id;
    }
}

I'm getting an error message because an admin created a validation rule for cases on creation. The response.getError()[0].message from calling the server function has the error message that is in the validation rule, but is has bunch of extra stuff that the user doesn't need to see, such as.

Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION,

 

.: [Priority]

I could use JavaScript to manipulate the string, but in my opinion that shouldn't be required. How do I get my server-side function to return a cleaner error message?

On my lightning component I have function that calls to server side function to create a case

Controller.apxc

public class CommunityCaseFormController {

    @AuraEnabled
    public static Id createCase(Case c) {
        try {
            insert c;
        } catch (Exception e) {
            String message = e.getMessage();
            AuraHandledException auraError = new AuraHandledException(message);
            auraError.setMessage(message);
            throw auraError;                
        }
        
        return c.Id;
    }
}

I'm getting an error message because an admin created a validation rule for cases on creation. The response.getError()[0].message from calling the server function has the error message that is in the validation rule, but is has bunch of extra stuff that the user doesn't need to see, such as.

Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION,

 

.: [Priority]

I could use JavaScript to manipulate the string, but in my opinion that shouldn't be required. How do I get my server-side function to return a cleaner error message?

On my lightning component I have function that calls to server side function to create a case

Controller.apxc

public class CommunityCaseFormController {

    @AuraEnabled
    public static Id createCase(Case c) {
        try {
            insert c;
        } catch (Exception e) {
            String message = e.getMessage();
            AuraHandledException auraError = new AuraHandledException(message);
            auraError.setMessage(message);
            throw auraError;                
        }
        
        return c.Id;
    }
}

I'm getting an error message because an admin created a validation rule for cases on creation. The response.getError()[0].message from calling the server function has the error message that is in the validation rule, but is has bunch of extra stuff that the user doesn't need to see, such as.

Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION,

.: [Priority]

I could use JavaScript to manipulate the string, but in my opinion that shouldn't be required. How do I get my server-side function to return a cleaner error message?

deleted 78 characters in body
Source Link
Tyler Zika
  • 2.9k
  • 5
  • 45
  • 93

On my lightning component I have function that calls to server side function to create a case

Controller.apxc

public class CommunityCaseFormController {

    @AuraEnabled
    public static Id createCase(Case c) {
        try {
            insert c;
        } catch (Exception e) {
            String message = e.getMessage();
            AuraHandledException auraError = new AuraHandledException(message);
            auraError.setMessage(message);
            throw auraError;                
        }
        
        return c.Id;
    }
}

I'm getting an error message because an admin created a validation rule for cases on creation. The response.getError()[0].message from calling the server function is returning an array with a property message that returns a string. This string does havehas the error message that is in the validation rule, but is has bunch of extra stuff that the user doesn't need to see, such as.

Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION,

.: [Priority]

I could use JavaScript to manipulate the string, but in my opinion that shouldn't be required. How do I get my server-side function to return a cleaner error message?

On my lightning component I have function that calls to server side function to create a case

Controller.apxc

public class CommunityCaseFormController {

    @AuraEnabled
    public static Id createCase(Case c) {
        try {
            insert c;
        } catch (Exception e) {
            String message = e.getMessage();
            AuraHandledException auraError = new AuraHandledException(message);
            auraError.setMessage(message);
            throw auraError;                
        }
        
        return c.Id;
    }
}

I'm getting an error message because an admin created a validation rule for cases on creation. The response.getError() from calling the server function is returning an array with a property message that returns a string. This string does have the error message that is in the validation rule, but is has bunch of extra stuff that the user doesn't need to see, such as.

Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION,

.: [Priority]

I could use JavaScript to manipulate the string, but in my opinion that shouldn't be required. How do I get my server-side function to return a cleaner error message?

On my lightning component I have function that calls to server side function to create a case

Controller.apxc

public class CommunityCaseFormController {

    @AuraEnabled
    public static Id createCase(Case c) {
        try {
            insert c;
        } catch (Exception e) {
            String message = e.getMessage();
            AuraHandledException auraError = new AuraHandledException(message);
            auraError.setMessage(message);
            throw auraError;                
        }
        
        return c.Id;
    }
}

I'm getting an error message because an admin created a validation rule for cases on creation. The response.getError()[0].message from calling the server function has the error message that is in the validation rule, but is has bunch of extra stuff that the user doesn't need to see, such as.

Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION,

.: [Priority]

I could use JavaScript to manipulate the string, but in my opinion that shouldn't be required. How do I get my server-side function to return a cleaner error message?

Source Link
Tyler Zika
  • 2.9k
  • 5
  • 45
  • 93

return clean error message from server side function

On my lightning component I have function that calls to server side function to create a case

Controller.apxc

public class CommunityCaseFormController {

    @AuraEnabled
    public static Id createCase(Case c) {
        try {
            insert c;
        } catch (Exception e) {
            String message = e.getMessage();
            AuraHandledException auraError = new AuraHandledException(message);
            auraError.setMessage(message);
            throw auraError;                
        }
        
        return c.Id;
    }
}

I'm getting an error message because an admin created a validation rule for cases on creation. The response.getError() from calling the server function is returning an array with a property message that returns a string. This string does have the error message that is in the validation rule, but is has bunch of extra stuff that the user doesn't need to see, such as.

Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION,

.: [Priority]

I could use JavaScript to manipulate the string, but in my opinion that shouldn't be required. How do I get my server-side function to return a cleaner error message?