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
Sascha DeinertSascha Deinert 

Unknown property 'Integer.Amount'

Hi,

If I try to save the apex code, I get the error Unknown property 'Integer.Amount'
Could you help me to fix the problem.

Thanks,
Sascha
 
<apex:page controller="VTPTeam7_class">

<apex:form >

<apex:pageblock >
    <apex:pageBlockButtons location="top" >
        <apex:commandButton action="{!myAnalyze2}" value="Search" id="SearchButton" style="align:center"/>      
    </apex:pageBlockButtons>         
    <table border="1">
        <tr>
            <td>Target Name</td>
            <apex:repeat value="{!RTypeList}" var="RL">
            <td>
                <apex:outputfield value="{!RL.Name}"/>
            </td>
            </apex:repeat>
        </tr>
        <apex:repeat value="{!ValueList}" var="VL1">
        <tr>
            <td>
                <apex:outputField value="{!VL1.Owner.Name}"/>
            </td>
            <apex:repeat value="{!Summaries}" var="VL2">
            <td>
                {!VL2.Amount}
            </td>
            </apex:repeat>               
        </tr>
        </apex:repeat>
    </table>         
</apex:pageblock>

</apex:form>

</apex:page>
 
Public Class VTPTeam7_class {

Public List <RecordType> RTypeList {get; set;}
Public List <User> UserList {get; set;}
Public List <Opportunity> ValueList {get; set;}
Public List <Integer> Summaries {get; set;}

Public VTPTeam7_class() {

}

Public void myAnalyze2() {

    RTypeList = [SELECT Id, Name FROM RecordType WHERE SobjectType = 'Opportunity'];
    UserList = [SELECT Id, Name FROM User WHERE Team__c = 'Team Bayern'];
    
    List <Integer> Summaries = new List <Integer>();
    
    FOR (User UserName : [SELECT Id, Name FROM User WHERE Team__c = 'Team Bayern']) {
        FOR (RecordType RType : [SELECT Id, Name FROM RecordType WHERE SobjectType = 'Opportunity']) {
            ValueList = [SELECT Owner.Id, Owner.Name, RecordType.Id, Amount FROM Opportunity WHERE Owner.Id = :UserList AND RecordType.Id = :RTypeList];           
                IF (ValueList.size()==0) {
                    Summaries.Add(0);
                }
                ELSE {
                    Summaries.Add(1);
                }
        }
   }
}

}

 
pconpcon
The problem is that the variable Summaries is of type integer so there is no child variable named amount.  You need to alter you VF page so that line 25 reads:
 
{!VL2}

 
Sascha DeinertSascha Deinert
@pcon

Thanks, I changed the code and now I get a list.

But my result is not very nice, it looks like

Target Name | RecordType 1 | RecordType 2 | RecordType 3
User 1          |           100000 |            40000 |           300000 |        2500000 |      100000
User 1          |           100000 |            40000 |           300000 |        2500000 |      100000
User 2          |           100000 |            40000 |           300000 |        2500000 |      100000
User 3          |           100000 |            40000 |           300000 |        2500000 |      100000
User 3          |           100000 |            40000 |           300000 |        2500000 |      100000

I get for each user (row) all opportunities of all user.
How can I change the code to show like this 

Target Name | RecordType 1 | RecordType 2 | RecordType 3
User 1          |                    0 |                   0 |           300000 
User 1          |                    0 |            40000 |                    0          
User 2          |           100000 |                   0 |                    0 
User 3          |         2500000 |                   0 |                    0
User 3          |                   0 |                   0 |           100000
 
Public Class VTPTeam8_class {

Public List <RecordType> RTypeList {get; set;}
Public List <User> UserList {get; set;}
Public List <Opportunity> ValueList {get; set;}

Public VTPTeam8_class() {

}

Public void myAnalyze2() {

    RTypeList = [SELECT Id, Name FROM RecordType WHERE SobjectType = 'Opportunity'];
    UserList = [SELECT Id, Name FROM User WHERE Team__c = 'Team XXXX'];
     
            ValueList = [SELECT Owner.Id, Owner.Name, RecordType.Id, Amount FROM Opportunity WHERE Owner.Id = :UserList AND RecordType.Id = :RTypeList];             
}
   
}
Thanks,
Sascha
Sascha DeinertSascha Deinert
@pcon,

