0

I have this below requirement where i am displaying opportunityteammember of its related Opportunity.

In the vf page i am dynamically adding opportunityteammember records to its opportunity.

I need to also remove selected opportunityteammember record from vf page row and database.From the vf page row i am able to remove, but i am unable to remove it from database.

Below is the wrapper class and delete method -

public List<InnerOpps> wrappers{get;set;}
public void deleteTeamMember () { 

        List<OpportunityTeamMember> OppTeamToDel = new List<OpportunityTeamMember>();
        for(Integer i=0;i<Wrappers.size();i++){
            OpportunityTeamMember oppToDel = Wrappers[i].oppTeam;
            system.debug('@@@@' + oppToDel);
            if(Wrappers[i].wrapperId==wrapperId){
               wrappers.remove(i);
               OppTeamToDel.add(wrappers[i].oppTeam);
            }
        }
        delete OppTeamToDel;
    }

wrapper class -

 public class InnerOpps{    

    public OpportunityTeamMember testTeam{get;set;}
    public String wrapperId{get;set;}

    public InnerOpps(OpportunityTeamMember  oppTeamMem){
        oppTeam=oppTeamMem;
        Blob b = Crypto.GenerateAESKey(128);
        String h = EncodingUtil.ConvertTohex(b);
        wrapperId = h.SubString(0,8)+ '-' + h.SubString(8,12) + '-' + h.SubString(12,16) + '-' + h.SubString(16,20) + '-' + h.substring(20);

    }


    } 

vf page -

<apex:page controller="OppoTeam" sidebar="false" showHeader="false">
    <apex:form >  
     <apex:pageBlock > 
     <apex:pageBlock id="pg">

         <apex:pageblocktable value="{!wrappers}" var="var" columns="4" > 

         <apex:column headerValue="Action">


                    <apex:actionRegion >
                                        <apex:commandButton value="Del" action="{!deleteTeamMember}" reRender="pg">
                        <apex:param name="wrapperId" value="{!var.wrapperId}" assignTo="{!wrapperId}"/>
                    </apex:commandButton>
                           </apex:actionRegion>
            </apex:column>   


            <apex:column headerValue="Team Member">
                <apex:outputPanel rendered="{!var.testTeam.Id != null}">
                    {!var.testTeam.Name}
                </apex:outputPanel>
            </apex:column>

         </apex:pageBlockTable>
         <apex:commandButton action="{!addTeamMember}" value="Add" reRender="pg"/> 
         </apex:pageBlock>                                 
      </apex:pageBlock>
    </apex:form>
</apex:page>

1 Answer 1

0

I believe the problem lies here

if(Wrappers[i].wrapperId==wrapperId){
    wrappers.remove(i);  
    OppTeamToDel.add(wrappers[i].oppTeam);
}

and if we narrow it down further, this line of code, wrappers.remove(i);, suggests that you are removing the oppTeamMembers from the wrapper before they are being part of the list. If you debug that particular line, you might get the index out of bound error, since wrapper[i] is no longer valid if it had only one item.

Try something like this

if(Wrappers[i].wrapperId==wrapperId){
    OppTeamToDel.add(wrappers[i].oppTeam);
    wrappers.remove(i);         
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .