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
sunfishettesunfishette 

Inserting Image based on Log in

Hello All!

 

2 parts to this question, then I will add code.

 

I have an Apex Class that calls information from my Opportunity record and displays it on my VisualForce page.  The data is then sorted into three categories on my page.  All is working well there.  But there are still 2 things I want to do.

 

1. I want to make the results clickable to take them to their appropriate opportunity record.

2. I want to add an image onto their Partner Portal page on login, based on their company Name.

   ----> I have stored the jpg's in to a zipped static resource folder called "Logos" and I have named each one identical to the name of the Portal login user   ------>Company name (for example, Charlie Brown logs in, he is from Brown Ltd, and his logo image is called "Brown Ltd.jpg"

 

I know I have a lot of oddball things in the code, but, I am new at this.  For example, my script twist thingy doesnt work.  No idea why.  For somereason, my pageBlockSections dont expand or collapse.  Its werid.  Any help would be .... helpful ...  I would like to point out an error, but I do not get any errors.  I simply do not get the image.  Thank you!!

 

VF PAGE:

<apex:page showHeader="false" sidebar="false" standardController="Opportunity" tabStyle="Opportunity" extensions="getAllRecords">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <body>   
                    <h5>
                       <p>Welcome Back {!$User.FirstName & ' ' & $User.LastName}!<br />
                          Todays Date: {!MONTH(TODAY())}/{!DAY(TODAY())}/{!YEAR(TODAY())}
                       </p>
                    </h5>
      
            <!-- ----------------------------------------- -->
            <!-- ---- INSERT THEIR LOGO ----- -->
            <!-- ----------------------------------------- -->  
                    <div id="displayDiv">Logo Image/Picture Loading...<br />(Want to see your logo displayed here?  Contact support for details)
                        <apex:variable var="imageVar" value="{!ImageName}"/>
                        <apex:image url="{!URLFOR($Resource.Logos, imageVar)}"/>
                    </div>
                 <apex:pageBlock id="block1">
                    <script>
                        twistSection(document.getElementById('{!$Component.block1.zero30}').getElementsByTagName('img')[0])                       
                    </script>
                    <apex:tabPanel selectedTab="MaintenanceRenewals" id="theTabPanel"  tabClass="activeTab" inactiveTabClass="inactiveTab"  width="100%">
                        <apex:tab label="Maintenance Renewals" name="MaintenanceRenewals" labelWidth="250px" >                                      
                            <apex:pageBlockSection id="zero30" title="0-30 Days Maintenance Renewals" columns="1">
                                <apex:PageBlockTable value="{!ZeroThirty}" var="records" rowClasses="red1,red2">
                                    <apex:column value="{!records.Name}" headerValue="Manufacturer Name" />
                                    <apex:column value="{!records.Contract_Owner__c}" headerValue="Contract Owner" />
                                    <apex:column value="{!records.Amount}" headerValue="Amount" />
                                    <apex:column value="{!records.CloseDate}" headerValue="Renwal Due By" />
                                </apex:pageBlockTable>      
                            </apex:pageBlockSection>
                            <apex:pageBlockSection title="31-60 Days Maintenance Renewals" columns="1">
                               <apex:PageBlockTable value="{!ThirtySixty}" var="records" rowClasses="yellow1,yellow2">
                                    <apex:column value="{!records.Name}" headerValue="Manufacturer Name" />
                                    <apex:column value="{!records.Contract_Owner__c}" headerValue="Contract Owner" />
                                    <apex:column value="{!records.Amount}" headerValue="Amount" />
                                    <apex:column value="{!records.CloseDate}" headerValue="Renwal Due By" />
                                </apex:pageBlockTable>
                            </apex:pageBlockSection>
                            <apex:pageBlockSection title="61 Days (or more) Maintenance Renewals" columns="1">
                                <apex:PageBlockTable value="{!OverSixty}" var="records" rowClasses="green1,green2">
                                    <apex:column value="{!records.Name}" headerValue="Manufacturer Name" />
                                    <apex:column value="{!records.Contract_Owner__c}" headerValue="Contract Owner" />
                                    <apex:column value="{!records.Amount}" headerValue=" Amount" />
                                    <apex:column value="{!records.CloseDate}" headerValue="Renwal Due By" />
                                </apex:pageBlockTable>
                            </apex:pageBlockSection>     
                        </apex:tab>
                    </apex:tabPanel>
                  </apex:pageBlock>
    </body>   
