• SFDC L
  • NEWBIE
  • 15 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
I am building a Custom object called Product_Interactions__C that logs changes made on Opportunity Products. This is done with a trigger that creates a record on Product_Interactions__c. 

My trigger code:
trigger ProductInteractionChange on OpportunityLineItem (after update) {  
    
    for (OpportunityLineItem I : Trigger.new){
    
        List<Product_Interactions__c> InteractionChangeAdmin = new List<Product_Interactions__c>();
    
    Product_Interactions__c SaveChangeAdmin = new Product_Interactions__c();
        
            
            SaveChangeAdmin.Opportunity__c 					= I.OpportunityId;
        	SaveChangeAdmin.Product_Name_Link__c			= I.Product_Link__c;
            SaveChangeAdmin.Interaction__c 					= I.Message__c;
            SaveChangeAdmin.Department__c 					= 'Admin';
                
            InteractionChangeAdmin.add (SaveChangeAdmin);
            
            insert InteractionChangeAdmin;   	
 
    }
}
On OpportunityLineItem there is also a formula called Product_Link__c:
HYPERLINK("/"&Id,PricebookEntry.Product2.Name)
As a better way to keep track of the records in this object I have also created a Visualforce Page, on this page I have been able to get a direct link to the Opportunity without problem but I am unable to display a hyperlink to the product that was edited. This is what my Visualforce Page looks at the moment:
VF Page

The id displayed in the Product Name column IS the correct one I am just unable to figure out how to display this as a hyperlink on my Visualforce page with the product name as text. I would really appreciate any help on how best to approach this, or if there is an easier way that I am overlooking.

Thanks
L
  • February 19, 2015
  • Like
  • 0
I'm using AggregateResult to display 2 values, first is a sum of a custom field Hours_Used__c which is in a custom object Holiday__c. Second is a sum of a custom field Hours_Available__c which is on the User object.

I am able to show these results separately on my visualforce page shown here:

vfpage

My requirement is to be able to display Hours_Available__c - Hours_Used__c to leave me with a column that shows the Staff Member Name and the total hours that are left.

For example using the screenshot above I would need a pageblocktable that shows:

Staff Member   | Hours Left
Adam west      | 252
Duke Young     | 225
Jim Taylor       | 198

Controller:
public class HolidayManagementController {
    
    Public List<Holiday__c> HolidayList {get;set;}
    Public List<AggregateResult> HoursUsedList;
    Public List<AggregateResult> AllowanceTotalList;
 
    String cname {get;set;}
    
    Public HolidayManagementcontroller(){
        cname		= UserInfo.getUserName();
        user cu	  	= [SELECT Name FROM User WHERE username =:cname];
        
        HolidayList 		= [SELECT Hours_Used__c, Staff_Member__c, Staff__r.Name, Manager_Name__c
                               FROM Holiday__c
                               WHERE Manager_Name__c =:cu.Name
                               ORDER BY Staff__r.Name];
       
        HoursUsedList 		= [SELECT SUM(Hours_Used__c) hours, Staff__r.Name staff
                               FROM Holiday__c
                               WHERE Manager_Name__c =:cu.Name
                               GROUP BY Staff__r.Name
                               ORDER BY Staff__r.Name asc];
        
        AllowanceTotalList 	= [SELECT SUM(Hours_Available__c) allowance, Name
                              FROM User
                              WHERE Manager__c =:cu.Name
                              GROUP BY Name
                              ORDER BY Name asc];
        
    }
    
    public list<AggregateResult> HoursList {
 	get { return HoursUsedList;}
 	}
    
    public list<AggregateResult> AllowanceList {
 	get { return AllowanceTotalList;}
 	}
}

VF Page:
<apex:page controller="HolidayManagementController" sidebar="false">
    <apex:form>
        <apex:pageBlock>
			<apex:pageBlockTable value="{!HolidayList}" var="hlist">

                <apex:column headerValue="Staff Member">
                <apex:outputField value="{!hlist.Staff__r.Name}"/>
                </apex:column>

                <apex:column headerValue="Manager">
                <apex:outputField value="{!hlist.Manager_Name__c}"/>
                </apex:column>
  
                <apex:column headerValue="Hours Used">
                <apex:outputField value="{!hlist.Hours_Used__c}"/>
                </apex:column>
                
            </apex:pageBlockTable>            
        </apex:pageBlock>
        
        <apex:pageBlock>
        <apex:pageBlockTable value="{!HoursList}" var="h">
        	  
           <apex:column >
            <apex:facet name="header">Staff Member</apex:facet>
            {!h['staff']}</apex:column>
            
            <apex:column >
            <apex:facet name="header">Hours Used</apex:facet>
            {!h['hours']}</apex:column>
            

            
        </apex:pageBlockTable>
            
        <apex:pageBlockTable value="{!AllowanceList}" var="a">
        	  
           <apex:column >
            <apex:facet name="header">Staff Member</apex:facet>
            {!a['Name']}</apex:column>
            
            <apex:column >
            <apex:facet name="header">Hours Available</apex:facet>
            {!a['allowance']}</apex:column>
            

            
        </apex:pageBlockTable>    
            
        </apex:pageBlock>
    </apex:form>
