You need to sign in to do that
Don't have an account?
DaGunster
Trigger - test class: Even your example fails !!!!!! lol
I have a trigger that works perfect in development. It's been done for about 1 week now.
I cannot get it deployed because I cannot build the test.
Hey, I've asked for help from this forum and no help - that worked
I've poured over every scrap of documentation.
I found an example and went back to it.
This time, I'm going to make a package out of your example
So here goes ...
This is all from your documentation.
First - the Trigger
Second - the Class.
Your documentation says this is what you need.
I made a trigger and compiled it - ok.
I made the class and compiled it - ok.
Went to make a package so I can get this into P R O D U C T I ON - and FAILURE !!!!!!!!!!!!!!
From your PDF - The_World's_First_On-Demand_Programming_Language
The Trigger:
Now : The Test Class.
AGAIN : the above compiled.
CREATE PACKAGE
With the two items above saving correctly, let's create a package.
Create a new unmanaged package and add the two items above.
Click 'upload'.
oops
- - - Here is what it says
HELLO - HOUSTON - WE HAVE A PROBLEM. Your own example doesn't work !!!!!!!!!!!!!!!!!!!!!!
I have spent the last 3-4 weekends on SalesForce. I've been working on this thing overtime about 3 nights a week.
Without getting our trigger up into production - I WILL report to my management that Salesforce is a FAILURE.
We are a LARGE account. My suggestion to executive level is
(1) You write the test for free, or
(2) You allow the trigger to work without a test, or
(3) We cancel the Purchase order and look at other CRM products.
We have called our account executive who put us in touch with a 'specialist'.
The specialist said that you don't even use tests anymore !
Something is going to give here.
Can you at LEAST make your example work so that I have SOMETHING to go by.
Time and Date: Saturday, April 19, 2008 at 4:30pm
WITHOUT A DEPLOYMENT OF THE ALREADY SUCCESSFULLY DEVELOPED TRIGGER - THIS DEPLOYMENT OF SALESFORCE IS A FAILURE.
Will you at least get your example to work? What are we going to do.
Monday, I go to my managment and raise big alarms and declare a failure.
I cannot get it deployed because I cannot build the test.
Hey, I've asked for help from this forum and no help - that worked
I've poured over every scrap of documentation.
I found an example and went back to it.
This time, I'm going to make a package out of your example
So here goes ...
This is all from your documentation.
First - the Trigger
Second - the Class.
Your documentation says this is what you need.
I made a trigger and compiled it - ok.
I made the class and compiled it - ok.
Went to make a package so I can get this into P R O D U C T I ON - and FAILURE !!!!!!!!!!!!!!
From your PDF - The_World's_First_On-Demand_Programming_Language
The Trigger:
trigger blockDuplicates_tgr on Lead bulk(before insert, before update) {
/*
* begin by building a map which stores the (unique) list of leads
* being inserted/updated, using email address as the key.
*/
Map<String, Lead> leadMap = new Map<String, Lead>();
for (Lead lead : System.Trigger.new) {
if (lead.Email != null) { // skip null emails
/* for inserts OR
* updates where the email address is changing
* check to see if the email is a duplicate of another in
* this batch, if unique, add this lead to the leadMap
*/
if ( System.Trigger.isInsert ||
(System.Trigger.isUpdate &&
lead.Email != System.Trigger.oldMap.get(lead.Id).Email)) {
if (leadMap.containsKey(lead.Email)) {
lead.Email.addError('Another new lead has the same email address.');
} else {
leadMap.put(lead.Email, lead);
}
}
}
}
/* Using the lead map, make a single database query,
* find all the leads in the database that have the same email address as
* any of the leads being inserted/updated.
*/
for (Lead lead : [select Email from Lead where Email IN :leadMap.KeySet()]) {
Lead newLead = leadMap.get(lead.Email);
newLead.Email.addError('A lead with this email address already exists.');
}
}
Now : The Test Class.
public class testBlockDuplicatesLeadTrigger {
static testMethod void testDuplicateTrigger(){
Lead[] l1 =new Lead[]{
new Lead( Email='homer@fox.tv', LastName='Simpson', Company='fox' )
};
insert l1; // add a known lead
Lead[] l2 =new Lead[]{
new Lead( Email='homer@fox.tv', LastName='Simpson', Company='fox' )
};
// try to add a matching lead
try { insert l2; } catch ( System.DmlException e) {
system.assert(e.getMessage().contains('first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, A lead with this email address already exists'),
e.getMessage());
}
// test duplicates in the same batch
Lead[] l3 =new Lead[]{
new Lead( Email='marge@fox.tv', LastName='Simpson', Company='fox' ),
new Lead( Email='marge@fox.tv', LastName='Simpson', Company='fox' )
};
try { insert l3; } catch ( System.DmlException e) {
system.assert(e.getMessage().contains('first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Another new lead has the same email'),
e.getMessage());
}
// test update also
Lead[] lup = new Lead[]{
new Lead( Email='marge@fox.tv', LastName='Simpson', Company='fox' )
};
insert lup;
Lead marge = [ select id,Email from lead where Email = 'marge@fox.tv' limit 1];
system.assert(marge!=null);
marge.Email = 'homer@fox.tv';
try { update marge; } catch ( System.DmlException e) {
system.assert(e.getMessage().contains('irst error: FIELD_CUSTOM_VALIDATION_EXCEPTION, A lead with this email address already exists'),
e.getMessage());
}
}
}
AGAIN : the above compiled.
CREATE PACKAGE
With the two items above saving correctly, let's create a package.
Create a new unmanaged package and add the two items above.
Click 'upload'.
oops
- - - Here is what it says
There are problems that prevent this package from being uploaded. |
Item Type | Name | Problem |
---|---|---|
Apex Class | testBlockDuplicatesLeadTrigger.testDuplicateTrigger() | System.DmlException:
Insert failed. First exception on row 0; first error:
CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, blockDuplicates: execution of
BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.blockDuplicates: line 14, column 32 Class.testBlockDuplicatesLeadTrigger.testDuplicateTrigger: line 6, column 9 |
HELLO - HOUSTON - WE HAVE A PROBLEM. Your own example doesn't work !!!!!!!!!!!!!!!!!!!!!!
I have spent the last 3-4 weekends on SalesForce. I've been working on this thing overtime about 3 nights a week.
Without getting our trigger up into production - I WILL report to my management that Salesforce is a FAILURE.
We are a LARGE account. My suggestion to executive level is
(1) You write the test for free, or
(2) You allow the trigger to work without a test, or
(3) We cancel the Purchase order and look at other CRM products.
We have called our account executive who put us in touch with a 'specialist'.
The specialist said that you don't even use tests anymore !
Something is going to give here.
Can you at LEAST make your example work so that I have SOMETHING to go by.
Time and Date: Saturday, April 19, 2008 at 4:30pm
WITHOUT A DEPLOYMENT OF THE ALREADY SUCCESSFULLY DEVELOPED TRIGGER - THIS DEPLOYMENT OF SALESFORCE IS A FAILURE.
Will you at least get your example to work? What are we going to do.
Monday, I go to my managment and raise big alarms and declare a failure.
Taking a look at Netsuite and Oracle.
However, do expect to hear about this from the top-down, because big $ have been paid for a failure.
No issues were encountered with creating or deploying this via packaging. I also validated the duplicate functionality on my consuming org.
Reviewing your error: "CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, blockDuplicates: execution of BeforeInsert" – this seems to reference another trigger. Can you post the "blockDuplicates" trigger code? Your post includes "blockDuplicates_tgr" not "blockDuplicates", perhaps this is causing the issue.
-Mario
Review all error messages below to correct your data.
Apex trigger returnSaved caused an unexpected exception, contact your administrator: returnSaved: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0 with id a072000000360hyAAA; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, returnSaved: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a0920000001c7IVAAY; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Phone- and Faxnumbers should start with a "+" and contain nothing else then numbers: [Id] Trigger.returnSaved: line 58, column 5: Trigger.returnSaved: line 42, column 13
Any tips on the code are welcome too for a starting APEX developper:)