You need to sign in to do that
Don't have an account?
Brian Sherman 22
Visualforce page conditional image not working
We have a VF page that displays one company logo in a certain condition, and another in all others. Code is below:
<apex:image id="Logo" value="{!If(objLeadSite.Site__r.Company__r.Name=="XXXX", "https://c.na24.content.force.com/servlet/servlet.ImageServer?id=0151a000000nGvu&oid=00D1a000000XXXX","https://c.na24.content.force.com/servlet/servlet.ImageServer?id=0151a000000nGvy&oid=00D1a000000YYYY")}" />
Now, when I land on this page from a related record that should match the Company Name, instead I am presented the "else" image.
What am I missing?
<apex:image id="Logo" value="{!If(objLeadSite.Site__r.Company__r.Name=="XXXX", "https://c.na24.content.force.com/servlet/servlet.ImageServer?id=0151a000000nGvu&oid=00D1a000000XXXX","https://c.na24.content.force.com/servlet/servlet.ImageServer?id=0151a000000nGvy&oid=00D1a000000YYYY")}" />
Now, when I land on this page from a related record that should match the Company Name, instead I am presented the "else" image.
What am I missing?
Use the render attribute for this funtion:
Try something like the below: Let me know if this helps.
As a common practice, if your question is answered, please choose 1 best answer.
Additionally you can give every answer a like if that answer is helpful to you.
Regards,
Anto Nirmal
rendered attribute is good for conditional display.
for(Lead_To_Site_Association__c objLeadToSite : [Select Id,
Appt_Requested__c,
Wait_List_Requested__c,
Lead__c,
Lead__r.Name,
Site__c,
Site__r.Name,
Suite_Type__c,
Appt_Preffered_Date_Time__c,
Site__r.State_Province__c
From Lead_To_Site_Association__c
Where Id=:strRecordId])
I do not see Site__r.Company__r.Name listed here. I presume that means I cannot grab that field. Correct me if I am wrong, but if I add that field to the list, it should render, right?
for(Lead_To_Site_Association__c objLeadToSite : [Select Id,
Appt_Requested__c,
Wait_List_Requested__c,
Lead__c,
Lead__r.Name,
Site__c,
Site__r.Name,
Suite_Type__c,
Appt_Preffered_Date_Time__c,
Site__r.State_Province__c,
Site__r.Company__r.Name
From Lead_To_Site_Association__c
Where Id=:strRecordId])
<apex:image id="Logo" value="{!If(relatedTo.Site__r.Company__r.Name==...
May be in page variables are not pointing to correct object data or may be contoller method is not getting called before loading the page.
Make sure that method containing query is called before page load.
you can put method in "action" attribute of page and see.
strImgUrl= '/servlet/servlet.FileDownload?file=';
for(Document objDocument : [SELECT Id FROM Document WHERE Name='Acme Logo' limit 1])
{
strImgUrl += objdocument.Id;
it could be that a loop variable in page, which is trying to use same variable name as it is in controller.
i am wondering variable "objLeadSite" is a list, so how come it is getting used as a single object instance.
Try this code and see :
Error: Incorrect parameter type for subscript. Expected Text, received Number
<apex:image id="Logo" url="https://c.cs41.content.force.com/servlet/servlet.ImageServer?id=XXX" rendered="{!objLeadSite[0].Site__r.Company__r.Name =='XXXX'}"/>
<apex:image id="logo1" url="https://c.cs41.content.force.com/servlet/servlet.ImageServer?id=YYYY" rendered="{!NOT(objLeadSite[0].Site__r.Company__r.Name=='XXXX')}"/>
may be we need write a method to get only first element and use that.
Can you put page and controller full code here, so i can have better idea on it?
//IF LEAD TO SITE RECORD already exists fetching the LeadName and SiteName for(Lead_To_Site_Association__c objLeadToSite : [Select Id, Appt_Requested__c, Wait_List_Requested__c, Lead__c, Lead__r.Name, Site__c, Site__r.Name, Suite_Type__c, Appt_Preffered_Date_Time__c, Site__r.State_Province__c, Site__r.Company__r.Name
i am assuming page is getting tested with "RecID" parameter?
<apex:page action="{!Mehod}"></apex:apge>
and see.
Authorization Required
You must first log in or register before accessing this page.
If you have forgotten your password, click Forgot Password to reset it.
This was never the case previously.