1

I'm running into these two errors and am not sure why. Any suggestions?

  • Error: /apex/lightningAccountLayout: Syntax error

  • Error Error: Syntax error

I'm new to SF, and just learning Apex. I'm also going through the Trailhead course for this, but the code below looks okay to me..

     
</apex:page>
<apex:page standardController="Account">
  <apex:stylesheet value="{!$Resource.styleforAccountLightningPage}"/>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script> 
  
  
  <p>{!IF(CONTAINS(Account.Systems_Pick__c,"Medication Dispenser"), 
      '"Medication Dispenser Device Number: " + {Account.MED_Device_Number__c}', false)}</p>

       
     
</apex:page>

2 Answers 2

1

The single apostrophes are incorrect, as well as the extra curly brackets. You put the entire formula in {!...}, and there should be no extra curly brackets anywhere. Also, string concatenation is & in Visualforce. Finally, you can't mix return types in an IF statement (string versus Boolean). Use an empty string instead.

  <p>{!IF(CONTAINS(Account.Systems_Pick__c,"Medication Dispenser"), 
      "Medication Dispenser Device Number: " & TEXT(Account.MED_Device_Number__c), '')}</p>
2
  • Very helpful in explination and example! However, I'm receiving this error with the changes above: 'Error: Incorrect parameter type for operator '&'. Expected Text, received Number' Oct 12, 2020 at 15:30
  • @AlexisFrisch So, TEXT(Accout.MED_Device_Number__c). I'll edit.
    – sfdcfox
    Oct 12, 2020 at 15:55
0

This was the code that worked

<apex:page standardController="Account">

  <apex:stylesheet value="{!$Resource.styleforAccountLightningPage}"/>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script> 
  
  
 <p> {!IF(CONTAINS(Account.Systems_Pick__c,"Medication Dispenser"), 
      "Medication Dispenser Device Number: " & TEXT(Account.MED_Device_Number__c), '')} </p>
     
</apex:page>

The error I received above was because the Account.MED_Device_Number__c was a number and not a string. Putting TEXT() around it, solved the error.

Code works great!

Huge shoutout to @sfdcfox for assisting and explaining so well!

2
  • My apologies for the previous comment. I thought you edited the question. It's perfectly fine to add your own answer when it's a self-Q&A, although standard etiquette states you should accept/upvote the provided answer rather than adding your own when someone else answers your question.
    – sfdcfox
    Oct 12, 2020 at 15:59
  • So sorry! I will figure out how to do that - Very new at this! Oct 12, 2020 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.