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
DannyTKDannyTK 

Receiving an error: no viable alternative at character ' '

Good afternoon, 

as a non-developer, i'm trying to write a trigger that will update the owner of a custom object record "Sales Order" back to the creator of the record when the status is "Sales Order Completion", 
(pretty basic, which is the only reason I would attempt it myself), code is:


trigger UpdateOwner on Sales_Order__c (after Update)
{  
if((trigger.new[0].Status__c == 'Sales Order Completion') && (trigger.old[0].Status__c != 'Sales Order Completion'))
{       trigger.new[0].OwnerId = trigger.new[0].CreatedById ;
         }
}

it's throwing a Compile Error: line 5:10 no viable alternative at character '' at line 5 column 10
the only thing on line 5 is the }, so i'm assuming i have a missing reference somewhere.  

Any help is appreciated on why i'm getting the error message
Best Answer chosen by DannyTK
Vinit_KumarVinit_Kumar

I found some issues in your code and modified it.Try the below code this should work :-

<pre>
trigger UpdateOwner on Sales_Order__c (before Update)

for(Sales_Order__c sc : trigger.new)
{
Sales_Order__c oldrecord = trigger.oldMap.get(sc.id);
if(sc.Status__c == 'Sales Order Completion' && oldrecord.Status__c=='Sales Order Completion')
  {      
   sc.OwnerId = sc.CreatedById ;
        }
}
</pre>

All Answers

Ramu_SFDCRamu_SFDC
As far as the code goes I do not see any issues. I came across one of the posts where a user has come across similar issue when he copied and pasted the code from other applications. The solution is to delte the single quotes and re-type them. The below post talks more about this

http://stackoverflow.com/questions/11001916/no-viable-alternative-at-character

Hope this helps !!
Vinit_KumarVinit_Kumar

I found some issues in your code and modified it.Try the below code this should work :-

<pre>
trigger UpdateOwner on Sales_Order__c (before Update)

for(Sales_Order__c sc : trigger.new)
{
Sales_Order__c oldrecord = trigger.oldMap.get(sc.id);
if(sc.Status__c == 'Sales Order Completion' && oldrecord.Status__c=='Sales Order Completion')
  {      
   sc.OwnerId = sc.CreatedById ;
        }
}
</pre>

This was selected as the best answer
DannyTKDannyTK
Thanks Vinit,

I replaced my trigger with yours, i trust that it's better than what i can write.  Looks like it's still throwing out the "no viable alternative at character '' at line 9 column 9" error message....i also deleted the single quotes and re-typed them.  (and added a closed "}", looks like it's missing one)

DannyTKDannyTK
Disregard my previous message Vinit,

I copied it from a different format and it worked, thanks for both of your help