</apex:page>

Any help would be greatly appreciated. I'm pretty new to programming in general so i'm open to suggesstions if i'm going about this the wrong way. 

Thanks
L
  • January 25, 2015
  • Like
  • 1
I'm using AggregateResult to display 2 values, first is a sum of a custom field Hours_Used__c which is in a custom object Holiday__c. Second is a sum of a custom field Hours_Available__c which is on the User object.

I am able to show these results separately on my visualforce page shown here:

vfpage

My requirement is to be able to display Hours_Available__c - Hours_Used__c to leave me with a column that shows the Staff Member Name and the total hours that are left.

For example using the screenshot above I would need a pageblocktable that shows:

Staff Member   | Hours Left
Adam west      | 252
Duke Young     | 225
Jim Taylor       | 198

Controller:
public class HolidayManagementController {
    
    Public List<Holiday__c> HolidayList {get;set;}
    Public List<AggregateResult> HoursUsedList;
    Public List<AggregateResult> AllowanceTotalList;
 
    String cname {get;set;}
    
    Public HolidayManagementcontroller(){
        cname		= UserInfo.getUserName();
        user cu	  	= [SELECT Name FROM User WHERE username =:cname];
        
        HolidayList 		= [SELECT Hours_Used__c, Staff_Member__c, Staff__r.Name, Manager_Name__c
                               FROM Holiday__c
                               WHERE Manager_Name__c =:cu.Name
                               ORDER BY Staff__r.Name];
       
        HoursUsedList 		= [SELECT SUM(Hours_Used__c) hours, Staff__r.Name staff
                               FROM Holiday__c
                               WHERE Manager_Name__c =:cu.Name
                               GROUP BY Staff__r.Name
                               ORDER BY Staff__r.Name asc];
        
        AllowanceTotalList 	= [SELECT SUM(Hours_Available__c) allowance, Name
                              FROM User
                              WHERE Manager__c =:cu.Name
                              GROUP BY Name
                              ORDER BY Name asc];
        
    }
    
    public list<AggregateResult> HoursList {
 	get { return HoursUsedList;}
 	}
    
    public list<AggregateResult> AllowanceList {
 	get { return AllowanceTotalList;}
 	}
}

VF Page:
<apex:page controller="HolidayManagementController" sidebar="false">
    <apex:form>
        <apex:pageBlock>
			<apex:pageBlockTable value="{!HolidayList}" var="hlist">

                <apex:column headerValue="Staff Member">
                <apex:outputField value="{!hlist.Staff__r.Name}"/>
                </apex:column>

                <apex:column headerValue="Manager">
                <apex:outputField value="{!hlist.Manager_Name__c}"/>
                </apex:column>
  
                <apex:column headerValue="Hours Used">
                <apex:outputField value="{!hlist.Hours_Used__c}"/>
                </apex:column>
                
            </apex:pageBlockTable>            
        </apex:pageBlock>
        
        <apex:pageBlock>
        <apex:pageBlockTable value="{!HoursList}" var="h">
        	  
           <apex:column >
            <apex:facet name="header">Staff Member</apex:facet>
            {!h['staff']}</apex:column>
            
            <apex:column >
            <apex:facet name="header">Hours Used</apex:facet>
            {!h['hours']}</apex:column>
            

            
        </apex:pageBlockTable>
            
        <apex:pageBlockTable value="{!AllowanceList}" var="a">
        	  
           <apex:column >
            <apex:facet name="header">Staff Member</apex:facet>
            {!a['Name']}</apex:column>
            
            <apex:column >
            <apex:facet name="header">Hours Available</apex:facet>
            {!a['allowance']}</apex:column>
            

            
        </apex:pageBlockTable>    
            
        </apex:pageBlock>
    </apex:form>
</apex:page>

Any help would be greatly appreciated. I'm pretty new to programming in general so i'm open to suggesstions if i'm going about this the wrong way. 

Thanks
L
  • January 25, 2015
  • Like
  • 1
I am building a Custom object called Product_Interactions__C that logs changes made on Opportunity Products. This is done with a trigger that creates a record on Product_Interactions__c. 

