+ Start a Discussion
santhosh konathala 17santhosh konathala 17 

Any body tell where I did wrong.I am getting an error" no viable alternative at character '' at line 7 column 74 " in this code below.

Trigger insertNotification on Account(after insert,After update) {
Set<Id> set1= new Set<Id>();
 List<Notification__c> member1 = new list<Notification__c>();
 for(Account member:Trigger.new)
{
set1.add(member.Id);       
List<Account> memberList = [Select id,name from Account where id in:set1];
for(Account  temp :memberList )
{
List<Notification__c> member2 = new list<Notification__c>();
member2.name = temp.name;
member1.add(member2);

insert member1;
}
}
Best Answer chosen by santhosh konathala 17
sfdcMonkey.comsfdcMonkey.com
hi santhosh konathala
update your trigger with this trigger :)
Trigger insertNotification on Account(after insert,After update) {
   List<Notification__c> member1 = new list<Notification__c>();
   
   for(Account member : Trigger.new){
     Notification__c member2 = new Notification__c();
     member2.name = temp.name;
     member1.add(member2);       
   }

   if(member1.size > 0){
	   insert member1;
   }  

 }
Thanks 
Please let me inform if it work and mark it best answer :)
 

All Answers

sfdcMonkey.comsfdcMonkey.com
hi santhosh konathala
update your trigger with this trigger :)
Trigger insertNotification on Account(after insert,After update) {
   List<Notification__c> member1 = new list<Notification__c>();
   
   for(Account member : Trigger.new){
     Notification__c member2 = new Notification__c();
     member2.name = temp.name;
     member1.add(member2);       
   }

   if(member1.size > 0){
	   insert member1;
   }  

 }
Thanks 
Please let me inform if it work and mark it best answer :)
 
This was selected as the best answer
santhosh konathala 17santhosh konathala 17
Hi Soni This code is working fine but problem is while updating a record ,a new record is inserting ,record not updating.
sfdcMonkey.comsfdcMonkey.com
hi santosh 
it because now these above trigger fire on both time and create a new Notification__c  recod
you can separate your both condition like that -:
Trigger insertNotification on Account(after insert,After update) {
   if(trigger.isAfter && trigger.isInsert){
   List<Notification__c> member1 = new list<Notification__c>();  
   for(Account member : Trigger.new){
     Notification__c member2 = new Notification__c();
     member2.name = temp.name;
     member1.add(member2);       
   }

   if(member1.size > 0){
	   insert member1;
      }  
   }
   else if(trigger.isAfter && trigger.isUpdate){
 
      // work for after update goes here 
 
    }
 }

Thanks :)