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
CBiZcuitCBiZcuit 

Is there an "and also" clause you can add to and "IF" statement?

Basically I need to override a page layout and have to check if the Record Owner is logged in and GLB_Privacy_Opt_Out__c = true.

 

so I have right now

 

<apex:page action="{!if( !Account.GLB_Privacy_Opt_Out__c == true
    , null
    , urlFor($Action.Account.Tab, $ObjectType.Account, null, true))}"
    standardController="Account"
    recordSetVar="accounts"
    tabStyle="Account">
  <h1>GLB Opt Out Account</h1>

This page will only show the Account Name if you are not the owner and GLB_Opt_Out__c = 'true'
</apex:page>

Is there a way to check both values like

<apex:page action="{!if( !Account.GLB_Privacy_Opt_Out__c == true && &Profile.Name = !Account.OwnerID
    , null
    , urlFor($Action.Account.Tab, $ObjectType.Account, null, true))}"
    standardController="Account"
    recordSetVar="accounts"
    tabStyle="Account">
  <h1>GLB Opt Out Account</h1>
  This page will only show the Account Name if you are not the owner and GLB_Opt_Out__c = 'true'

</apex:page>

I keep getting syntax errors.

Best Answer chosen by Admin (Salesforce Developers) 
mikeafter6mikeafter6

Regardless of protocol, I hope this may help:

 

