You need to sign in to do that
Don't have an account?
jeevitha annabathula 5
Hi,I would like to create a visual force page in which i would like to prepopulate the list price value based on selecting of lookup field aand want to pull value from that lookup and at that same time I want to create a button to add rows dynamically. I
I have written two separate visual force pages to prepopulate and add rows dynamically. I would like to know how to merge these two codes. Can some help me with this coding please.
PREPOPULATE <apex:page standardController="IT_Contract_Line__c" extensions="Autocall,AddNewRows" showHeader="true" sidebar="true"> <apex:form > <apex:pageBlock > <apex:pageBlockSection > <apex:pageBlockTable value="{!cwrap}" var="cn"> <apex:column headerValue="Product"> <apex:inputField value="{!Testing.Product__c}" > <apex:actionSupport event="onchange" action="{!autoCal}" reRender="accEmail,accPhone"> </apex:actionSupport> </apex:inputField> </apex:column> <apex:column headerValue="UOM"> <apex:inputField value="{!Testing.UOM_Unit_Of_Measure1__c}" id="accEmail" html-disabled="true"/> </apex:column> <apex:column headerValue="Unit Price"> <apex:inputField value="{!Testing.Unit_Price__c}" id="accPhone"/> </apex:column> <apex:column headerValue="QUantity"> <apex:inputField value="{!Testing.Quantity__c}"/> </apex:column> <apex:column headerValue="Discount"> <apex:inputField value="{!Testing.Unit_Discount__c}"/> </apex:column> <apex:column headerValue="Line Tax"> <apex:inputField value="{!Testing.Line_Tax__c}"/> </apex:column> <apex:column headerValue="IT-Contracts"> <apex:outputField value="{!Testing.IT_Contracts__c }" html-disabled="true"/> </apex:column> </apex:pageBlockTable> </apex:pageBlockSection> <apex:commandButton value="AddRow" action="{!addRows}" reRender="lab"/> <apex:commandButton value="Save" action="{!save}" /> </apex:pageBlock> </apex:form> </apex:page> PREPOPULATE public class Autocall { public IT_Contract_Line__c Testing {get;set;} public boolean flag{get;set;} private ApexPages.StandardController stdController; public Autocall(ApexPages.StandardController controller) { Testing=(IT_Contract_Line__c)controller.getRecord(); } //function is called from actionsupport event public PageReference autoCal() { Id accId = Testing.Name; // collecting account id from visualforce page List<Product2> accLst = [select id,UOM__c,List_Price__c from Product2 where id=:Testing.Product__c]; Testing.UOM_Unit_Of_Measure1__c = accLst[0].UOM__c; Testing.Unit_Price__c = accLst[0].List_Price__c; return null; } public PageReference save() { upsert Testing; flag=true; PageReference nextPage = new ApexPages.StandardController(Testing).view(); nextPage.setRedirect(true); return nextPage; } } ADD ROWS DYNAMICALLY <apex:page standardController="IT_Contract_Line__c" recordSetVar="IT_Contract_Line__c" extensions="ITContractLines"> <apex:form > <apex:pageBlock > <apex:pageBlockSection title="Add Vendor QuoteLines" columns="1"> <apex:pageBlockTable value="{!listMeetingAttendee}" var="meetAtt" id="customTable"> <apex:column headerValue="Product"> <apex:inputField value="{!meetAtt.Product__c}" required="true"/> </apex:column> <apex:column headerValue="Quantity"> <apex:inputField value="{!meetAtt.Quantity__c}"/> </apex:column> <apex:column headerValue="Unit Price"> <apex:inputField value="{!meetAtt.Unit_Price__c }"/> </apex:column> <apex:column headerValue="Unit Discount"> <apex:inputField value="{!meetAtt.Unit_Discount__c}"/> </apex:column> <apex:column headerValue="Line Tax"> <apex:inputField value="{!meetAtt.Line_Tax__c}"/> </apex:column> <apex:column headerValue="IT-Contract"> <apex:outputField value="{!meetAtt.IT_Contracts__c }" html-disabled="true"/> </apex:column> <apex:column id="two"> <apex:commandButton value="Remove LineItem" action="{!removerow}"/> </apex:column> </apex:pageBlockTable> </apex:pageBlockSection> <apex:pageBlockButtons > <apex:commandButton value="Add IT-ContractLines" action="{!addLineItem}" rerender="customTable" immediate="true"/> <apex:commandButton value="Save IT-ContractLines" action="{!saveLineItem}"/> <apex:commandButton value="Cancel" action="{!cancel}" immediate="true"/> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page> ADD ROWS DYNAMICALLY public class ITContractLines { public List<IT_Contract_Line__c> listMeetingAttendee {get; set;} IT_Contract_Line__c meetingAttendee = new IT_Contract_Line__c(); IT_Contracts__c meetingAttendees = new IT_Contracts__c(); public String KARId = apexpages.currentpage().getParameters().get('Id'); public ApexPages.StandardSetController stdCntrlr {get; set;} public ITContractLines(ApexPages.StandardSetController controller) { stdCntrlr = controller; listMeetingAttendee = new List<IT_Contract_Line__c>(); system.debug(KARId); if(KARId<>null){ for(IT_Contracts__c KAR: [SELECT Id FROM IT_Contracts__c WHERE Id =:KARId ]){ meetingAttendee.IT_Contracts__c = KARId ; listMeetingAttendee.add(meetingAttendee ); } } else{ listMeetingAttendee.add(meetingAttendee ); } } public void addLineItem(){ IT_Contract_Line__c meetAtt = new IT_Contract_Line__c(); meetAtt.IT_Contracts__c = KARId ; listMeetingAttendee.add(meetAtt); } public PageReference saveLineItem() { system.debug('listMeetingAttendee'+listMeetingAttendee); for(Integer i=0; i<listMeetingAttendee.size(); i++) { upsert listMeetingAttendee; } PageReference nextPage = new ApexPages.StandardController(meetingAttendees).view(); nextPage.setRedirect(true); return nextPage; } public void removerow() { Integer i = listMeetingAttendee.size(); listMeetingAttendee.remove(i-1); } public PageReference cancel(){ Id ide = ApexPages.Currentpage().getParameters().get('id'); return new PageReference('/' + KARId ); } }