• Gilz
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 7
    Replies

Hi,

 

I'm working on my first trigger and test, and I think I got through most of the problems in the code, but I keep failing to validate them. In the developer console it tells me that the trigger has a 100% on all tests,but as you can see, this is not how the program reads it when validating.

 

Attached are the fails I get, and the modified code:

 

TestDontDelete.myUnitTest() - Failure Message: "System.QueryException: List has more than 1 row for assignment to SObject", Failure Stack Trace: "Class.TestDontDelete.myUnitTest: line 7, column 1"
 
dontDelete - Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required.
 
Deploy Error - Average test coverage across all Apex Classes and Triggers is 0%, at least 75% test coverage is required.

 

Trigger:

 

//Prevent deleting a contact that is associated with a 203k disbursement

trigger dontDelete on Contact (before delete)
{
  RecordType r =[Select id, name from RecordType where SobjectType='Contact' and name='Contractor'];
  for (Contact x : Trigger.old)
  {
    if (x.RecordTypeId==r.id)
    {
      x.addError('You cannot delete this an account of type "Contractor"');
    }
  }
}

 

Test:

 

@isTest
private class TestDontDelete
{
  static testMethod void myUnitTest()
  {

    Contact con = new Contact (LastName = 'Testi', RecordTypeID= [SELECT Id FROM RecordType WHERE Name = 'Contractor'].Id);

    try
    {
      delete con;
    }
  catch (dmlexception e)
  {
    system.assert(e.getMessage().contains('You cannot delete this an account of type "Contractor"'),
    e.getMessage());
  }
}
}

  • July 01, 2013
  • Like
  • 0

Hi all,

I am new to Salesforce, and I'm spending much time on this first trigger that I'm trying to deploy.

I feel like I am almost done creating it, but I get one problem with the trigger, and one with the test.

The goal of the trigger is to prevent the delete of contacts of record type 'contractor'. The reasoning bhind it is that Contractors often have child objects that I don't want to be deleted with them.

 

Here are the codes, and the problems (the lines where they appear are red).

 

Trigger:

 

//Prevent deleting a contact that is associated with a 203k disbursement

 

RecordType r =[Select id, name from RecordType where sobject='Contact' and name='Contractor'];

 

trigger dontDelete on Contact (before delete)
  {
  for (Contact x : Trigger.old)
  {
    if (x.RecordTypeId==r.id)
    {
      x.addError('You cannot delete this an account of type "Contractor"');
    }
  }
}

 

Probelm: unexpected token: RecordType

 

test:

 

@isTest
private class TestDontDelete
{
  static testMethod void myUnitTest()
  {
    List<Contact> con = [SELECT id FROM Contact WHERE RecordTypeId in (SELECT Id FROM RecordType WHERE sobject='Contact' and         name='Contractor')];

    try
    {
      delete con;
    }
    catch (dmlexception e)
    {
      system.assert(e.getMessage().contains('You cannot delete this an account of type "Contractor"'),
      e.getMessage());
    }
  }
}

 

Problem: No such column 'sboject' on entity 'RecordType'. If you are attempting to use a custon field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

 

Thank you all very much,

Gil

  • July 01, 2013
  • Like
  • 0

Hello, I'm pretty new to salesforce and I'm trying to deploy a trigger I adjusted from an online source.

 

I cannot deploy/validate the trigger, because the results of the Test coverage are 0%. However, when I run the code on the developer console, I get higher percentages. Still, there are some tests that the code fails in the DC as well. I would appreciate any help in getting past this stage.

 

The code is meant to prevent deleting contacts of a certain record type id. Here are the code and the test:

 

//Prevent deleting a contact that is associated with a 203k disbursement
trigger dontDelete on Contact (before delete)
{
for (Contact x : Trigger.old)
{
if (x.RecordTypeId=='01250000000DwuV')
{
x.addError('You cannot delete this an account of type "Contractor"');
}
}
}

 

 

@isTest
private class TestDontDelete
{
static testMethod void myUnitTest()
{
List<Contact> con = [SELECT id FROM Contact WHERE RecordTypeId ='01250000000DwuV'];

try
{
delete con;
}
catch (dmlexception e)
{
system.assert(e.getMessage().contains('You cannot delete this an account of type "Contractor"'),
e.getMessage());
}
}
}

 

 

 

  • June 26, 2013
  • Like
  • 0

