0

I am writing for the simple triger created. I don't understand why i am getting this error while all I am trying to do is create account record with one field name?

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Length of name is greater than 30. Please removenull Charachters from Account Name: [Name]

Below is the code I have written

@istest

public class TestNameLengthCount {

    static testMethod void testNameLemgthCount()
    {
        Account a = new account( Name='TestAccountNameLengthTestRecordsdsd' );
        insert a;

    }

}
  • 2
    Hi Ricky. Can you post the error message as well? – Ruslan Vekua Aug 6 '15 at 18:10
  • Error message please – Anitha J J Aug 6 '15 at 18:10
  • The account name is empty so that's why you are getting kind of error – Ruslan Vekua Aug 6 '15 at 18:15
  • Did you Try to pass atleast some value for Name as this is test class only? – Anitha J J Aug 6 '15 at 18:15
  • 1
    You are getting the error due to the validation rule. You question does not make sense as it looks like you are testing that the validation rule fires yet it seems you are expecting the record to be inserted.... – Eric Aug 6 '15 at 18:20
1

Apparently you have a validation rule where the message seems conflicting.

At one point it says it is > 30 characters but it shows null as part of the message.

if you are not testing the validation rule then try:

@istest

    public class TestNameLengthCount {

        static testMethod void testNameLemgthCount()
        {
            Account a = new account( Name='TestAccountNameLengthTestRecordsdsd' );
            insert a;        
        }

    }

if you are testing the validation rule then do this

@istest

    public class TestNameLengthCount {

        static testMethod void testNameLemgthCount()
        {
                Account a = new account( Name='TestAccountNameLengthTestRecordsdsd' );
                insert a;        

            try{
              insert a;
              system.assertEquals(false,true,'We ere expecting an error to be thrown');
            }catch(DMLException e){
               system.assertEquals(true,e.getDMLMessage(0).contains('Length of name'));
            }

        }

    }
  • I have edited my question with changed code. That was actually old code I tried – Ricky Aug 6 '15 at 18:16
  • @Ricky - See my update answer I was typing as you commented - I thought you may be testing for the error – Eric Aug 6 '15 at 18:18
  • I am getting this error message with your code. expecting a right parentheses, found ';' – Ricky Aug 6 '15 at 18:21
  • Updated.....Missed a ) and added the name to match your new post – Eric Aug 6 '15 at 18:23
  • Ohh man your comment actually triggered something in my mind. I was doing it all wrong. I am not suppose to enter that long name while main trigger I am writing the test class for is to limit under 30 . – Ricky Aug 6 '15 at 18:26
0

As error says, Name field is having more than 30 characters. Reduce the character and try..

  • This would be more suited for a comment, not so much an answer. That's why someone downvoted you – EricSSH Aug 6 '15 at 18:35
  • Your answer is unclear. It doesn't solve the problem – Ruslan Vekua Aug 6 '15 at 18:39
  • @Anitha you are correct. I was little confused. And was doing that silly mistake . – Ricky Aug 6 '15 at 18:40
  • @EricSSH ,@Ruslan Vekua, I will comment in comment section if it's not sure. Thanks :) – Anitha J J Aug 6 '15 at 18:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.