• EdL
  • NEWBIE
  • -2 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Hey all,
 
I'm having a lot of trouble with a trigger I wrote.  It works *perfectly* within salesforce, however when I use the Data Loader to get data from a .CSV file, it's like the trigger never even fires.
 
It's designed to change a relationship by moving some information around.  For reference, the Project1 object has a Master-Detail relationship based upon a field called "Project_BEN_Number".  When I perform a bulk data load there are no errors given, the rows insert fine.  The problem is that the code is never executed, or at least the results are never saved.
 
Help!
 
Thanks,
 
EdL
 
 
Trigger Code:
Full disclosure:  I use an upsert to load the data, but it still doesn't work even with a regular insert.
 
Code:
trigger fixType on Resource_Data_Item__c (before insert) {

private Resource_Data_Item__c[] ti = Trigger.new;
try
{
    string initiative = ti[0].Initiative_Number__c;
    if(initiative == 'INIT_NA')
    {
        ti[0].Initiative_Number__c = ti[0].Project_Name__c;
        ti[0].Initiative_Name__c = ti[0].Project_Name__c;
        ti[0].Project_Name__c = ti[0].Task_Name__c;
        ti[0].Project_Number__c = ti[0].Task_Number__c;
        string pID = [select ID from Project1__c where Name = :ti[0].Project_Name__c].ID;
        ti[0].Project__c = pID;
    }
}
catch(Exception ex)
{
    ti[0].addError('Insert error: INIT_NA Task ' + ti[0].Task_Name__c + ' does not exist as a project.' + ex.getMessage());
}


}

 
  • May 27, 2008
  • Like
  • 0
Hey all,
 
I'm having a lot of trouble with a trigger I wrote.  It works *perfectly* within salesforce, however when I use the Data Loader to get data from a .CSV file, it's like the trigger never even fires.
 
It's designed to change a relationship by moving some information around.  For reference, the Project1 object has a Master-Detail relationship based upon a field called "Project_BEN_Number".  When I perform a bulk data load there are no errors given, the rows insert fine.  The problem is that the code is never executed, or at least the results are never saved.
 
Help!
 
Thanks,
 
EdL
 
 
Trigger Code:
Full disclosure:  I use an upsert to load the data, but it still doesn't work even with a regular insert.
 
Code:
trigger fixType on Resource_Data_Item__c (before insert) {

private Resource_Data_Item__c[] ti = Trigger.new;
try
{
    string initiative = ti[0].Initiative_Number__c;
    if(initiative == 'INIT_NA')
    {
        ti[0].Initiative_Number__c = ti[0].Project_Name__c;
        ti[0].Initiative_Name__c = ti[0].Project_Name__c;
        ti[0].Project_Name__c = ti[0].Task_Name__c;
        ti[0].Project_Number__c = ti[0].Task_Number__c;
        string pID = [select ID from Project1__c where Name = :ti[0].Project_Name__c].ID;
        ti[0].Project__c = pID;
    }
}
catch(Exception ex)
{
    ti[0].addError('Insert error: INIT_NA Task ' + ti[0].Task_Name__c + ' does not exist as a project.' + ex.getMessage());
}


}

 
  • May 27, 2008
  • Like
  • 0
How do I throw an exception? The developers guide helpfully tells me to use the throw statement and provide it with an exception object but then unhelpfully provides the following example:
 
throw <exceptionObject>;
 
I tried:
 
throw new Exception('error message');
 
but get the error - type cannot be constructed: Exception.
 
I did find something that said I could not construct any of the system exceptions so then what excepetion object can I provide to the throw statement?