You need to sign in to do that
Don't have an account?
santhosh konathala 17
Hi please help My apex code is well compiled.Here is my class calling through my trigger but functionality not executing in sandbox ?plz tell me where I did wrong?
My Trigger code:
Trigger insertNotification1 on Account(after insert,after update) {
Notificationserviceclass1 handler=new Notificationserviceclass1();
if(Trigger.isinsert ){
handler.OnAfterInsert(Trigger.new);
}
if(Trigger.isupdate ){
handler.OnAfterUpdate(Trigger.new,Trigger.oldMap);
}}
My Apex class--
public class NotificationServiceClass1 {
public void onAfterInsert (Account[] newAccounts){
List<Notification__c> notifyInsertList = new list<Notification__c>();
for(Account accname:newAccounts){
If(userinfo.getusername() == 'Kanaka konathala')
{
Notification__c notify=new Notification__c();
notify.name=accname.name;
notify.Action__c='Add';
notify.Test__c='Outbound';
}
else
If(userinfo.getusername() == 'reddy kon'){
Notification__c notify12=new Notification__c();
notify12.name=accname.name;
notify12.Test__c='Inbound';
notifyInsertList.add(notify12);
}
if(notifyInsertList.size()>0)
{
insert notifyInsertList;
}
}
}
public void onAfterUpdate(Account[] newAccounts, map<id, Account> oldMap ){
List<Notification__c> notifyUpdateList = new list<Notification__c>();
for(Account Acc:newAccounts){
Account oldAcc = oldMap.get(Acc.Id);
if(Acc.name!=oldAcc.name){
If(userinfo.getusername() == 'Kanaka konathala'){
Notification__c notifyUpdate = new Notification__c();
notifyUpdate.name=Acc.name;
notifyUpdate.Action__c= 'Modify';
notifyUpdate.Test__c='Outbound';
}
else
If(userinfo.getusername() == 'reddy kon'){
Notification__c notifyUpdate1 = new Notification__c();
notifyUpdate1.Test__c='Inbound';
notifyUpdateList.add(notifyUpdate1);
}
}
if(notifyUpdateList.size()>0 && notifyUpdateList.size()!=null){
insert notifyUpdateList;
}
}
}
}
Trigger insertNotification1 on Account(after insert,after update) {
Notificationserviceclass1 handler=new Notificationserviceclass1();
if(Trigger.isinsert ){
handler.OnAfterInsert(Trigger.new);
}
if(Trigger.isupdate ){
handler.OnAfterUpdate(Trigger.new,Trigger.oldMap);
}}
My Apex class--
public class NotificationServiceClass1 {
public void onAfterInsert (Account[] newAccounts){
List<Notification__c> notifyInsertList = new list<Notification__c>();
for(Account accname:newAccounts){
If(userinfo.getusername() == 'Kanaka konathala')
{
Notification__c notify=new Notification__c();
notify.name=accname.name;
notify.Action__c='Add';
notify.Test__c='Outbound';
}
else
If(userinfo.getusername() == 'reddy kon'){
Notification__c notify12=new Notification__c();
notify12.name=accname.name;
notify12.Test__c='Inbound';
notifyInsertList.add(notify12);
}
if(notifyInsertList.size()>0)
{
insert notifyInsertList;
}
}
}
public void onAfterUpdate(Account[] newAccounts, map<id, Account> oldMap ){
List<Notification__c> notifyUpdateList = new list<Notification__c>();
for(Account Acc:newAccounts){
Account oldAcc = oldMap.get(Acc.Id);
if(Acc.name!=oldAcc.name){
If(userinfo.getusername() == 'Kanaka konathala'){
Notification__c notifyUpdate = new Notification__c();
notifyUpdate.name=Acc.name;
notifyUpdate.Action__c= 'Modify';
notifyUpdate.Test__c='Outbound';
}
else
If(userinfo.getusername() == 'reddy kon'){
Notification__c notifyUpdate1 = new Notification__c();
notifyUpdate1.Test__c='Inbound';
notifyUpdateList.add(notifyUpdate1);
}
}
if(notifyUpdateList.size()>0 && notifyUpdateList.size()!=null){
insert notifyUpdateList;
}
}
}
}
Trigger :
Apex class
i hop its helps you :)
if it work let me inform and mark it best answer
Thanks
All Answers
try this......
Trigger :
Trigger insertNotification1 on Account(after insert,after update) {
NotificationServiceClass1 handler=new NotificationServiceClass1();
if(Trigger.isinsert ){
handler.onAfterInsert (Trigger.new);
}
if(Trigger.isupdate ){
handler.onAfterUpdate(Trigger.new,Trigger.oldMap);
}
}
Apex class--
public class NotificationServiceClass1 {
public void onAfterInsert (Account[] newAccounts){
List<Notification__c> notifyInsertList = new list<Notification__c>();
for(Account accname:newAccounts){
If(userinfo.getusername() == 'Kanaka konathala')
{
Notification__c notify=new Notification__c();
notify.name=accname.name;
notify.Action__c='Add';
notify.Test__c='Outbound';
}
else
If(userinfo.getusername() == 'reddy kon'){
Notification__c notify12=new Notification__c();
notify12.name=accname.name;
notify12.Test__c='Inbound';
notifyInsertList.add(notify12);
}
if(notifyInsertList.size()>0)
{
insert notifyInsertList;
}
}
}
public void onAfterUpdate(Account[] newAccounts, map<id, Account> oldMap ){
List<Notification__c> notifyUpdateList = new list<Notification__c>();
for(Account Acc:newAccounts){
Account oldAcc = oldMap.get(Acc.Id);
if(Acc.name!=oldAcc.name){
If(userinfo.getusername() == 'Kanaka konathala'){
Notification__c notifyUpdate = new Notification__c();
notifyUpdate.name=Acc.name;
notifyUpdate.Action__c= 'Modify';
notifyUpdate.Test__c='Outbound';
}
else
If(userinfo.getusername() == 'reddy kon'){
Notification__c notifyUpdate1 = new Notification__c();
notifyUpdate1.Test__c='Inbound';
notifyUpdateList.add(notifyUpdate1);
}
}
if(notifyUpdateList.size()>0 && notifyUpdateList.size()!=null){
insert notifyUpdateList;
}
}
}
}
hope this helps you..
thanks
Same problem getting..record not created in notication object once record created in account
Trigger :
Apex class
i hop its helps you :)
if it work let me inform and mark it best answer
Thanks
Your code is working fine ...Thanks for your your help
I need an help .In above code if Account record is created, automatically that record goes into Notification Object.In the same way,if contact is created same record goes into Notification object.So for both Account and contact created ,Notification record should be created.So , for this what changes we need to do in Above Apex class .please help me ...
i think no need to changes in above code. you should create a new trigger on contact object on after insert of after update as like above code change account object code with contact object :)