New to apex coding and I've been searching on the web all day for what I need to get this task completed. I'm working on a purchasing application. We can probably buy this, but buying it is not an option.
So what I have done so far. Created a Purchase Request object, for the initial request. It has Purchase Request Lines as a related list.
I also have a Purchase Quote related to the Purchase Request and the Purchase Quote has a related line item list.
I want to be able to use a button to create a new Purchase Quote record and pull the Purchase Request Line information and create Purchase Quote line items. It would also need to pull the Purchase Request id and add it to the lookup field in the Purchase Quote.
Here's what I've done so far:
<apex:page standardController="Purchase_Request__c" extensions="NewPurchaseQuoteEntry" >
<apex:form >
<apex:pageBlock title="New Purchase Quote" >
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}" rerender="error" />
</apex:pageBlockButtons>
<apex:pageBlocktable value="{!newPurchaseQuote}" var="a" id="table">
<apex:column headerValue="Purchase Request Number">
<apex:inputField value="{!a.Purchase_Request_Number__c}"/>
</apex:column>
<apex:column headerValue="Contact">
<apex:inputField value="{!a.Contact__c}"/>
</apex:column>
<apex:column headerValue="Additional Information">
<apex:inputField value="{!a.Additional_Information__c}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Extension:
public class NewPurchaseQuoteEntry {
public final Purchase_Request__c purchaseRequest;
public Purchasing_Quote__c newPurchaseQuote { get; set; }
public List<Purchase_Quote_Line__c> newPurchaseQuoteLine = new List<Purchase_Quote_Line__c>();
public NewPurchaseQuoteEntry (ApexPages.Standardcontroller myController){
this.purchaseRequest = (Purchase_Request__c)myController.getrecord();
newPurchaseQuote = new Purchasing_Quote__c();
}
public List<Purchase_Quote_Line__c> getQuoteList (){
List<Purchase_Quote_Line__c> tempList = new List<Purchase_Quote_Line__c>();
for(Purchase_Request_Line__c tempRequest: [SELECT Product__c, Request_Qty__c, Hardware_Level__c,
Software_Level__c FROM Purchase_Request_Line__c
WHERE Purchase_Request_Line__c.Purchase_Request__c = :purchaseRequest.id]){
Purchase_Quote_Line__c newQuoteLine = new Purchase_Quote_Line__c();
newQuoteLine.Product__c = tempRequest.Product__c;
newQuoteLine.Qty_Available__c = tempRequest.Request_Qty__c;
newQuoteLine.Hardware_Level__c = tempRequest.Hardware_Level__c;
newQuoteLine.Software_Level__c = tempRequest.Software_Level__c;
newQuoteLine.Purchase_Quote_Number__c = newPurchaseQuote.id;
tempList.add(newQuoteLine);
}
return tempList;
}
public void newPurchaseQuoteRecord (){
newPurchaseQuoteLine = getQuoteList();
newPurchaseQuote.Purchase_Request_Number__c = purchaseRequest.id;
}
public PageReference save(){
newPurchaseQuote.Purchase_Request_Number__c = purchaseRequest.id;
insert newPurchaseQuote;
insert newPurchaseQuoteLine;
PageReference pageRef = new PageReference('/' + newPurchaseQuote.id);
pageRef.setRedirect(true);
return pageRef;
}
}
I'm unable to pull the Purchase Request id over onto the visualforce page. I would also like to add the Purchase Quote Line related list onto the visualforce page and add in certain information there before saving it.
<apex:page ...
element look like? All attributes and values for this are needed to make a fair assessment. Also, what kind of button are you using? What does the URL look like when the page loads? What formula/code are you using in the button? The devil is in the details.