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
MateoMateo 

Newbie: Error on APEX Trigger

Hi there,

 

I'm new to APEX coding and seem to be frustrated by the smallest infractions...  

 

Receiving the error "Compile Error: line 2:0 no viable alternative at character " at line 2 column 0" 

 

Exact code is as follows:

trigger InsertUpdateContactBefore on Contact (before insert, before
update)
{
        for (Contact c : Trigger.new) {
               

//Don't let records be entered without Account
               


if (c.AccountId == null){
                       



c.addError('All contacts must be related to an account.  If you are
creating this Contact in the Lookup screen,


you\'ll need to create the
contact with complete information by selecting Contact from the
"Create New..."




drop-down in the left-hand sidebar.');














}
       







} }

 

 

 I'm certain this is an easy answer, but I can't come up with it.  I've attempted to "retype" the code after copying and pasting from a text editor as simple text.  I've also looked for help in other forums and using the APEX manual available online - just not getting it.  

 

Thanks in advance!

Best Answer chosen by Admin (Salesforce Developers) 
MateoMateo

Ankit,

 

Thank you!  I ended up having to type the whole code sequence back into the UI manually.  Your copy/paste idea still didn't work - I received the same error -  BUT your comment did allow me to see that something in the text was functioning incorrectly - so I certainly appreciate the help! 

 

Thanks much,

Mateo

 

 

All Answers

Ankit AroraAnkit Arora

Hi Mateo,

 

The problem is very strange as everything looks fine. But what we see is not real sometimes.

 

Yes, I copy your code and pasted in notepad I got 

 

 

trigger InsertUpdateContactbeforeBefore on Contact (before insert, before.
update) { }

 

The dot in red is invisible on UI. Copy this code as your first line it will surely resolve your problem

 

 

trigger InsertUpdateContactbeforeBefore on Contact (before insert, before update)
{
}

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

 

 

 

MateoMateo

Ankit,

 

Thank you!  I ended up having to type the whole code sequence back into the UI manually.  Your copy/paste idea still didn't work - I received the same error -  BUT your comment did allow me to see that something in the text was functioning incorrectly - so I certainly appreciate the help! 

 

Thanks much,

Mateo

 

 

This was selected as the best answer