You need to sign in to do that
Don't have an account?
Jim Montgomery
Combine data from 2 seperate custom objects into one list in apex class
I am trying to append data from 2 seperate lists into a single list in an apex class.
I keep getting an error"Illegal assignment from List<AMS_Renewal_Data__c> to List<Apttus_Proposal__Proposal__c> at line 12 column 1".
Class below.
Any assistance will be greatly appreciated!
public with sharing class AMSRDController {
Public List<apttus_proposal__Proposal__c> RenewalData{get;set;}
Public List<apttus_proposal__Proposal__c> Junk{get;set;}
Public AMSRDController() {
GetRenewalData();
GetJunk();
GetCombinedList();
}
Public Void GetRenewalData()
{
RenewalData = [select product_description__c from AMS_Renewal_Data__c where id = :ApexPages.currentPage().getParameters().get('id')];
}
Public Void GetJunk()
{
Junk = [select product_description__c from Apttus_Proposal__Proposal_Line_Item__c where id = :ApexPages.currentPage().getParameters().get('id')];
}
Public List<apttus_proposal__Proposal__c> GetCombinedList()
{
List<apttus_proposal__Proposal__c> CombinedItems=new List<apttus_proposal__Proposal__c>();
CombinedItems.addAll(RenewalData);
CombinedItems.addAll(Junk);
return CombinedItems;
}
}
I keep getting an error"Illegal assignment from List<AMS_Renewal_Data__c> to List<Apttus_Proposal__Proposal__c> at line 12 column 1".
Class below.
Any assistance will be greatly appreciated!
public with sharing class AMSRDController {
Public List<apttus_proposal__Proposal__c> RenewalData{get;set;}
Public List<apttus_proposal__Proposal__c> Junk{get;set;}
Public AMSRDController() {
GetRenewalData();
GetJunk();
GetCombinedList();
}
Public Void GetRenewalData()
{
RenewalData = [select product_description__c from AMS_Renewal_Data__c where id = :ApexPages.currentPage().getParameters().get('id')];
}
Public Void GetJunk()
{
Junk = [select product_description__c from Apttus_Proposal__Proposal_Line_Item__c where id = :ApexPages.currentPage().getParameters().get('id')];
}
Public List<apttus_proposal__Proposal__c> GetCombinedList()
{
List<apttus_proposal__Proposal__c> CombinedItems=new List<apttus_proposal__Proposal__c>();
CombinedItems.addAll(RenewalData);
CombinedItems.addAll(Junk);
return CombinedItems;
}
}
I have corrected, but still don't know how to get all of this in one list at the bottom. Compile Error: Invalid type: CombinedItems at line 20 column 44
public with sharing class AMSRDController {
Public List<AMS_Renewal_Data__c> RenewalData{get;set;}
Public List<apttus_proposal__proposal_line_item__c> Junk{get;set;}
Public AMSRDController() {
GetRenewalData();
GetJunk();
GetCombinedList();
}
Public Void GetRenewalData()
{
RenewalData = [select product_description__c from AMS_Renewal_Data__c where id = :ApexPages.currentPage().getParameters().get('id')];
}
Public Void GetJunk()
{
Junk = [select product_description__c from Apttus_Proposal__Proposal_Line_Item__c where id = :ApexPages.currentPage().getParameters().get('id')];
}
Public List<apttus_proposal__Proposal__c> GetCombinedList()
{
List<CombinedItems> CombinedItems=new List<CombinedItems>();
CombinedItems.addAll(RenewalData);
CombinedItems.addAll(Junk);
return CombinedItems;
}
}
Please refer above mentioned code. You will have to use List<Sobject> if you want to store the values of different objects in a single list.
public with sharing class AMSRDControllerExtension {
Public AMSRDControllerExtension(ApexPages.StandardController stdController){}
Public List<AMS_Renewal_Data__c> RenewalData{get;set;}
Public List<apttus_proposal__proposal_line_item__c> Junk{get;set;}
Public AMSRDControllerExtension() {
GetRenewalData();
GetJunk();
GetCombinedList();
}
Public Void GetRenewalData()
{
RenewalData = [select product_description__c from AMS_Renewal_Data__c where id = :ApexPages.currentPage().getParameters().get('id')];
}
Public Void GetJunk()
{
Junk = [select product_description__c from Apttus_Proposal__Proposal_Line_Item__c where id = :ApexPages.currentPage().getParameters().get('id')];
}
Public List<SObject> GetCombinedList()
{
List<SObject> CombinedItems=new List<SObject>();
CombinedItems.addAll(RenewalData);
CombinedItems.addAll(Junk);
return CombinedItems;
}
}
You're trying to combine two lists of different data types.
I noticed you only have product_description__c as the common field in both lists.
1. You can change the data type for the lists to String and only store product description. Then, combine at the end
Can you please let us know what exactly you want to achieve? We can better assist you if we know the actual requirement.
Thanks,
Pankaj
Jim Montgomery Manager, Sales Intelligence Operations Wolters Kluwer Tax & Accounting 20101 Hamilton Ave. Torrance, CA 90502 877-346-7148 jim.montgomery@wolterskluwer.com
VF Page:
Class
public with sharing class AMSRDControllerExtension {
Public List<AMS_Renewal_Data__c> RenewalData{get;set;}
Public List<apttus_proposal__proposal_line_item__c> Junk{get;set;}
Public List<Object> CombinedItems {get;set;}
Public AMSRDControllerExtension(ApexPages.StandardController stdController){
GetRenewalData();
GetJunk();
GetCombinedList();
}
Public Void GetRenewalData()
{
RenewalData = new list<ams_renewal_data__c>([select product_description__c from AMS_Renewal_Data__c where Proposal_id__c = :ApexPages.currentPage().getParameters().get('id')]);
}
Public Void GetJunk()
{
Junk = new List<apttus_proposal__proposal_line_item__c>([select product_description__c from Apttus_Proposal__Proposal_Line_Item__c where apttus_proposal__Proposal__c = :ApexPages.currentPage().getParameters().get('id')]);
}
Public Void GetCombinedList()
{
CombinedItems=new List<Object>();
CombinedItems.addAll((List<object>)RenewalData);
CombinedItems.addAll((List<object>)Junk);
}
}
Page
<apex:page StandardController="Apttus_Proposal__Proposal__c" extensions="AMSRDControllerExtension" sidebar="False" showHeader="false" pageStyle="width:1100px;" >
<head>
<style type="text/css">
textarea {
resize: none;
}
@media print
{
.noprint {display:none;}
.Break {page-break-before:Always;}
.Body {zoom:120%;}
}
@media screen
{
.medium {color: #F00;}
}
</style>
</head>
<apex:form >
<div class="noprint">
<apex:Pageblock >
<apex:commandButton value="Print" onclick="window.print()" />
</apex:Pageblock>
</div>
<body class="Body">
<b><apex:outputLabel style="position:fixed;left:300px;font-size:25px;" Value="2016 CCH"/><apex:outputLabel style="position:fixed;left:417px;" value="®"/></b>
<b><apex:outputLabel style="position:fixed;left:427px;font-size:25px;" Value="Prosystem fx"/><apex:outputLabel style="position:fixed;left:585px;" value="®"/></b>
<b><apex:outputLabel style="position:fixed;font-size:25px;left:600px;" value="Renewal Notice"/></b>
<apex:outputLabel style="position:fixed;left:900px;" Value="Account #:"/>
<apex:outputText value="{!Apttus_Proposal__Proposal__c.AMS_Account_Number__c}" style="position:fixed;left:975px;"/>
<br/>
<apex:outputLabel style="position:fixed;left:900px;" Value="Order#:"></apex:outputLabel>
<apex:outputText value="{!Apttus_Proposal__Proposal__c.Contract_Number__c}" style="position:fixed;left:975px;"/>
<br/>
<BR/>
<apex:outputLabel style="position:fixed;left:250px;border:1px solid;" value="RENEW BY FAX:1-866-584-3582"/>
</body>
<br/>
<be/>
<apex:pageBlock >
<apex:pageBlockTable value="{!RenewalData}" var="Items">
<apex:Column value="{!Items.Product_Description__c}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>