You need to sign in to do that
Don't have an account?
John L Schneider II
As the topic says, this works when I create a record through the GUI but not when loading records through Data Loader (CLI Batch or Bulk).
I am attempting to split the value in LastName whenever the FirstName is blank and the LastName has a space in it.
Apex Trigger works for records created in GUI but not through API
trigger Contact on Contact (before insert, before update) { for (Contact c1 : trigger.new) { string fullname = c1.LastName; string firstname = c1.FirstName; if( fullname.containsWhitespace() == true ) { if (String.isBlank(firstname) == true) { string fn; string ln; fn = fullname.substring(0,fullname.indexOf(' ')); ln = fullname.substring(fullname.indexOf(' ')+1); c1.LastName = ln; c1.FirstName = fn; } } } }
As the topic says, this works when I create a record through the GUI but not when loading records through Data Loader (CLI Batch or Bulk).
I am attempting to split the value in LastName whenever the FirstName is blank and the LastName has a space in it.
All Answers
It is working for small batches.
Let me know the result.
Best,
Nithesh
So, When doing fullname.containsWhitespace() , it is throwing null pointer exception.
Lets add
But its Strange, Contact last name wont be null, Since its a required field and System Validation Rule will catch it. Do you hae any idea which particular records were causing this problem. Try adding System.Debug(c1) in the third line. We can make changes accordingly.
Best,
Nithesh
Also, you don't need to add == TRUE in the IF condition block, as these functions return boolean type only. So:
line 6 could be : if( fullname.containsWhitespace() )
and line 8 : if (String.isBlank(firstname) )