function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
stra80stra80 

trigger & data loader problem

Hoyy,
I am trying to input one trigger into the enterprise edition account of our organization and is not showing up (except of the first lines) although the trigger working fine into my developer edition.

I am working with the eclipse and when i try to save the trigger to the standard object is notify me that the file saved only locally and not in the server!!!
how i can save it into the enterprise account??

i also tried  to implement the data loader but the steps in order to implement it are unacceptable and i can't make it work!!

If anyone has a solution to these problems please let me know.

thanks,
stratos
JonPJonP
Production Salesforce organizations require Apex classes and triggers to be covered by test methods.  If you have not created portable test methods for your Apex code in your Developer Edition organization, you will not be able to deploy them to a production organization.  See the Apex Language Reference document for details on code coverage requirements and writing test methods.

Also, we strongly recommend against creating a Force.com project in the Force.com IDE directly against a production organization.  Instead, you should create a project against your Developer Edition (or Sandbox) organization containing the components you want to migrate, and then use the Force.com > Deploy to Server wizard to push all the files to your production organization in a single transaction.

Jon
salesforce.com Product Manager
stra80stra80
Dear JonP,

Thank you very much for the advice. I tried to make the test method but i can't again push it from eclipse to my production organization and i don't understand why.
Again only a part of the code is appearing. Also in my developer account in the setup for trigger and appex classes they is a option (a button "new") to create and writte directly code in the salesforce enviroment and in the production account is not existing such an option, so i am thinking  that mayby i must make some changes into the profile of administration in order to handle apex???

I also paste the codes of trigger and the test method and if you have time you can check it and tell me why is not appearing into the salesforce environment?

Thank you very much!!!

stratos.

The test method:
@isTest
public class contactDupePreventerTest{
static testMethod void testLeadDupPreventer() {


Set<String> testEmailAddress = new Set<String>();
testEmailAddress.add('test1@duptest.com');
testEmailAddress.add('test2@duptest.com');
testEmailAddress.add('test3@duptest.com');
testEmailAddress.add('test4@duptest.com');
testEmailAddress.add('test5@duptest.com');
System.assert([select count() from Contact
where Email in :testEmailAddress] == 0);


Contact contact1 = new Contact(LastName='Test1', Email='test1@duptest.com');
Contact contact2 = new Contact(LastName='Test2', Email='test4@duptest.com');
Contact contact3 = new Contact(LastName='Test3', Email='test5@duptest.com');
Contact[] contacts = new Contact[] {contact1, contact2, contact3};
insert contacts;


contact2.Email = 'test2@duptest.com';
contact3.Email = 'test3@duptest.com';
update contacts;


Contact dup1 = new Contact(LastName='Test1Dup', Email='test1@duptest.com');

try {
insert dup1;
System.assert(false);
}
catch (System.DmlException e) {
System.assert(e.getNumDml() == 1);
System.assert(e.getDmlIndex(0) == 0);
System.assert(e.getDmlFields(0).size() == 1);
System.assert(e.getDmlMessage(0).indexOf('A contact with this email address already exists.') > -1);
}


dup1 = new Contact(Id = contact1.Id, LastName='Test1Dup', Email='test2@duptest.com');
try {
update dup1;
System.assert(false);
}
catch (System.DmlException e) {
System.assert(e.getNumDml() == 1);
System.assert(e.getDmlIndex(0) == 0);
System.assert(e.getDmlFields(0).size() == 1);
System.assert(e.getDmlMessage(0).indexOf('A contact with this email address already exists.') > -1);
}


dup1 = new Contact(LastName='Test1Dup', Email='test4@duptest.com');
Contact dup2 = new Contact(LastName='Test2Dup', Email='test2@duptest.com');
Contact dup3 = new Contact(LastName='Test3Dup', Email='Test3@duptest.com');
Contact[] dups = new Contact[] {dup1, dup2, dup3};

try {
insert dups;
System.assert(false);
}
catch (System.DmlException e) {
System.assert(e.getNumDml() == 2);
System.assert(e.getDmlIndex(0) == 1);
System.assert(e.getDmlFields(0).size() == 1);
System.assert(e.getDmlMessage(0).indexOf('A contact with this email address already exists.') > -1);
System.assert(e.getDmlIndex(1) == 2);
System.assert(e.getDmlFields(1).size() == 1);
System.assert(e.getDmlMessage(1).indexOf('A contact with this email address already exists.') > -1);
}


dup1 = new Contact(Id=contact1.Id, Email='test4@duptest.com');
dup2 = new Contact(Id=contact2.Id, Email='test2@duptest.com');
dup3 = new Contact(Id=contact3.Id, Email='test1@duptest.com');
dups = new Contact[] {dup1, dup2, dup3};
try {
update dups;
System.assert(false);
}
catch (System.DmlException e) {
System.debug(e.getNumDml());
System.debug(e.getDmlMessage(0));
System.assert(e.getNumDml() == 1);
System.assert(e.getDmlIndex(0) == 2);
System.assert(e.getDmlFields(0).size() == 1);
System.assert(e.getDmlMessage(0).indexOf('A contact with this email address already exists.') > -1);
}

dup1 = new Contact(LastName='Test1Dup', Email='test4@duptest.com');
dup2 = new Contact(LastName='Test2Dup', Email='test4@duptest.com');
dup3 = new Contact(LastName='Test3Dup', Email='test3@duptest.com');
dups = new Contact[] {dup1, dup2, dup3};
try {
insert dups;
System.assert(false);
}
catch (System.DmlException e) {
System.assert(e.getNumDml() == 2);
System.assert(e.getDmlIndex(0) == 1);
System.assert(e.getDmlFields(0).size() == 1);
System.assert(e.getDmlMessage(0).indexOf('Another new contact has the same email address.') > -1);
System.assert(e.getDmlIndex(1) == 2);
System.assert(e.getDmlFields(1).size() == 1);
System.assert(e.getDmlMessage(1).indexOf('A contact with this email address already exist.') > -1);
}


dup1 = new Contact(Id=contact1.Id, Email='test4@duptest.com');
dup2 = new Contact(Id=contact2.Id, Email='test4@duptest.com');
dup3 = new Contact(Id=contact3.Id, Email='test2@duptest.com');
dups = new Contact[] {dup1, dup2, dup3};
try {
update dups;
System.assert(false);
}
catch (System.DmlException e) {
System.assert (e.getNumDml() == 2);
System.assert(e.getDmlIndex(0) == 1);
System.assert(e.getDmlFields(0).size() == 1);
System.assert(e.getDmlMessage(0).indexOf('Another new contact has the same email address.') > -1);
System.assert(e.getDmlIndex(1) == 2);
System.assert(e.getDmlFields(1).size() == 1);
System.assert(e.getDmlMessage(1).indexOf('A contact with this email address already exists.') > -1);
}
}
}
The Trigger:

trigger contactDuplicatePreventer on Contact (before insert, before update) {

Map<String, Contact> contactMap = New Map<String, Contact>();
for (Contact contact : System.Trigger.new) {


if ((contact.Email !=null) &&
(System.Trigger.isInsert ||
(contact.Email != System.Trigger.oldMap.get(contact.Id).Email))) {


if (contactMap.containsKey(contact.Email)) {
contact.Email.addError('Another new contact has the '+ 'same email address.');
} else {
contactMap.put(contact.Email, contact);
}
}
}


for (Contact contact : [select Email from Contact where Email in :contactMap.KeySet() ]) {
Contact newContact = contactMap.get(contact.Email);
newContact.Email.addError('A contact with this email '+ 'address already exists.');
}


}



JonPJonP
In the web UI, you cannot create new Apex classes or triggers in a production organization.  The only way to get them into production is to deploy them, using a tool like the Force.com IDE or the Force.com Migration Tool for Ant.  This is why there are no "New" buttons for Apex in a production organization.

What's happening with what you describe as "only a part of the code is appearing" is this:

1. In the Force.com IDE, you created a Force.com project against your production organization.
2. You created a new Apex Trigger using the IDE's New Apex Trigger wizard.
- Behind the scenes, the IDE generated an empty trigger body and saved it to the server using the Metadata API's deploy() action
- The server allowed you to deploy this trigger to a production organization because, since it was empty, it had no untested lines.
3. You opened the new trigger in the IDE's Apex Code Editor, added some lines of code, and saved the file.
- When you saved, the IDE once again sent the trigger file to the server using the Metadata API's deploy() action
- This time, the server rejected the deploy because your new lines of trigger code were NOT tested.

Thus, all that was ever saved to the server was the initial, empty trigger body.  This is why we recommend you NEVER create a Force.com project using production credentials.


Following these steps should solve your problem:

1. In the Force.com IDE, create a Force.com project using your Developer Edition credentials.
2. Create your trigger and test class.
3. In the project explorer, right-click on your test class and select Force.com > Run Tests from the context menu.
4. Confirm all your tests pass and that code coverage for your trigger is > 75%.
5. When you're ready, in the project explorer right-click on the "src" folder and select Force.com > Deploy to Server.
- In step 1, enter your production credentials.
- In step 3, deselect all components except your trigger and test class, and click Next.
- Review the deployment results to confirm your deployment was successful, or if not to see what errors the server reported.
6. In the web browser, log into your production organization and look at the trigger to confirm it was created successfully.


stra80stra80
Thank you very much!!!!
Your instructions were perfect i found everything. Although i must have some problem in the test method because is not running but at least now i know how to migrate apex from one account to the other.

Have a nice day!