could you take a look again to my code. 

Thanks,
Sascha
pconpcon
What you are trying to do is not an easy thing.  Below is some code that should help you out.  It probably will not work right away since I haven't tested it but it should get you going in the right direction.

Page Controller
public class VTPTeam8_class {
    private Map<Id, RecordType> rTypeMap;
    private Map<Id, User> userMap;

    public class OppRecord {
        public String Name {get; set;}
        private Map<Id, Integer> amtMap {get; set;}

        public oppRecord(Opportunity opp, Map<Id, User> userMap) {
            this.Name = userMap.get(opp.OwnerId);
            this.amtMap.put(opp.RecordTypeId, opp.Amount);
        }
    }

    public List<OppRecord> oppRecords {get; set;}

    public VTPTeam8_class() {}

    public void myAnalyze2() {
        this.rTypeMap = new Map<Id, RecordType>([
            select Name
            from RecordType
            where SobjectType = 'Opportunity'
        ]);

        this.userMap = new Map<Id, User>([
            select Name
            from User
            where Team__c = 'Team XXXX'
        ]);

        this.oppRecords = new List<OppRecord>();

        for (Opportunity opp: [
            select OwnerId,
                RecordTypeId,
                Amount
            from Opportunity
            where OwnerId in :this.userMap.keys() and
                RecordTypeId in :this.rTypeMap.keys()
        ]) {
            this.oppRecords.add(new OppRecord(opp, this.userMap));
        }
    }

    public List<RecordType> getRecordTypes() {
        return this.rTypeMap.values();
    }
}

Component Controller
public class getOppAmount_Controller {
    public Id rTypeId {get; set;}
    public Map<Id, Integer> amtMap {get; set;}

    public getOppAmount_Controller() {}

    public Integer getAmount() {
        return (this.amtMap.containsKey(this.rTypeId)) ? this.amtMap.get(this.rTypeId) : 0;
    }
}

Component
<apex:component controller="getOppAmount_Controller">
    <apex:attribute name="rt" description="Record Type Id" type="String" required="required" assignTo="rTypeId" />
    <apex:attribute name="amt" description="Record Type Id to Amount map" type="map" required="required" assignTo="amtMap" />
    {!amount}
</apex:component>

Page
<apex:page controller="VTPTeam7_class">
    <apex:form >
        <apex:pageblock >
            <apex:pageBlockButtons location="top" >
                <apex:commandButton action="{!myAnalyze2}" value="Search" id="SearchButton" style="align:center"/>
            </apex:pageBlockButtons>
            <table border="1">
                <tr>
                    <td>Target Name</td>
                    <apex:repeat value="{!recordTypes}" var="rt">
                        <td>
                            <apex:outputfield value="{!rt.Name}"/>
                        </td>
                    </apex:repeat>
                </tr>
                <apex:repeat value="{!oppRecords}" var="or">
                    <tr>
                        <td>
                            <apex:outputField value="{!or.Name}"/>
                        </td>
                        <apex:repeat value="{!recordTypes}" var="rt">
                            <td>
                                <c:getOppAmount rt="{!rt.Id}" amt="{or.amtMap}" />
                            </td>
                        </apex:repeat>               
                    </tr>
                </apex:repeat>
            </table>         
        </apex:pageblock>
    </apex:form>
</apex:page>

NOTE: This code may contain typographical or logical errors
Sascha DeinertSascha Deinert
@pcon, 

thanks for your respone.

I get an error if I run your code 

Method does not exist or incorrect signature: [Map<Id,User>].keys() at line 39 column 31

Could you please take a look.

Thanks,
Sascha
pconpcon
Sorry, line 39 and 40 should read
 
where OwnerId in :this.userMap.keySet() and
    RecordTypeId in :this.rTypeMap.keySet()