</html>
</apex:page>

APEX CLASS:

public class getAllRecords {
    public getAllRecords(ApexPages.StandardController Controller) {
    } 
    public Opportunity[] getRecordDetail(){
    Opportunity[]recordList = new List<Opportunity>();
        recordList = [SELECT Name,
                             Contract_Owner__c,
                             Amount,
                             CloseDate
                        FROM Opportunity
                       WHERE AccountId IN 
                            (SELECT AccountId 
                             FROM User 
                             WHERE username=:UserInfo.getUsername())
                        ORDER BY CloseDate];
       return recordList;
    }
    public Opportunity[] getZeroThirty(){
    List<Opportunity> recordList = getRecordDetail();
    List<Opportunity> zeroThirtyList = new List<Opportunity>();
        for(Opportunity obj:recordList) {
            if(obj.CloseDate < (system.today() + 30)) {
                zeroThirtyList.add(obj);
            }
        }
    return zeroThirtyList;
    }
    public Opportunity[] getOverSixty(){
        List<Opportunity> recordList = getRecordDetail();
        List<Opportunity> overSixtyList = new List<Opportunity>();
            for(Opportunity obj2:recordList) {
                if(obj2.CloseDate > (system.today() + 60)) {
                    overSixtyList.add(obj2);
                }
            }
    return overSixtyList;
    }
    public Opportunity[] getThirtySixty(){
    List<Opportunity> recordList = getRecordDetail();
    List<Opportunity> thirtySixtyList = new List<Opportunity>();
        for(Opportunity obj3:recordList) {
            if((obj3.CloseDate < (system.today() + 60)) && (obj3.CloseDate > (system.today() + 30))) {
                thirtySixtyList.add(obj3);
            }
        }
    return thirtySixtyList;
    }
    public String getImageName() {
        Opportunity fileName = new Opportunity();
            fileName = [SELECT Name FROM Opportunity WHERE AccountId IN (SELECT AccountId From User WHERE username=:UserInfo.getUsername())];
            string image = '';
            image = fileName + '.jpg';
        return image;
        }
sunfishettesunfishette

An UPDATE:

 

It appears I am getting closer to solving the issue.  I think the error is now in my SOQL statement.  Again, I am trying to get the (Business name) Account Name based on the ID of the user logging in to my Partner Portal and setting it equal to a string which I can then pass back to my visualforce page.  Here is my updated (albeit incorrect ...) code.  The line that I commented out of the Apex Class returns a correct result, hence the assumption that my SOQL is wrong.

 

APEX CLASS:

    public String getImageName(){
      
       String file = [SELECT Name
                        FROM Account
                       WHERE Id IN
                            (SELECT AccountId
                               FROM user
                              WHERE username=:UserInfo.getUsername()
                             )
                       LIMIT 1
                     ].Name;
       String foldername = 'Logos/';
       String extension = '.jpg';
       String fullImageName = '"' + foldername + file + extension + '"';     
       return fullImageName;
      /*
       return 'Logos/Johnson.jpg';
       */
    }

 

VISUALFORCE SECTION:

<apex:variable var="imageVar" value="{!imageName}"/>
 <apex:image url="{!URLFOR($Resource.Logos, imageVar)}" />

 

Any help is appreciated.  I am ready to be done with this so I can be frustrated by something else ... :)

 

Thank you.