My trigger code:
trigger ProductInteractionChange on OpportunityLineItem (after update) {  
    
    for (OpportunityLineItem I : Trigger.new){
    
        List<Product_Interactions__c> InteractionChangeAdmin = new List<Product_Interactions__c>();
    
    Product_Interactions__c SaveChangeAdmin = new Product_Interactions__c();
        
            
            SaveChangeAdmin.Opportunity__c 					= I.OpportunityId;
        	SaveChangeAdmin.Product_Name_Link__c			= I.Product_Link__c;
            SaveChangeAdmin.Interaction__c 					= I.Message__c;
            SaveChangeAdmin.Department__c 					= 'Admin';
                
            InteractionChangeAdmin.add (SaveChangeAdmin);
            
            insert InteractionChangeAdmin;   	
 
    }
}
On OpportunityLineItem there is also a formula called Product_Link__c:
HYPERLINK("/"&Id,PricebookEntry.Product2.Name)
As a better way to keep track of the records in this object I have also created a Visualforce Page, on this page I have been able to get a direct link to the Opportunity without problem but I am unable to display a hyperlink to the product that was edited. This is what my Visualforce Page looks at the moment:
VF Page

The id displayed in the Product Name column IS the correct one I am just unable to figure out how to display this as a hyperlink on my Visualforce page with the product name as text. I would really appreciate any help on how best to approach this, or if there is an easier way that I am overlooking.

Thanks
L
  • February 19, 2015
  • Like
  • 0
I'm using AggregateResult to display 2 values, first is a sum of a custom field Hours_Used__c which is in a custom object Holiday__c. Second is a sum of a custom field Hours_Available__c which is on the User object.

I am able to show these results separately on my visualforce page shown here:

vfpage

My requirement is to be able to display Hours_Available__c - Hours_Used__c to leave me with a column that shows the Staff Member Name and the total hours that are left.

For example using the screenshot above I would need a pageblocktable that shows:

Staff Member   | Hours Left
Adam west      | 252
Duke Young     | 225
Jim Taylor       | 198

Controller:
public class HolidayManagementController {
    
    Public List<Holiday__c> HolidayList {get;set;}
    Public List<AggregateResult> HoursUsedList;
    Public List<AggregateResult> AllowanceTotalList;
 
    String cname {get;set;}
    
    Public HolidayManagementcontroller(){
        cname		= UserInfo.getUserName();
        user cu	  	= [SELECT Name FROM User WHERE username =:cname];
        
        HolidayList 		= [SELECT Hours_Used__c, Staff_Member__c, Staff__r.Name, Manager_Name__c
                               FROM Holiday__c
                               WHERE Manager_Name__c =:cu.Name
                               ORDER BY Staff__r.Name];
       
        HoursUsedList 		= [SELECT SUM(Hours_Used__c) hours, Staff__r.Name staff
                               FROM Holiday__c
                               WHERE Manager_Name__c =:cu.Name
                               GROUP BY Staff__r.Name
                               ORDER BY Staff__r.Name asc];
        
        AllowanceTotalList 	= [SELECT SUM(Hours_Available__c) allowance, Name
                              FROM User
                              WHERE Manager__c =:cu.Name
                              GROUP BY Name
                              ORDER BY Name asc];
        
    }
    
    public list<AggregateResult> HoursList {
 	get { return HoursUsedList;}
 	}
    
    public list<AggregateResult> AllowanceList {
 	get { return AllowanceTotalList;}
 	}
}

VF Page:
<apex:page controller="HolidayManagementController" sidebar="false">
    <apex:form>
        <apex:pageBlock>
			<apex:pageBlockTable value="{!HolidayList}" var="hlist">

                <apex:column headerValue="Staff Member">
                <apex:outputField value="{!hlist.Staff__r.Name}"/>
                </apex:column>

                <apex:column headerValue="Manager">
                <apex:outputField value="{!hlist.Manager_Name__c}"/>
                </apex:column>
  
                <apex:column headerValue="Hours Used">
                <apex:outputField value="{!hlist.Hours_Used__c}"/>
                </apex:column>
                
            </apex:pageBlockTable>            
        </apex:pageBlock>
        
        <apex:pageBlock>
        <apex:pageBlockTable value="{!HoursList}" var="h">
        	  
           <apex:column >
            <apex:facet name="header">Staff Member</apex:facet>
            {!h['staff']}</apex:column>
            
            <apex:column >
            <apex:facet name="header">Hours Used</apex:facet>
            {!h['hours']}</apex:column>
            

            
        </apex:pageBlockTable>
            
        <apex:pageBlockTable value="{!AllowanceList}" var="a">
        	  
           <apex:column >
            <apex:facet name="header">Staff Member</apex:facet>
            {!a['Name']}</apex:column>
            
            <apex:column >
            <apex:facet name="header">Hours Available</apex:facet>
            {!a['allowance']}</apex:column>
            

            
        </apex:pageBlockTable>    
            
        </apex:pageBlock>
    </apex:form>
</apex:page>

Any help would be greatly appreciated. I'm pretty new to programming in general so i'm open to suggesstions if i'm going about this the wrong way. 

Thanks
L
  • January 25, 2015
  • Like
  • 1