Sascha DeinertSascha Deinert
@pcon,

I tried your code, but I get an error:

Illegal assignment from User to String at line 10 column 13

I want to change the string into id, but the I get the same error with id.
pconpcon
Sorry for the delay (I was on vacation and then at Dreamforce).  Line 10 of the controller should read:
 
this.Name = userMap.get(opp.OwnerId).Name;
Sascha DeinertSascha Deinert
Thanks for your respnse again. 
No problem, vacaction is ok, I'm glad that you hlep me again and again and again :-)

I get one more error. If I try to save the component I get the following error

Type mismatch for <apex:attribute assignTo>. Value binding to a property of type Map<Object,Object> is required, property specified (amtMap) is of type Map<Id,Integer>.
pconpcon
Ok, this means you'll have to modify the controller a little bit
 
public class getOppAmount_Controller {
    public Id rTypeId {get; set;}
    public Map<Object, Object> amtMap {get; set;}

    public getOppAmount_Controller() {}

    public Integer getAmount() {
        Map<Id, Integer> tmpAmtMap = (Map<Id, Integer>)(this.amtMap);
        return (tmpAmtMap.containsKey(this.rTypeId)) ? tmpAmtMap.get(this.rTypeId) : 0;
    }
}

Sorry I wasn't able to actually test this.  Most of this is coming off the top of my head and I'm just praying it works :)
Sascha DeinertSascha Deinert
Sorry, but I get the next errors.

[Error] Error: getOppAmount line 4, column 22: Element type "Object" must be followed by either attribute specifications, ">" or "/>"
[Error] Error: Element type "Object" must be followed by either attribute specifications, ">" or "/>".
pconpcon
Ok, so I broke down and configured my Sandbox in a way that will allow me to do this.  Here is the code that I have that seems to work.  The page will need some formatting

VTPTeam8_class.cls
public class VTPTeam8_class {
    private Map<Id, RecordType> rTypeMap;
    private Map<Id, User> userMap;

    public class OppRecord {
        public String Name {get; set;}
        private Map<Id, Decimal> amtMap;
        
        public OppRecord() {
            this.amtMap = new Map<Id, Decimal>();
        }

        public oppRecord(Opportunity opp, Map<Id, User> userMap) {
            this();
            this.Name = userMap.get(opp.OwnerId).Name;
            this.amtMap.put(opp.RecordTypeId, opp.Amount);
        }
                 
        public String getAmtMapStr() {
            return JSON.serialize(this.amtMap);
        }
        
        public String getName() {
            return this.Name;
        }
    }

    public List<OppRecord> oppRecords {get; set;}

    public VTPTeam8_class() {
		this.rTypeMap = new Map<Id, RecordType>([
            select Name
            from RecordType
            where SobjectType = 'Opportunity'
        ]);

        this.userMap = new Map<Id, User>([
            select Name
            from User
            where Team__c = 'Team XXXX'
        ]);

    }

    public void myAnalyze2() {
        this.oppRecords = new List<OppRecord>();

        for (Opportunity opp: [
            select OwnerId,
                RecordTypeId,
                Amount
            from Opportunity
            where OwnerId in :this.userMap.keySet() and
                RecordTypeId in :this.rTypeMap.keySet()
        ]) {
            this.oppRecords.add(new OppRecord(opp, this.userMap));
        }
    }

    public List<RecordType> getRecordTypes() {
        return this.rTypeMap.values();
    }
}
getOppAmount_Controller.cls
public class getOppAmount_Controller {
    public Id rTypeId {get; set;}
    public String amtMapStr {get; set;}
    private Map<Id, Decimal> amtMap;
    
    public Map<Id, Decimal> getAmtMap() {
        if (this.amtMap == null) {
            this.amtMap = new Map<Id, Decimal>();
            Map<String, Object> tmpAmtMap = (Map<String, Object>)(JSON.deserializeUntyped(this.amtMapStr));
            
            for (String key : tmpAmtMap.keySet()) {
                this.amtMap.put((Id)(key), (Decimal)(tmpAmtMap.get(key)));
            }
        }
        
        return this.amtMap;
    }

