• Enrique Diaz
  • NEWBIE
  • 10 Points
  • Member since 2020
  • CRM Admin


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies

Hello to all,
I'm new on this and I'm stuck. Any help will be very appreciated.
I would like to use this VF page on a detail buttom. I'm trying to view all WPage__c object existing records and select some of them and add them on a related list of Section_selections__c object. Here is my code

/**VisualForce page*/ 

<apex:page standardController="Section_selections__c" extensions="ViewAvailableWPages">
   <apex:form >  
    <apex:pageBlock >
            <apex:pageBlockButtons >      
                <apex:commandButton action="{!updateWPages}" value="Update WPages"/>                       
                </apex:pageBlockButtons>
        
            <apex:pageBlockSection >
                <apex:pageBlockTable title="All WPages" var="a" value="{!allWPages}">
                    <apex:column headerValue="Select">
                        <apex:inputCheckbox value="{!a.selected}" />
                    </apex:column>
                    <apex:column value="{!a.WPage__c.Name}" headerValue="WPage Name"/>
                </apex:pageBlockTable>
               </apex:pageBlockSection>
       </apex:pageBlock>
     </apex:form>     
</apex:page>

/**Apex class*/:

public class ViewAvailableWPages {
    public List<WPage__c> selectedWPagees;
    public List<WPageRecord> allWPages{get;set;}
    public ViewAvailableWPages(ApexPages.StandardController controller) {
        populateAllWPages();
    }    
   public void populateAllWPages()
    {
        allWPages = new List<WPageRecord>();
        List<WPage__c> WPages = [Select Name,State__c,WPage_URL__c From WPage__c Where Section_selections__c = null Order By Name];
        for(WPage__c a: WPages){
        allWPages.add(new WPageRecord(a));            
        }
    }
  
        public PageReference updateWPages(){
        selectedWPages  = new List<WPage__c>();
        String SectionSelectionsId = ApexPages.currentPage().getParameters().get('id');
        Section_selections__c SectionSelections = [Select Id From Section_selections__c Where Id = :SectionSelectionsId];
        for(WPageRecord pr : allWPages)
        {
            system.debug(pr.selected);
            if(pr.selected)
            {
                WPage__c WPage = pr.WPage;
                WPage.Section_selections__c = SectionSelectionsId;
                selectedWPages.add(WPage);
            }
        }
        update selectedWPages;
        PageReference prf = new ApexPages.StandardController(SectionSelections).view();
        prf.setRedirect(true);
        return prf;
    }
    
    public class WPageRecord {
        public Boolean selected {get;set;}
        public WPage__c WPage {get;set;}
        
        public WPageRecord(WPage__c WPage){
            selected = false;
            this.WPage= WPage;
        }
    }   
}

Hello to all,
I'm new on this and I'm stuck. Any help will be very appreciated.
I would like to use this VF page on a detail buttom. I'm trying to view all WPage__c object existing records and select some of them and add them on a related list of Section_selections__c object. Here is my code

/**VisualForce page*/ 

<apex:page standardController="Section_selections__c" extensions="ViewAvailableWPages">
   <apex:form >  
    <apex:pageBlock >
            <apex:pageBlockButtons >      
                <apex:commandButton action="{!updateWPages}" value="Update WPages"/>                       
                </apex:pageBlockButtons>
        
            <apex:pageBlockSection >
                <apex:pageBlockTable title="All WPages" var="a" value="{!allWPages}">
                    <apex:column headerValue="Select">
                        <apex:inputCheckbox value="{!a.selected}" />
                    </apex:column>
                    <apex:column value="{!a.WPage__c.Name}" headerValue="WPage Name"/>
                </apex:pageBlockTable>
               </apex:pageBlockSection>
       </apex:pageBlock>
     </apex:form>     
</apex:page>

/**Apex class*/:

public class ViewAvailableWPages {
    public List<WPage__c> selectedWPagees;
    public List<WPageRecord> allWPages{get;set;}
    public ViewAvailableWPages(ApexPages.StandardController controller) {
        populateAllWPages();
    }    
   public void populateAllWPages()
    {
        allWPages = new List<WPageRecord>();
        List<WPage__c> WPages = [Select Name,State__c,WPage_URL__c From WPage__c Where Section_selections__c = null Order By Name];
        for(WPage__c a: WPages){
        allWPages.add(new WPageRecord(a));            
        }
    }
  
        public PageReference updateWPages(){
        selectedWPages  = new List<WPage__c>();
        String SectionSelectionsId = ApexPages.currentPage().getParameters().get('id');
        Section_selections__c SectionSelections = [Select Id From Section_selections__c Where Id = :SectionSelectionsId];
        for(WPageRecord pr : allWPages)
        {
            system.debug(pr.selected);
            if(pr.selected)
            {
                WPage__c WPage = pr.WPage;
                WPage.Section_selections__c = SectionSelectionsId;
                selectedWPages.add(WPage);
            }
        }
        update selectedWPages;
        PageReference prf = new ApexPages.StandardController(SectionSelections).view();
        prf.setRedirect(true);
        return prf;
    }
    
    public class WPageRecord {
        public Boolean selected {get;set;}
        public WPage__c WPage {get;set;}
        
        public WPageRecord(WPage__c WPage){
            selected = false;
            this.WPage= WPage;
        }
    }   
}

Hi,

I have 1 custom object "Loan__c" with master-detail relationship to Account (used for loan of equipments).
I am planning to use the Asset object to manage my stock of loan equipments.
I created a custum field "LoanRef__c" into Asset with look-up relationship to the Loan__c object.

I have a related list "Assets" in the "Loan__c" object - I'd like to add a custom list button there to add existing asset records to this loan. When clicked, the list of all existing asset records must be shown with ability to check the ones I want to add to the loan.

I guess I need to develop an apex class + visual force page.
I'm a novice with apex and visual force but I tried to adapt some similar codes found on the forum, with no success.

Any idea?

Thanks