Hi,

 

I'm working on my first trigger and test, and I think I got through most of the problems in the code, but I keep failing to validate them. In the developer console it tells me that the trigger has a 100% on all tests,but as you can see, this is not how the program reads it when validating.

 

Attached are the fails I get, and the modified code:

 

TestDontDelete.myUnitTest() - Failure Message: "System.QueryException: List has more than 1 row for assignment to SObject", Failure Stack Trace: "Class.TestDontDelete.myUnitTest: line 7, column 1"
 
dontDelete - Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required.
 
Deploy Error - Average test coverage across all Apex Classes and Triggers is 0%, at least 75% test coverage is required.

 

Trigger:

 

//Prevent deleting a contact that is associated with a 203k disbursement

trigger dontDelete on Contact (before delete)
{
  RecordType r =[Select id, name from RecordType where SobjectType='Contact' and name='Contractor'];
  for (Contact x : Trigger.old)
  {
    if (x.RecordTypeId==r.id)
    {
      x.addError('You cannot delete this an account of type "Contractor"');
    }
  }
}

 

Test:

 

@isTest
private class TestDontDelete
{
  static testMethod void myUnitTest()
  {

    Contact con = new Contact (LastName = 'Testi', RecordTypeID= [SELECT Id FROM RecordType WHERE Name = 'Contractor'].Id);

    try
    {
      delete con;
    }
  catch (dmlexception e)
  {
    system.assert(e.getMessage().contains('You cannot delete this an account of type "Contractor"'),
    e.getMessage());
  }
}
}

  • July 01, 2013
  • Like
  • 0

Hi all,

I am new to Salesforce, and I'm spending much time on this first trigger that I'm trying to deploy.

I feel like I am almost done creating it, but I get one problem with the trigger, and one with the test.

The goal of the trigger is to prevent the delete of contacts of record type 'contractor'. The reasoning bhind it is that Contractors often have child objects that I don't want to be deleted with them.

 

Here are the codes, and the problems (the lines where they appear are red).

 

Trigger:

 

//Prevent deleting a contact that is associated with a 203k disbursement

 

RecordType r =[Select id, name from RecordType where sobject='Contact' and name='Contractor'];

 

trigger dontDelete on Contact (before delete)
  {
  for (Contact x : Trigger.old)
  {
    if (x.RecordTypeId==r.id)
    {
      x.addError('You cannot delete this an account of type "Contractor"');
    }
  }
}

 

Probelm: unexpected token: RecordType

 

test:

 

@isTest
private class TestDontDelete
{
  static testMethod void myUnitTest()
  {
    List<Contact> con = [SELECT id FROM Contact WHERE RecordTypeId in (SELECT Id FROM RecordType WHERE sobject='Contact' and         name='Contractor')];

    try
    {
      delete con;
    }
    catch (dmlexception e)
    {
      system.assert(e.getMessage().contains('You cannot delete this an account of type "Contractor"'),
      e.getMessage());
    }
  }
}

 

Problem: No such column 'sboject' on entity 'RecordType'. If you are attempting to use a custon field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

 

Thank you all very much,

Gil

  • July 01, 2013
  • Like
  • 0

Hello, I'm pretty new to salesforce and I'm trying to deploy a trigger I adjusted from an online source.

 

I cannot deploy/validate the trigger, because the results of the Test coverage are 0%. However, when I run the code on the developer console, I get higher percentages. Still, there are some tests that the code fails in the DC as well. I would appreciate any help in getting past this stage.

 

The code is meant to prevent deleting contacts of a certain record type id. Here are the code and the test:

 

//Prevent deleting a contact that is associated with a 203k disbursement
trigger dontDelete on Contact (before delete)
{
for (Contact x : Trigger.old)
{
if (x.RecordTypeId=='01250000000DwuV')
{
x.addError('You cannot delete this an account of type "Contractor"');
}
}
}

 

 

@isTest
private class TestDontDelete
{
static testMethod void myUnitTest()
{
List<Contact> con = [SELECT id FROM Contact WHERE RecordTypeId ='01250000000DwuV'];

try
{
delete con;
}
catch (dmlexception e)
{
system.assert(e.getMessage().contains('You cannot delete this an account of type "Contractor"'),
e.getMessage());
}
}
}

 

 

 

  • June 26, 2013
  • Like
  • 0