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
Amit Singh.ax1042Amit Singh.ax1042 

How to display alert box ,and how to check condition after pressing custom button???

I have Following Objects


3)Estimate Line Item (ELI)
Fields- Job (Master),Vendor(Look up),Amount

4)Purchase Order
Fields- Job (Master),Vendor (Look up),PO# (Auto number) etc.

5)Purchase Order Line Item
Fields- Purchase order (Master),Estimate Line Item (Look up)

(Here Master denotes MD relationship,Lookup- Lookup relationship)

i have taken a button named as Create PO(to create Purchase order)on Estimate Line Item detail Page

and override it with vf pafe, its Job will be pulled from ELI and vendor also will be pulled from ELI,and other fields value of Purchase order will be given manually.... after save a child Record (POLI) of PO also will be created with Estimate Line Item,and Amount field...

you will get it from code,

Now suppose i am going to create a PO from any Other Estimate Line Items Detail Page... and this time we have to check whether PO for this vendor (Estimate Line Items Vendor) is already there in any PO or not??
then we have to open a popup..asking .... PO for Estimate Line Items Vendor is already created... do you want to add this item into existing Vendors POLI or want to create New PO?...
if yes then add ELI into POLi of that vendors PO.
and if no again Open a page to create New PO.

Create PO--(Button is override with vf page)...

<apex:page standardController="Estimate_Line_Items__c" tabStyle="Job__c" extensions="CreatePOFromEstimateLIExtension">


 <apex:form >
  <apex:sectionHeader title="Purchase Order Details"/>
     <apex:pageBlock >
         <apex:pagemessages />
             <apex:pageBlockButtons >
                 <apex:commandButton action="{!saveme}" value="Save"></apex:commandButton>
                 <apex:commandButton action="{!cancel}" value="Cancel" immediate="true"></apex:commandButton>
             <apex:pageBlockSection title="Information" columns="2" collapsible="true">            
                  <apex:pageBlockSectionItem >
                  <apex:outputLabel value="Job"/>
                  <apex:outputField value="{!PO.Job__c}"/>
              <apex:pageBlockSectionItem >
                  <apex:outputLabel value="Vendor"/>
                  <apex:outputField value="{!PO.Vendor__c}"/>
             <apex:pageBlockSectionItem >
                  <apex:outputLabel value="Status"/>
                  <apex:inputField value="{!PO.Status__c}" required="true"/>
           <apex:inputField value="{!PO.Issue_Date__c}"/>
            <apex:inputField value="{!PO.Due_Date__c}"/>
            <apex:pageBlockSectionItem >
                  <apex:outputLabel value="Approved By"/>
                  <apex:inputField value="{!PO.Approved_By_Staff__c}"/>



Apex Class-:

public class CreatePOFromEstimateLIExtension 
    private final Estimate_Line_Items__c ELI;
    public String ELIid{get;set;}
   Public Purchase_Order__c PO;
   public String strId{get;set;}
   public PO_Line_Item__c POLI;
   String jobid,jobId1;
   public List<PO_Line_Item__c> lstPOLI=new List<PO_Line_Item__c>();

    public CreatePOFromEstimateLIExtension(ApexPages.StandardController controller) 
     this.ELI = (Estimate_Line_Items__c)controller.getRecord();
     String ELIid=ApexPages.CurrentPage().getParameters().get('id');
     Estimate_Line_Items__c obj1 = [Select id,Job__c from Estimate_Line_Items__c where id =: ELIid Limit 1];
    //PO.Job__c = ELI.Job__c ;
   Public Purchase_Order__c getPO()
        PO = new Purchase_Order__c();
        String ELIid=ApexPages.CurrentPage().getParameters().get('id');
        Estimate_Line_Items__c obj = [Select id,Job__c,Vendor__c from Estimate_Line_Items__c where id =: ELIid Limit 1];
        PO.Job__c = obj.Job__c;
        PO.Vendor__c = obj.Vendor__c;
        return PO;
    Public PageReference Saveme()
    String strPOid;
     insert PO;
     jobid = PO.Job__r.Id;
     strPOid = PO.Id;
     catch(System.DMLException e)
     return null;
      String ELIid=ApexPages.CurrentPage().getParameters().get('id');
      Estimate_Line_Items__c obj = [Select id,Job__c,Total_Amount__c,Vendor__c from Estimate_Line_Items__c where id =: ELIid];
         POLI = new PO_Line_Item__c();
         POLI.Purchase_Order__c = strPOid;
         POLI.Amount__c = obj.Total_Amount__c;
         POLI.Estimate_Line_Item__c = obj.Id;
         insert lstPOLI;
       PageReference pageRef =  new Pagereference('/apex/JobListView?id='+jobId1+'&intFocus=6');
       return pageRef;
    return null;