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 

can anybody resolve this getting problem' no viable alternative at character'.

public  class NotificationServiceClass {

public void onAfterInsert (Account[] newAccounts){
     
        List<Notification__c> notifyInsertList = new list<Notification__c>();
        for(Account accname:newAccounts){
            Notification__c notify=new Notification__c();
            notify.name=accname.name;
            notify.Action__c='Add';
          If(userinfo.getusername() == 'Kanaka konathala')
            notify.Test__c='Outbound';
            If(userinfo.getusername() == 'reddy kon')
            notify.Test__c='Inbound';
            notifyInsertList.add(notify);
        }
        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){
                Notification__c notifyUpdate = new Notification__c();
                notifyUpdate.name=Acc.name;
                notifyUpdate.Action__c= 'Modify';
              If(userinfo.getusername() == 'Kanaka konathala')
                notifyUpdate.Test__c='Outbound';
                If(userinfo.getusername() == 'reddy kon')
                notifyUpdate.Test__c='Inbound';
                notifyUpdateList.add(notifyUpdate);
            }
        }
        
        if(notifyUpdateList.size()>0 && notifyUpdateList.size()!=null){
            insert notifyUpdateList;
        }
        
    }

 
Best Answer chosen by santhosh konathala 17
Dilip_VDilip_V
Hi Santosh

Try this once and let me know.If it didn't work please post the line number and screen shot of your code.
public  class NotificationServiceClass {

public void onAfterInsert (Account[] newAccounts){
     
        List<Notification__c> notifyInsertList = new list<Notification__c>();
        for(Account accname:newAccounts){
            Notification__c notify=new Notification__c();
            notify.name=accname.name;
            notify.Action__c='Add';
          If(userinfo.getusername() == 'Kanaka konathala')
            notify.Test__c='Outbound';
            If(userinfo.getusername() == 'reddy kon')
            notify.Test__c='Inbound';
            notifyInsertList.add(notify);
        }
        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){
                Notification__c notifyUpdate = new Notification__c();
                notifyUpdate.name=Acc.name;
                notifyUpdate.Action__c= 'Modify';
              If(userinfo.getusername() == 'Kanaka konathala')
                notifyUpdate.Test__c='Outbound';
                If(userinfo.getusername() == 'reddy kon')
                notifyUpdate.Test__c='Inbound';
                notifyUpdateList.add(notifyUpdate);
            }
        }
        
        if(notifyUpdateList.size()>0 && notifyUpdateList.size()!=null){
            insert notifyUpdateList;
        }
        
    }
}
If it works mark it as best answer.

Thanks.
 

All Answers

Dilip_VDilip_V
Hi Santosh,

Please share line number.

Thanks

 
santhosh konathala 17santhosh konathala 17
Hi Thermo,

Thanks for your help..

In above code I am getting problem in onAfterinsert method
Dilip_VDilip_V
Hi Santosh

Try this once and let me know.If it didn't work please post the line number and screen shot of your code.
public  class NotificationServiceClass {

public void onAfterInsert (Account[] newAccounts){
     
        List<Notification__c> notifyInsertList = new list<Notification__c>();
        for(Account accname:newAccounts){
            Notification__c notify=new Notification__c();
            notify.name=accname.name;
            notify.Action__c='Add';
          If(userinfo.getusername() == 'Kanaka konathala')
            notify.Test__c='Outbound';
            If(userinfo.getusername() == 'reddy kon')
            notify.Test__c='Inbound';
            notifyInsertList.add(notify);
        }
        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){
                Notification__c notifyUpdate = new Notification__c();
                notifyUpdate.name=Acc.name;
                notifyUpdate.Action__c= 'Modify';
              If(userinfo.getusername() == 'Kanaka konathala')
                notifyUpdate.Test__c='Outbound';
                If(userinfo.getusername() == 'reddy kon')
                notifyUpdate.Test__c='Inbound';
                notifyUpdateList.add(notifyUpdate);
            }
        }
        
        if(notifyUpdateList.size()>0 && notifyUpdateList.size()!=null){
            insert notifyUpdateList;
        }
        
    }
}
If it works mark it as best answer.

Thanks.
 
This was selected as the best answer
santhosh konathala 17santhosh konathala 17

Hi Thermo,

Thank you soo much.Now it compiled.May I know where you kept modified to resolve this issue..

 
Dilip_VDilip_V
Glad to know that.I just removed ' ' and edited in Developer console.

Thats it.
santhosh konathala 17santhosh konathala 17
Ok thank you