• salesforce sfdc 18
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Befoer update:
Trigger that executes due to an update operation and before the record is saved to the database.

Trigger Code:

Trigger customerupdate on customer__c (before update) {
 List<Test__c> test = new List<Test__c> ();
 for(Customer__C x  : Trigger.old) {
test__c t = new test__c();
t.name  =  x.name;
t.phone__c  = x.phone__c;
t.salary__c  =  x.salary__c;
test.add(t);
}
insert test;
}


Test class:

@isTest

Public class  customerinsert {

pubilc static testmethod void testinsert() {

Customer__c x = new Customer__C();
x.name = 'raghavendra';
x.phone ='876';
x.salary = 700;
insert x;

test__c  t = new Test__c();
t.name = x.name;
 t.phone__c = x.phone__c;
t.salary__C = x.salary__C;
inasert t;

system.assertEquals(t.name , x.name);
system.assertEquals(t.phone_c , x.phone__c);
x.name = 'raghavendra c';
x.phone__c = '764';

update x;

}
}



 
 

Hi , am writing an apex trigger in which I need to validate the account name if already exist before insertion... so this trigger event will be "before insert" on "Account" object... my question is there is a way from the trigger to stop the insertion process and rase an error or warning to the user that this account name already exist?

 

  • November 28, 2011
  • Like
  • 0