You need to sign in to do that
Don't have an account?
isBlank in Apex "Method does not exist"??
I have an extremely basic trigger that is designed to delete any task with a blank subject when it's created:
trigger deleteBlankSubjects on Task (after insert){ list<Task> records = trigger.new; list<Task> deletable = new list<Task>(); for(Task t : records){ if(t.Subject == null || isBlank(t.Subject)){ deletable.add(t); } } delete deletable; }
For some reason though, whenever I write out the isBlank() method, I get the error, "Save error: Method does not exist or incorrect signature: isBlank(String)".
I've tried writing it a bunch of different ways now, and every time I get the same error. What's worse, is that I can't seem to find any examples of people using the APEX .isBlank() method on google (where I usually turn when I'm stuck), even though the APEX Handbook says it's perfectly allowable. What am I doing wrong here??? Totally confused.
I'm using Eclipse if it's of any help. Any insight from any guru's out there would be HUGELY appreciated.
You must do:
string.isBlank(t.Subject)
All Answers
You must do:
string.isBlank(t.Subject)
Oh wow, that worked! Thanks Max!!
I'm still kind of confused though... how come the "return type" is Boolean (in the APEX guide), yet I need to put "string" before ".isBlank"? I kept writting boolean.isBlank(t.Subject) in my other variations of trying to make this work, but I never tried string because I thought that wasn't the right return type. Is the method actually returning a string value that says "true" or "false"?
Thanks again!
You are calling a static method in the string class that takes a string argument and returns a boolean.
This would be valid:
string s = 'test string'
boolean b = string.isBlank(s);
b would be boolean false because s (the string that was passed to the isBlank constructor) is not blank. The returned result really is a boolean value, not a string containing the word false.
string s = ''
boolean b = string.isBlank(s);
Here b would be boolean true because s is blank.
Also, I highly recommend you go here:
docs.oracle.com/javase/tutorial/java/javaOO/index.html
and review everything under the subheadings Classes, Objects, and More On Classes. Everything in Apex is a class or instance of a class (object), even if this is not always obvious, so the better you understand the easier life will be!
Ohhhhhhhhhhhhhh, geeze... talk about feeling like I just got hit in the head with a lightning bolt. Suddenly a lot of different things that have always seemed kind of confusing to me have just come into total clerity. So if a variable has already been declared (say a string) and you're performing a "variable.method(argument)" or "variable.method()" method on it, Eclipse knows you're referncing the String class because you declared it earlier when you made that variable that you're now including in your method. But if you haven't declared the data type (which identifies the class that contains that method) then you need to declare it before you write the ".method" or else the system won't know where to go in order to find the class that contains the method.
Man... talk about a "duhhh" moment, but thanks so much for clearing that up for me, you rock!
What you have described is the difference between a static method and instance method. I am sure this is explained better online than I can explain, but it is important to understand so please seek it out.
Will do. Thanks!