You need to sign in to do that
Don't have an account?
santhosh konathala 17
Hi Community I am new to Apex , can anybody call my Trigger through Apex class.Below is my code.
Trigger insertNotification on Account(after insert,after update) {
List<Notification__c> member1 = new list<Notification__c>();
List<Notification__c> member2 = new list<Notification__c>();
if(Trigger.isinsert)
{
for(account acclist:Trigger.new)
{
Notification__c nr=new notification__c();
nr.name=acclist.name;
nr.Action__c='Add';
member2.add(nr);
}
insert member2;
}
if(Trigger.isupdate)
{
for(Account member:Trigger.new)
{
Account oldacc = Trigger.oldMap.get(member.Id);
if(member.name!=oldacc.name)
{
Notification__c memb = new Notification__c();
memb.name=member.name;
memb.Action__c= 'Modify';
member1.add(memb);
}
if(member1.size()>0 && member1.size()!=null)
{
insert member1;
}
}
}
}
List<Notification__c> member1 = new list<Notification__c>();
List<Notification__c> member2 = new list<Notification__c>();
if(Trigger.isinsert)
{
for(account acclist:Trigger.new)
{
Notification__c nr=new notification__c();
nr.name=acclist.name;
nr.Action__c='Add';
member2.add(nr);
}
insert member2;
}
if(Trigger.isupdate)
{
for(Account member:Trigger.new)
{
Account oldacc = Trigger.oldMap.get(member.Id);
if(member.name!=oldacc.name)
{
Notification__c memb = new Notification__c();
memb.name=member.name;
memb.Action__c= 'Modify';
member1.add(memb);
}
if(member1.size()>0 && member1.size()!=null)
{
insert member1;
}
}
}
}
Thanks :)
All Answers
your trigger is automatic call when you create or update a account record with you apex class
first write a apex class for insert record
call this apex class from execute anonymous window from developer console
open developer console ---> debug ---> open execute anonymous window and call your static class
AccountHandler.insertNewAccount('dummy account1');
and click Execute button
and then your account trigger automatic call :)
Thanks
Mark it best answer if it helps you
overall code must be in Apex class then from Apex class my Trigger need to be executed
The above Apex class code is not compiling coming an error "Loop variable must be of type SObject "
Thanks :)
Apex class is fine but while executing Trigger I got an error"Variable does not exist: handler at line 9 "
A great Thanks to you. code is very well executing..