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
JamesCoopeViconJamesCoopeVicon 

Problem getting vaules form apex input filed

I am trying to create assets from product line items when a ship button in clicked on the line item related list. The ship button extends the save function for the line items.When the ship button is clicked the inputeed data is saved correctly but it is not available to the controller so the loop that creates assets does not work.

If I click the ship button again. the vaules are set from the previous save and assets are created correctly.

 

Does any one have any idea how to get this to work the first time the button is clicked?

 

 

 

>> Below is the controller code and visualforce page... 

 

 public class Ship_Controller {

 

    /* The standard controller object which will be used later for navigation and to invoke

       it's save action method to create the new shipment. */

    ApexPages.StandardController controller;

/* The shipment property which is used by the shipmentNew and shipmentPDF Pages and this controller

    to provide access to the relevant shipment information. */

private final shipment__c sh {get;set;}

public List<ItemSerialNoList> AssetList {get; set;}

public Ship_Controller(ApexPages.StandardController c) {

        controller = c;

        sh = (shipment__c) c.getRecord(); 

        

        sh.Sales_Order_Handoff__c = ApexPages.currentPage().getParameters().get('SOH');  

System.debug('****** new shipment =' + sh.Sales_Order_Handoff__c);

AssetList = getAssetList();

    }

    

  //  public List<SCRB_SalesOrderLineItem__c> ItemList {get; set;}

 

    public List<ItemSerialNoList> getAssetList(){

        if(AssetList == null){

           AssetList = new List<ItemSerialNoList>();  

           List<Asset> s = new List<Asset>();

           for(SCRB_SalesOrderLineItem__c i : [select Id, Shipped__c,Name, Quantity__c, QuantityShipped__c, ProductId__c,SalesOrderId__r.AccountId__c,SalesOrderId__r.Contact__c from SCRB_SalesOrderLineItem__c  where SalesOrderId__c = :sh.Sales_Order_Handoff__c AND Shipped__c = :false]){  

  System.debug('\n ******' +sh.Sales_Order_Handoff__c);            

                AssetList.add(new ItemSerialNoList(i));

                for (Double qty = i.QuantityShipped__c; qty < i.Quantity__c; qty +=1) {              

AssetList.get(0).assets.add(new Asset(

Name = i.Name,

               AccountId = i.SalesOrderId__r.AccountId__c, 

               ContactId = i.SalesOrderId__r.Contact__c,   

               Product2Id = i.ProductId__c,

               Sales_Order_Item__c = i.Id,

shipment__c  = controller.getId()

));

                }

                

 

            }

       }

       return AssetList;

    }

   

 

    public PageReference save(){

Pagereference p = controller.save();

        List<Asset> newAssets = new List<Asset>();

        List<SCRB_SalesOrderLineItem__c> items = new List<SCRB_SalesOrderLineItem__c>();

   for(ItemSerialNoList i : getAssetList()){

    items.add(i.item);

    System.debug('/n/n ****** new shipment =' + i.item.name);

            for(Asset a : i.assets){

           newAssets.add(a);   

           items.get(0).QuantityShipped__c +=1;

             if(items.get(0).QuantityShipped__c == items.get(0).Quantity__c){

           items.get(0).Shipped__c = true;

           }

                    

            }    

    }      

       try {

       insert sh;

           update items;

           insert newAssets;

       } catch(System.DMLException e) {

           ApexPages.addMessages(e);

           return null;

       }

       

       /* Return the page reference generated by the standard controller save, which usually drops the user

           on the detail page for the newly created object. */

        return p;

    }

 

<apex:page standardController="SCRB_SalesOrderLineItem__c" recordSetVar="SCRB_SalesOrderLineItem__c" tabStyle="SCRB_SalesOrderLineItem__c" extensions="shipSOHext">

    <apex:form>

        <apex:pageBlock title="Edit Ship details" mode="edit">

            <apex:pageMessages />

            <apex:pageBlockButtons location="top">

                <apex:commandButton value="Save" action="{!save}"/>

                <apex:commandButton value="Cancel" action="{!cancel}"/>

            </apex:pageBlockButtons> 

            <apex:pageBlockTable value="{!selected}" var="i">

                <apex:column value="{!i.SalesOrderId__r.AccountId__c}"/>

                <apex:column value="{!i.SalesOrderId__r.Contact__c}"/>

                <apex:column value="{!i.ProductId__c}"/>

                <apex:column value="{!i.Item_notes__c}"/>

                <apex:column value="{!i.Name}"/>

                <apex:column value="{!i.Quantity__c}"/>

                <apex:column value="{!i.QuantityShipped__c}"/>

                <apex:column value="{!i.Shipped__c}"/>                

                <apex:column headerValue="Ship Qty" rendered="{!NOT(i.Shipped__c)}">

                    <apex:inputField value="{!i.QuantityToShip__c}" id="inputdata"/>

                </apex:column>                

            </apex:pageBlockTable>      

         </apex:pageBlock>

         <apex:panelGrid columns="2">

            <apex:commandLink action="{!previous}">Previous</apex:commandlink>

            <apex:commandLink action="{!next}">Next</apex:commandlink>

         </apex:panelGrid>        

    </apex:form>

    </apex:page>