0

I have a strange issue in vf page,I have attached my code below.Onclicking remove service particular page block is getting removed and the record also getting removed from database.But onclicking remove service button the lookup functionality in the last page block is not working.I couldnt figure out the issue its seems to be strange.

<apex:sectionHeader Title="product"  />

<div style="float:right; padding-top:25px">
        <apex:commandButton value="Add Service" action="{!Add}" immediate="true" reRender="addservicereRender"/>
 </div>             

    <apex:outputPanel id="addservicereRender" >
    <apex:repeat value="{!prod}" var="p" id="theRepeat">            
    <apex:pageBlock id="block1">

    <div>
        <apex:outputLabel value="productlookup"/>&nbsp;&nbsp;
        <apex:inputField value="{!p.product__c}" onFocus="this.blur()"/>
        <apex:commandButton value="Remove Service" action="{!Remove}" style="float:right" reRender="addservicereRender" immediate="true">
            <apex:param name="PId" value="{!p.Id}" />  
        </apex:commandButton>
    </div> 

    <apex:pageBlockSection id="section1">               

                <apex:inputfield value="{!p.prdouct1}" />


                <apex:inputField value="{!p.prdouct2}"  />


                <apex:inputField value="{!p.prdouct3}"  />

 </apex:pageBlockSection> 


</apex:pageBlock>       
</apex:repeat> 
</apex:outputPanel> 

</apex:form>

public with sharing class example1Controller {


public LIst<example__c> prod {get;set;}
public String OpportunityId{get;set;}

public example1Controller() 
{
    try{
        OpportunityId =ApexPages.currentPage().getParameters().get('id');
        prod = new list<example__c>();
        String Action  =ApexPages.currentPage().getParameters().get('action');


        if(OpportunityId != null && OpportunityId != '') 
        {
            prod =  [SELECT Id,product__c,prdouct1__c,prdouct2__c,prdouct3__c FROM example__c WHERE Opportunity__c =:OpportunityId];

            if(Action == 'add'){
                example__c  e = new example__c();
                e.Opportunity__c = OpportunityId;
                prod.add(e);
            }
        }
    } catch(Exception e) {
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage()));
    } 
}




public void Add()
{
    try{
       example__c  e = new example__c();
       e.Opportunity__c = OpportunityId;
       prod.add(e);
    }catch(Exception e) {
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage()));
    } 
}

//************** RemoveService *****************************//
public void Remove()
{
    try{

        boolean hasRun = false;
        String exampleId = ApexPages.currentPage().getParameters().get('PId');
        System.debug('exampleId:'+exampleId );
        if (exampleId != null && exampleId != '') 
        {
            example__c s;
            for(example__c sl: prod )
            {
                if(sl.Id == exampleId)
                {

                    s = Sl;
                }
            } 
            delete s;
            for(Integer i=0;i<prod.size();i++)
            {
                if(prod[i].Id==exampleId)
                {
                    prod.remove(i);

                }
            }                                     
        }
    }catch(Exception e) {
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage()));
    }
}

}

enter image description here

Onclicking remove service pageblock is removed but the lookup in last pageblock is not working.

enter image description here

8
  • 1
    n.b. you're overloading the page param 'ID' to be both the Oppo Id and the line item to be removed product Id. This is confusing and you might want to use 'PID' for the name of the param in the latter case
    – cropredy
    Jul 16 '14 at 17:03
  • 1
    What error you are getting when you click on lookup? Check the error on web console. Jul 16 '14 at 17:10
  • Not exactly sure what you mean by "the last page block is not working". Can you describe that a bit more detailed? Also, why are you using the onfocus event on your lookup field and why on earth is this calling "this.blur()" ?
    – FrankZ
    Jul 17 '14 at 9:42
  • The error on the console is Uncaught TypeError: Cannot read property 'value' of null VM1109:1 (anonymous function) Jul 17 '14 at 11:44
  • And the contents of VM1109 is openLookup('/_ui/common/data/LookupPage?lkfm=j_id0%3Anewform&lknm=j_id0%3Anewform%3AtheRepeat%3A2%3Ablock1%3Aj_id44&lktp=' + getElementByIdCS('j_id0:newform:theRepeat:2:block1:j_id44_lktp').value,670,'1','&lksrch=' + escapeUTF(getElementByIdCS('j_id0:newform:theRepeat:2:block1:j_id44').value.substring(0, 80))) Jul 17 '14 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.