• JamesCoopeVicon
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 5
    Replies

Below is a controller I have written to allow the update of OpportunityLineItem Quantity_Shipped__c with a VF page I have created. Please can someone help write a test for this.

 

 

public class OppLineListCon {

 

    public PageReference cancel() {

        Pagereference p = new Pagereference('/' + Apexpages.currentPage().getParameters().get('id'))  ; 

        p.setRedirect(true);    

        return p;

    }

 

    public List<OpportunityLineItem> LineItems {

        get {

            LineItems = [select 

                    TotalPrice, 

                    UnitPrice, 

                    Quantity, 

                    PricebookEntry.Product2.Name, 

                    PricebookEntry.Product2.Description,                    

                    Quantity_Shipped__c, 

                    Description  

                    from OpportunityLineItem 

                    where OpportunityId = :Apexpages.currentPage().getParameters().get('id')];

            return LineItems;

        }

        set;

    }

 

    public Pagereference save(){

        Pagereference p = new Pagereference('/' + Apexpages.currentPage().getParameters().get('id'))  ;  

 

        try {

            update LineItems; 

        }

        catch(System.DMLException e) {

           ApexPages.addMessages(e);

           system.debug(e);

           return null;

        } 

        p.setRedirect(true);    

        return p;

    }

}

 

 

here is the code for the page


<apex:page controller="OppLineListCon" tabStyle="Asset">
    <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="{!LineItems}" var="i">
                <apex:column headerValue="Product">
                    <apex:OutputText value="{!i.PricebookEntry.Product2.Name}" style="font-size:13px"/>
                    <br></br>
                    <apex:OutputText value="{!i.PricebookEntry.Product2.Description}" style="font-size:11px"/>
                </apex:column>                
                <apex:column headerValue="Ship Qty">
                    <apex:inputField value="{!i.Quantity_Shipped__c}" />
                </apex:column>                
            </apex:pageBlockTable>      
         </apex:pageBlock>
        
    </apex:form>
    </apex:page>
<apex:page controller="OppLineListCon" tabStyle="Asset">    <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="{!LineItems}" var="i">                <apex:column headerValue="Product">                    <apex:OutputText value="{!i.PricebookEntry.Product2.Name}" style="font-size:13px"/>                    <br></br>                    <apex:OutputText value="{!i.PricebookEntry.Product2.Description}" style="font-size:11px"/>                </apex:column>                                <apex:column headerValue="Ship Qty">                    <apex:inputField value="{!i.Quantity_Shipped__c}" />                </apex:column>                            </apex:pageBlockTable>               </apex:pageBlock>            </apex:form>    </apex:page>

 

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> 

 

 

I am referencing a visualforce email template in a URL as below so it can be used in a detail page button.

/email/author/emailauthor.jsp?p2={!RMS_LicenseInfo__c.Contact__c}&p2_lki
d={!Contact.Id}&p3_lkid={!RMS_LicenseInfo__c.Id}&p26=support@vicon.com&t
emplate_id=00X300000011xl7


The attachment created by the template is not generated when the button is clicked.
If the template is selected manually then the attachment will appear.

Is there any way to make the attachment wok when the button is clicked?

Could I use Java or something?

Thanks,
James

HI,

   Iam using a simple code in .net for creating a new account in salesforce.com.While iam calling this  method iam getting below error "CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY Error message: entity type cannot be inserted: Account " .

Any suggestions.

  • April 19, 2010
  • Like
  • 0

Hi,

 

When the Contact creation is part of a Lead conversion, before insert triggers that I have on Contact are not triggered. Is there a workaround?

Thx! 

I am referencing a visualforce email template in a URL as below so it can be used in a detail page button.

/email/author/emailauthor.jsp?p2={!RMS_LicenseInfo__c.Contact__c}&p2_lki
d={!Contact.Id}&p3_lkid={!RMS_LicenseInfo__c.Id}&p26=support@vicon.com&t
emplate_id=00X300000011xl7


The attachment created by the template is not generated when the button is clicked.
If the template is selected manually then the attachment will appear.

Is there any way to make the attachment wok when the button is clicked?

Could I use Java or something?

Thanks,
James
I would like to add a custom field from the Products object to the Opportunity Product object.  For example, for each product we specify a custom field call Product Family.  I would like to include that field in the product records listed in an Opportunity such that when I add/update an Opportunity Product item the correct Product Family value is displayed for the selected Product. 
 
So far, I've added a Product Family field to the Opportunity Product and I've setup a workflow rule to update the field on new/update of records.  To fill-in the value, I've tried to use ISPICK() and CASE() but I've reached a dead end.  Any help would be *much appreciated*.
 
Jeff
Anyone know , how to set up in office and out of office in the calenda ?