    public getOppAmount_Controller() {}

    public Decimal getAmount() {
        return (getAmtMap().containsKey(this.rTypeId)) ? getAmtMap().get(this.rTypeId) : 0;
    }
}
getOppAmt.component
<apex:component controller="getOppAmount_Controller">
    <apex:attribute name="rt" description="Record Type Id" type="String" required="required" assignTo="{!rTypeId}" />
    <apex:attribute name="amt" description="JSON String representing amount map" type="string" required="required" assignTo="{!amtMapStr}" />
    {!amount}
</apex:component>
TeamClass.page
<apex:page controller="VTPTeam8_class">
    <apex:form >
        <apex:pageblock >
            <apex:pageBlockButtons location="top" >
                <apex:commandButton action="{!myAnalyze2}" value="Search" id="SearchButton" style="align:center"/>
            </apex:pageBlockButtons>
            <table border="1">
                <tr>
                    <td>Target Name</td>
                    <apex:repeat value="{!recordTypes}" var="rt">
                        <td>
                            <apex:outputfield value="{!rt.Name}"/>
                        </td>
                    </apex:repeat>
                </tr>
                <apex:repeat value="{!oppRecords}" var="or">
                    <tr>
                        <td>
                            <apex:outputText value="{!or.Name}" />
                        </td>
                        <apex:repeat value="{!recordTypes}" var="rt">
                            <td>
                                <c:getOppAmt rt="{!rt.Id}" amt="{!or.amtMapStr}" />
                            </td>
                        </apex:repeat>               
                    </tr>
                </apex:repeat>
            </table>         
        </apex:pageblock>
    </apex:form>
</apex:page>

I had to do some "interesting" work around sending the amount map to the component, but it does work.
Sascha DeinertSascha Deinert
cool, it works. great.

It is possible to change the code very easy to aggregate the values of each user and opportunity.recordtype?
pconpcon
Yes, here is the updated controller code to do that.  All the other parts stay the same
 
public class VTPTeam8_class {
    private Map<Id, RecordType> rTypeMap;
    private Map<Id, User> userMap;
    private Map<Id, List<Opportunity>> userOppMap;
    private List<Opportunity> opportunities;
    
    public static String TEAM_NAME = 'Team XXXX';

    public class OppRecord {
        public String Name {get; set;}
        private Map<Id, Decimal> amtMap;
        
        public OppRecord() {
            this.amtMap = new Map<Id, Decimal>();
        }

        public oppRecord(List<Opportunity> oppList, Set<Id> rTypes, User user) {
            this();
            
			this.Name = user.Name;
            
            for (Id id : rTypes) {
                this.amtMap.put(id, 0);
            }
            
            for (Opportunity opp : oppList) {
                if (opp.OwnerId == user.Id) {
                	this.amtMap.put(opp.RecordTypeId, (this.amtMap.get(opp.RecordTypeId) + opp.Amount));
                }
            }
        }
                 
        public String getAmtMapStr() {
            return JSON.serialize(this.amtMap);
        }
        
        public String getName() {
            return this.Name;
        }
    }

    public List<OppRecord> oppRecords {get; set;}

    public VTPTeam8_class() {
		this.rTypeMap = new Map<Id, RecordType>([
            select Name
            from RecordType
            where SobjectType = 'Opportunity'
        ]);

        this.userMap = new Map<Id, User>([
            select Name
            from User
            where Team__c = :teamName
        ]);

    }

    public void myAnalyze2() {
        this.oppRecords = new List<OppRecord>();

        opportunities = [
            select OwnerId,
                RecordTypeId,
                Amount
            from Opportunity
            where OwnerId in :this.userMap.keySet() and
                RecordTypeId in :this.rTypeMap.keySet()
        ];
        
        for (Id id : this.userMap.keySet()) {
            this.oppRecords.add(new OppRecord(this.opportunities, this.rTypeMap.keySet(), this.userMap.get(id)));
        }
    }

    public List<RecordType> getRecordTypes() {
        return this.rTypeMap.values();
    }
}