• Nyssa
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

Hello,

 

I'm trying to create a simple trigger that will add a hyphen to a custom field. I am using the following code for the trigger:

 

trigger MyTrigger on My_Object__c (before insert, before update) {
for (Integer i=0;i<Trigger.new.size();i++) {
String tmp = Trigger.new[i].My_Field__c;
if ((tmp != null) && (tmp.length() == 9)) {
tmp = tmp.substring(0,3)+'-'+tmp.substring(3,5);
Trigger.new[i].My_Field__c = tmp;
}
}
}

 

And I have the following test case, which runs fine with 0 lines not tested, 100% covered:

 

public with sharing class TestCase {
public static testMethod void testMyTrigger() {
My_Object__c someObject = new My_Object__c();
someObject.Name = 'testing';
insert someObject;
someObject.My_Field__c = '12345';
update someObject;

My_Object__c out = [select My_Field__c from My_Object__c where Id = :someObject.Id];
System.assertEquals('123-45', out.My_Field__c);
}
}

 

And when I try to save in Eclipse 3.4.2 with Salesforce plugin version 16.0.0.200906151227 I get the "Unable to perform save on all files" error. If I comment out the line in the trigger with the substring(), it saves fine. If I uncomment it, I get the error again. What is going on?

Message Edited by Nyssa on 03-09-2010 10:45 PM
  • March 09, 2010
  • Like
  • 0

Hello,

 

I'm trying to create a simple trigger that will add a hyphen to a custom field. I am using the following code for the trigger:

 

trigger MyTrigger on My_Object__c (before insert, before update) {
for (Integer i=0;i<Trigger.new.size();i++) {
String tmp = Trigger.new[i].My_Field__c;
if ((tmp != null) && (tmp.length() == 9)) {
tmp = tmp.substring(0,3)+'-'+tmp.substring(3,5);
Trigger.new[i].My_Field__c = tmp;
}
}
}

 

And I have the following test case, which runs fine with 0 lines not tested, 100% covered:

 

public with sharing class TestCase {
public static testMethod void testMyTrigger() {
My_Object__c someObject = new My_Object__c();
someObject.Name = 'testing';
insert someObject;
someObject.My_Field__c = '12345';
update someObject;

My_Object__c out = [select My_Field__c from My_Object__c where Id = :someObject.Id];
System.assertEquals('123-45', out.My_Field__c);
}
}

 

And when I try to save in Eclipse 3.4.2 with Salesforce plugin version 16.0.0.200906151227 I get the "Unable to perform save on all files" error. If I comment out the line in the trigger with the substring(), it saves fine. If I uncomment it, I get the error again. What is going on?

Message Edited by Nyssa on 03-09-2010 10:45 PM
  • March 09, 2010
  • Like
  • 0