function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
santhosh konathala 17santhosh konathala 17 

Hi community below is my code .No compilation error.But when I switched into my user I am not getting the functionality?please help me where I did wrong?

Trigger createNotification on Account(After insert, After update)
{
list<Notification__c> notifyList = new list<Notification__c>();
list<user> varUser=[select id,name from user ];

for(account acc:Trigger.new)
{
if(varUser[0].name=='Kanaka konathala')
{
Notification__C notify=new Notification__C();
acc.name=notify.name;
notify.Test__C='Outbound';
notifylist.add(notify);
}
}
if(notifylist.size()>0)
{
insert notifylist;
}
}
Best Answer chosen by santhosh konathala 17
David Catindoy 101David Catindoy 101
Trigger CreateNotification on Account(after insert, after update) {
    List<Notification__c> notifyList = new List<Notification__c>();
    User varUser = [SELECT Id, Name FROM User WHERE Id =: UserInfo.getUserId()];

    for(Account acc : Trigger.new){
        if(varUser.Name == 'Kanaka konathala'){
            Notification__c notify = new Notification__c();
            notify.Name = acc.Name;
            notify.Test__c = 'Outbound';
            notifylist.add(notify);
        }
    }
    
    if(!notifylist.isEmpty()){
        Database.insert(notifylist);
    }
}
This might work.
 

All Answers

David Catindoy 101David Catindoy 101
Trigger CreateNotification on Account(after insert, after update) {
    List<Notification__c> notifyList = new List<Notification__c>();
    User varUser = [SELECT Id, Name FROM User WHERE Id =: UserInfo.getUserId()];

    for(Account acc : Trigger.new){
        if(varUser.Name == 'Kanaka konathala'){
            Notification__c notify = new Notification__c();
            notify.Name = acc.Name;
            notify.Test__c = 'Outbound';
            notifylist.add(notify);
        }
    }
    
    if(!notifylist.isEmpty()){
        Database.insert(notifylist);
    }
}
This might work.
 
This was selected as the best answer
santhosh konathala 17santhosh konathala 17
Hi community I have two users user1 and user2 of same profile .Now, when user1  create/update records in an account, In   notification  object  my picklist value shown as 'outbound' or if user2 my picklist value shown as 'Inbound'.plz help me have any idea on this....I written some piece of code but not getting functionalty.
santhosh konathala 17santhosh konathala 17
Hi david,

your code is working fine for  user1.   but for user2  Test__c field will be displayed as  Inbound.How to achieve this...in that piece of code
santhosh konathala 17santhosh konathala 17
Thank you so much david...