First:  Any reason your GLB_Privacy_Opt_Out__c is a string storing 'true' and 'false'?  Why isn't it a checkbox?

          (If you need to store 'true', 'false' & null, then a string makes since, otherwise, make your life easy and define GLB_Privacy_Opt_Out__c as a checkbox (force.com's boolean))

 

Second:  The result of a SOQL statement is either a single SObject <OR>   List<SObject>.  So you you are getting back an SObject of type 'Account' in your select statement.

 

Syntax when the field is a string:

 

Account a = [Select GLB_Privacy_Opt_Out__c from Account where id = '001T000000AqSTVIA3'];
boolean bIsGLBPrivate;
If (a.GLB_Privacy_Opt_Out__c == 'true') {
bIsGLBPrivate = true;
} else {
bIsGLBPrivate = false;
}

 


 Now, here's the syntax if you change the data type of your field to the Checkbox (aka boolean):

 

 

//syntax if you change the custom field to a datatype of checkbox (aka boolean)
Account a = [Select GLB_Privacy_Opt_Out__c from Account where id = '001T000000AqSTVIA3'];
boolean bIsGLBPrivate = a.GLB_Privacy_Opt_Out__c;

 

 

 

 NOTE: Please click the solution button, if this is the answer.

 

 

 

 

     

Message Edited by mikeafter6 on 2009_0508 08:28 AM

All Answers

mikeafter6mikeafter6

Instead of &&, try the AND(  expression 1 , expression 2, . . . , expression n ) syntax. See the first code block below.

 

Below shows some samples of expression syntax that may help you:

 

I've never used an IF statement in the 'action' attribute before; however, here are some things I've learned about using boolean expressions within attributes on a visualforce page.  (Believe me, the syntax is a killer and requires trial and error.)

 

Working expression for a 'rendered' attribute: 

  • I used the 'OR' statement in this sample.  Syntax for AND() is similar.  (kind of like EXCEL logic)
  • Notice how I use a single equals sign (not 2 equal signs like we do in apex) 

rendered="{!OR(IF(objectA='Person',True,False),IF(objectB='Pet',True,False))}"

This syntax works for getting to a list of accounts.  Dollar signs are still important.

 

<apex:outputLink value="{!URLFOR($Action.Account.List,$ObjectType.Account)}" id="view29">Click Here</apex:outputLink>

 

This syntax works for editing an account.  Notice how I didn't use an exclamation point before Account.ID.  For some reason, the exclamation point is not necessary within the parens of commands like URLFOR, AND, OR, etc.

 

<apex:outputLink title="Edit" value="{!URLFOR($Action.Account.Edit,Account.id)}">edit</apex:outputLink>

 

I hope these samples give you a hint.  All 3 samples work.  Again I've never used a boolean expression on the action attribute.

 

If this helps to point you in the right direction, please post your solution.  Thanks.


 

 

Message Edited by mikeafter6 on 2009_0428 05:32 PM
mikeafter6mikeafter6

Also, any reason why you can't apply your logic within a controller extension? 

 

You can create a custom action in the controller extension (APEX CLASS).  Use the extension attribute in the <apex:page> tag to reference the class that has the custom action.  (The custom action is a method in the class that usually returns a PageReference object.)

 

 

<apex:page standardController="Account" extensions="nameOfApexClassWithTheCustomAction">

 

 

 

Message Edited by mikeafter6 on 2009_0428 05:28 PM
CBiZcuitCBiZcuit

Thanks for the response(s).  Nice to know that the syntax is trial and error.

 

Basically we are in the first stages of implementing custom classes.  I was handed the issue, the resource books, and just got the "okay" to download the Eclipse IDE.

CBiZcuitCBiZcuit

Here is another question. 

 

We have a Privacy Opt option and if it is checked I would need to hide any "contact" information (address, phone, email) for that record.  If i could load a new view that would be fine could you give an example in code?

 

Also is there a way to override information that is pulled in the "hover" for recent items because it displays address and phone information.

mikeafter6mikeafter6

CBizCuit:  You can accomplish both declaratively <OR> by writing your own visualforce pages; depending on how sophisticated your requirement is.

 

(1) Hiding fields can be accomplished in several ways.  

      -  Create different layouts for different user profiles (one layout would not have the hidden fields)

      -  create visualforce pages that hide fields depending on the user.  An advanced solution may require a custom controller and/or controller extension; however, try using the standard controllers if you can.

 

(2) The 'HOVER' is controlled by modifying the 'Mini-Page Layouts' which are accessbible by editing the page-layouts for an object.  If you need more control than what's available here, then you will need to create your own visualforce pages.  (See how far you can get declaratively before writing visualforce pages, though.)

 

 

CODE EXAMPLES:

I recommend studying the overview links in the WIKI under 'Core Resources' at developer.force.com

 

Then, glance through the COOKBOOK.

 

Link to the COOKBOOK (sign up for developer access on developer.force.com to access the entire book)

CBiZcuitCBiZcuit

Thank you again for the information.  I actually have a hard copy of the cookbook so pinpointing where to look helps tremendously.  I think we are going to swap out page views depending on the criteria so creating custom classes/page layouts is the way to go.  That is where we are at right now, creating custom classes and new page layouts.  Thanks again!

CBiZcuitCBiZcuit

Well i am in need of some assistance. 

 

I am trying to set a local variable to the value retrieved from the Account Object called 'GLB_Privacy_Opt_Out__c'

 

It (GLB_Privacy_Opt_Out__c) is stored as a varchar value ('true' or 'false') and I want to cast it to a Boolean.

I get "Save error: Illegal assignment from LIST:SOBJECT:Account to Boolean"

 

Here is my code:

 

public static void isGLBPrivate()
{

 Boolean bIsGLBPrivate = [select GLB_Privacy_Opt_Out__c from Account where id = '001T000000AqSTVIA3'];
 if (bIsGLBPrivate)
 {
  //Show new page layout
 }
 else
 {
  //do nothing}
 }

Could you give me some hints to set Database values to local variables in Apex?

mikeafter6mikeafter6

CBiZcuit:  Please create new posts for your new questions; otherwise, I'll be the only one helping you.  I am still learning force.com, so you are hindering yourself.  Often, a salesforce.com expert will answer your questions.  Also, you aren't helping others learn from your questions.

 

NOTE:   You can always create a new POST and then send me a private message (via the discussion board) to read your post.  If I can help, I will.

CBiZcuitCBiZcuit

Not a problem.  Thanks.

mikeafter6mikeafter6

Regardless of protocol, I hope this may help:

 

First:  Any reason your GLB_Privacy_Opt_Out__c is a string storing 'true' and 'false'?  Why isn't it a checkbox?

          (If you need to store 'true', 'false' & null, then a string makes since, otherwise, make your life easy and define GLB_Privacy_Opt_Out__c as a checkbox (force.com's boolean))

 

Second:  The result of a SOQL statement is either a single SObject <OR>   List<SObject>.  So you you are getting back an SObject of type 'Account' in your select statement.

 

Syntax when the field is a string:

 

Account a = [Select GLB_Privacy_Opt_Out__c from Account where id = '001T000000AqSTVIA3'];
boolean bIsGLBPrivate;
If (a.GLB_Privacy_Opt_Out__c == 'true') {
bIsGLBPrivate = true;
} else {
bIsGLBPrivate = false;
}

 


 Now, here's the syntax if you change the data type of your field to the Checkbox (aka boolean):

 

 

//syntax if you change the custom field to a datatype of checkbox (aka boolean)
Account a = [Select GLB_Privacy_Opt_Out__c from Account where id = '001T000000AqSTVIA3'];
boolean bIsGLBPrivate = a.GLB_Privacy_Opt_Out__c;

 

 

 

 NOTE: Please click the solution button, if this is the answer.

 

 

 

 

     

Message Edited by mikeafter6 on 2009_0508 08:28 AM
This was selected as the best answer
CBiZcuitCBiZcuit

You probably guessed why it is set up that way…whoever did it didn’t know the difference or didn’t care. 

Thanks again!