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
dboonepesdboonepes 

Property access error.

I have created a join/junction object to allow many-to-many relationships between cases and assets. I am currently trying to develop a simplified UI to add assets to cases. The basic idea is that one would click on a button on the case layout and be presented a page with all of the assets related to the account related to the case.  The user will check next to all of the assets to be added to the case and then click a button add them to the case. I have just started writing the code for it and have hit a road block. 

 

I have created a wrapper class.

 

public class accountasset {

    /* Properties of the class */
    public ID assetID { get; private set; }
    public boolean selected   { get; private set; }
    public string name   { get; private set; }
    public string room { get; private set; }
    
    /* Class constructor */
    public AccountAsset(ID i, boolean s, String n, String r) {
        assetID   = i;
        selected = s;
        name    = n;
        room   = r;
    }
    
}

  And the class directly accessed by the VF page

public class AddAssetsToCase {
    
    /* Property value that holds the current Case */
    public Case myCase { get; set; }

    /* Property value that holds the current Account */
    public Account myAccount  { get; set; }

    /* Constructor of the class where we default the above property values */
    public AddAssetsToCase(){
        mycase = [SELECT id, description, subject, accountid FROM Case WHERE id = :ApexPages.currentPage().getParameters().get('id')];
        
        myaccount = [SELECT id, name,
            (SELECT Id, Name, Room__c          FROM Assets) 
        FROM account 
        WHERE id = :mycase.accountid];    
    }   
    
    /* Action method for navigating the user back to the case page. */
    public PageReference backToCase() {
        return new ApexPages.StandardController(mycase).view();
    }

    /* Accessor for retrieving the case object.*/
    public Case getCase() { 
        return mycase; 
    }
    
    /* Accessor for retrieving the case object and its related items.*/
    public Account getAccount() { 
        return myaccount; 
    }
    
    /* This accessor provides the page with the ordered collection of history (apex) objects for display in the page. 
       it also processes the truncation of case comments as specified by the fullComments property value.*/
    public AccountAsset[] getAccountAssets() {
        AccountAsset[] accountassets = new accountasset[]{};
        for (Asset aa:a.assets) {
        accountasset naa = new accountasset(aa.id,False,aa.name,aa.room__c);
                accountassets.add(naa); 
        }
        
        return accountassets;
    }
    

    /* The case object set by the getCase method and used by the getHistories method to acquire
       the related records.  */
    private Account a { 
        get { return getAccount(); }
        set; 
    }
     
}

 and finally a VF page

<apex:page controller="AddAssetsToCase">
    <apex:sectionHeader title="Add Assets to Case" subtitle="Case: {!Case.subject} for Account: {!Account.Name}"/>
    <apex:pageBlock >
       <apex:Form >
            <apex:PageBlockTable value="{!accountassets}" var="a">
                <apex:column headerValue="Select?">
                    <apex:inputCheckbox value="{!a.selected}"/>
                </apex:column>
                <apex:Column value="{!a.name}" headerValue="Name"/>
                <apex:Column value="{!a.room}" headerValue="Room"/>
            </apex:PageBlockTable>
        </apex:Form>
    </apex:pageBlock>
</apex:page>

 When I try and save the VF page as above I get the following error.

Error: Read only property 'accountasset.selected'

 

What am I doing wrong here?

Best Answer chosen by Admin (Salesforce Developers) 
Cory CowgillCory Cowgill

remove private from the set.

 

public boolean selected {get;set;}

All Answers

Cory CowgillCory Cowgill

remove private from the set.

 

public boolean selected {get;set;}

This was selected as the best answer
dboonepesdboonepes

Thanks for the help. I figured it was something pretty simple I was overlooking. I am pretty new to Apex and OOP, if you couldn't tell.

Cory CowgillCory Cowgill

No problem. Glad to help.