• sandeep87
  • NEWBIE
  • 0 Points
  • Member since 2012

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

trigger myAccountTrigger on Account(before delete, before insert, before update,
after delete, after insert, after update) {
if (Trigger.isBefore) {
if (Trigger.isDelete) {

// In a before delete trigger, the trigger accesses the records that will be

// deleted with the Trigger.old list.

for (Account a : Trigger.old) {
if (a.name != 'okToDelete') {
a.addError('You can\'t delete this record!');
}
}
} else {

// In before insert or before update triggers, the trigger accesses the new records

// with the Trigger.new list.

for (Account a : Trigger.new) {
if (a.name == 'bad') {
a.name.addError('Bad name');
}
}
if (Trigger.isInsert) {
for (Account a : Trigger.new) {
System.assertEquals('xxx', a.accountNumber);
System.assertEquals('Banking', a.industry);
System.assertEquals(100, a.numberofemployees);
System.assertEquals(100.0, a.annualrevenue);
a.accountNumber = 'yyy';
}

// If the trigger is not a before trigger, it must be an after trigger.

} else {
if (Trigger.isInsert) {
List<Contact> contacts = new Contact[0];
for (Account a : Trigger.new) {
if(a.Name == 'makeContact') {
contacts.add(new Contact (LastName = a.Name,
AccountId = a.Id));
}
}
insert contacts;
}
}
}}}

 

TEST CLASS

@istest
private class myAccountTrigger
{
static testmethod void test()
{
account a=new account(name='makeContact',accountnumber='xxx',industry='banking',numberofemployees=100,annualrevenue=100);
insert a;

system.assertequals(a.accountNumber,'xxx');

account k=new account(name='bad');
try{
insert k;
System.assert(false);
}
catch (Exception e)
{

}

system.assertnotequals('okToDelete',a.name);
delete a ;                // AND HERE IT IS GIVING ERROR 

 

ERROR IS System.DmlException: Delete failed. First exception on row 0 with id 0019000000E4eDUAAZ; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, You can't delete this record!: []
STACK TRACE:Class.myAccountTrigger.test: line 22, column 1


}
}

 

 

GETTING 71 % TEST COVERAGE.. ANY HELP WILL BE APPRECIATED

I have created a VF page which displays all the records(in a page block table) related to a custom object(Candidate).Above this table,I have created all the fields which are included as columns in the table. However,I need to create filters on the columns of this table to dynamically display the records based on the values chosen in the fields.(i,e) Suppose I have a pick-list called "Branch" which has values (CSE,IT,ECE,EEE). When ever I choose the value in the pick list on the VF page,It should display the table of records filetered by the value choosen in the pick list.. Can anyone help me out on how to implement this functionality?? Thanks!!!! Regards, Anusha

Hi Guys,

Can someone help me out here!


This is my situation:

I have two custom objects Job_ATS__c and Shortlists__c.

Job_ATS__c is the Parent and Shortlists__c is the Child. The relationship is one to many.


That means one job can have many shortlists and each shortlist has a Status__c. Status are 'Interested' or 'Not Interested'

 

So what I want is a query that will return Job Name and count for Interested and Not Interested shortlists.

 

E.g...

 

Job_ATS__c                      Shortlists__c                                                                           Desired Result

______________         __________________________________                       ______________________________
Job Name       id             Shortlist Name       id     job_id   Status                                   Job Name   Interested     Not Interested
______________         __________________________________                       _______________________________
Job1                 1               Shortlist1                1        1          Interested                             Job1                1                        1  
Job2                 2               Shortlist2                2        1          Not Interested                      Job2                1                        0

                                           Shortlist3                3         2          interested

 

I need to Display the desired result on Vf page.

  • August 28, 2012
  • Like
  • 0