+ Start a Discussion
SF7SF7 

On click fuction

Hi 

i am trying to open an another vf page in the same window and after doing my wrk in that page i want to return back to the same page but i am unable to do it right now my page is opening in a new window and after saving it is continuing in the new page.

Can any one help me with this.

<apex:page standardController="Opportunity" extensions="ContactRolesShowController">
  <style type="text/css">
     .style1{ font-size: 12px;
            font-family: arial;
            color: black;
            font-weight:normal; }   
     .style2{ font-size: 12px;
            font-family: arial;
            color: Yellow;
            font-weight:normal; }
 </style>

<script language="javascript">
        function confirmDelete(IdVal){
            if(confirm('Are you sure you want to delete?'))
                callRemoveFn(IdVal);
            else
                return false;
        }
    </script>

  <apex:form id="contactRoleForm">
  <p align="center" >
     <apex:commandButton value="Add/Edit Contact Roles" onclick="window.open('/apex/ContactRolePage?id={!opty.Id}')"/>
  </p>

       <apex:outputPanel id="msg"> 
        <apex:pageMessages /> 
     </apex:outputPanel>  
        <apex:pageBlock mode="maindetail">
           <apex:pageBlockTable id="table" value="{!OpportunityContactRoleRecords}" width="1000px" var="ocr" columns="7" cellpadding="5px" rendered="{!isNoOcr == False}" rows="{!rowsToDisplay}"> 
               <apex:column id="removeColumn" width="50px">     
                   <apex:facet name="header">&nbsp;&nbsp;&nbsp;&nbsp;Action&nbsp;&nbsp;&nbsp;&nbsp;</apex:facet>  
      
                      <apex:commandlink value="Edit" onclick="window.open('/apex/ContactRolePage?Id={!opty.Id}')" style="color:blue"/>  
                       &nbsp;|&nbsp; 
                      <apex:commandlink value="Del" onclick="confirmDelete('{!ocr.Id}');" style="Color:Blue" rerender="msg">
                      </apex:commandlink>
              </apex:column>
             
              
              <apex:column id="contactColumn">
                  <apex:facet name="header">Contact</apex:facet>          
                   <apex:outputLink target="_top" value="/{!ocr.ContactId}">{!ocr.Contact.Name}
                   </apex:outputLink>
              </apex:column> 
                            
              <apex:column id="clientColumn">
                  <apex:facet name="header">Client</apex:facet>          
                   <apex:outputLink target="_top" value="/{!opty.Local_Client__c}">{!opty.Local_Client__r.Name}
                   </apex:outputLink>                   
              </apex:column> 
              
              <apex:column id="emailColumn">
                  <apex:facet name="header">Email</apex:facet>          
                  <apex:outputText value="{!ocr.Contact.Email}"/>
              </apex:column> 
              
              <apex:column id="phoneColumn">
                  <apex:facet name="header">Phone</apex:facet>          
                  <apex:outputText value="{!ocr.Contact.Phone}"/>
              </apex:column>
                           
              <apex:column id="roleColumn">
                  <apex:facet name="header">Role</apex:facet>          
                  <apex:outputText value="{!ocr.Role}"/>
              </apex:column>
                            
              <apex:column id="isPrimaryColumn">
                  <apex:facet name="header">Primary</apex:facet>          
                  <apex:inputCheckbox value="{!ocr.isPrimary}" disabled="true"/>
              </apex:column>              
          </apex:pageBlockTable>
           
            <apex:actionFunction action="{!remove}" name="callRemoveFn" rerender="contactRoleForm,msg">
              <apex:param value="" name="ocrId"/>
            </apex:actionFunction>
           
          <br/>
          <apex:outputPanel id="noOcr" rendered="{!isNoOcr}">
            <apex:outputText value="No ContactRoles" />  
          </apex:outputPanel> 
          <apex:outputPanel style="margin:0px;padding:10px;padding-top:5px;" rendered="{!isShowMore}"> 
               <apex:commandlink Value="xxx"  target="_top"  oncomplete="window.top.location = '/apex/ContactRoleRecordsListPage?optyId={!opty.Id}'"/>
          </apex:outputPanel>  
     </apex:pageBlock>   
  </apex:form>
</apex:page>
public with sharing class ContactRolesShowController {
    
    public Opportunity opty{get;set;}
    public String ocrId{get;set;}
    public Boolean isNoOcr{get;set;}
    public Integer rowsToDisplay{get;set;}
    public Boolean isShowMore{get;set;}
    public Integer totalOCR{get;set;}
    public boolean noshowRemove{get;set;}
    public Boolean hasAccess{get;set;}
    private ID oppId;
       
    public ContactRolesShowController(ApexPages.StandardController stdctrl) {
    
        Opportunity optyRecord;
        Id optyId = ApexPages.currentPage().getParameters().get('optyId');    
        oppId=optyId;
        System.debug('---OpportunityID------'+optyId);
        if(optyId !=null)
            optyRecord = new Opportunity(Id = optyId);
        else
            optyRecord = (Opportunity)stdctrl.getRecord();
        
        opty = [select Name, AccountId,Local_Client__c,Local_Client__r.Id,Local_Client__r.Name,OwnerId from Opportunity where Id =: optyRecord .Id];
        isNoOcr = false;
        getOpportunityContactRoleRecords();
        System.debug('---constructor------');
        List<Profile> noEditAccessProfiles = [select Id,Name from Profile where Name ='LEGAL_USER' or Name = 'FINANCE_USER'];
        
        for(Profile p : noEditAccessProfiles) {
            if(p.Id == UserInfo.getProfileId()) {
                noshowRemove = true;
                break;
            }   
        }
       
        if(getCheckSystemAdmin()) 
            noshowRemove = false;
        else if(opty.OwnerId == UserInfo.getUserId())
            noshowRemove = false;   
        else {
            List<AccountTeamMember> teamMemberList = [Select a.UserId, a.TeamMemberRole, a.SystemModstamp, a.LastModifiedDate, 
                a.LastModifiedById, a.IsDeleted, a.Id, a.CreatedDate, a.CreatedById, a.AccountId, 
                a.AccountAccessLevel From AccountTeamMember a where a.accountId =: opty.Local_Client__c];
            
            if (teamMemberList != null && teamMemberList.size() > 0 ) {
                Map<String, String> teamMembersMap = new Map<String, String>();
                for (Integer i=0; i< teamMemberList.size(); i++) {
                    teamMembersMap.put(teamMemberList[i].userId, teamMemberList[i].userId);
                }
                String myUserId = teamMembersMap.get(UserInfo.getUserId());
                if (myUserId != null ) {
                    noshowRemove = false;
                }
                else
                    noshowRemove = true;
            }
        }       
    }
    
/*    public PageReference ContactRolePage(){
        PageReference p;
        oppId = ApexPages.currentPage().getParameters().get('Id');    
        p = new PageReference('/apex/ContactRolePage?id='+oppId);
        return p;
    }
*/    
    public Boolean getCheckSystemAdmin()
    {
     List<Profile> Prof;
      Prof = [Select id from Profile where Name = 'System Administrator' or Name = 'L2_LOB/REGION_SYS_ADMIN'];
      
        for(Profile p :Prof)
        {
            if (UserInfo.getProfileId()== p.Id)
                return true;
        }
        
        return false;
    }
    public List<OpportunityContactRole> getOpportunityContactRoleRecords() {
        
        rowsToDisplay = 0;
        totalOCR = 0;
        List<OpportunityContactRole> ocrList = new List<OpportunityContactRole>();
        ocrList = [select Id,ContactId,role,OpportunityId,IsPrimary,Contact.Email,Contact.Phone,Contact.Name from OpportunityContactRole where OpportunityId =: opty.Id];    
        if(ocrList.size() == 0)
            isNoOcr= true;  
        
        if(ocrList.size() > 5) { 
            rowsToDisplay =5;
            isShowMore = true;
        }   
        else {
            rowsToDisplay = ocrList.size();
            isShowMore = false;
        }
        totalOCR = ocrList.size();
        return ocrList;        
    }
    
    
    
    public void remove()
    {
        ocrId = ApexPages.currentPage().getParameters().get('ocrId');    
        System.debug('-------ocrId-------'+ocrId);
        OpportunityContactRole delOcrRecord = new OpportunityContactRole(Id = ocrId);
        try {
            delete delOcrRecord;
        }
        catch (DMLException de)
            {
              if(de.getMessage().contains('INSUFFICIENT_ACCESS_OR_READONLY') || de.getMessage().contains('INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY'))
              {
                ApexPages.addMessage(new ApexPages.Message (ApexPages.Severity.Info, 
                                   'Insufficient privileges - You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary. ' ));
              }
              else {
                ApexPages.addMessage(new ApexPages.Message (ApexPages.Severity.ERROR, 
                                   'DML Error: '+ de.getMessage ()));
              }
            }      
        getOpportunityContactRoleRecords();
    }
    
    public pageReference goToList() {
        PageReference pageRef = new PageReference('/apex/ContactRoleRecordsListPage?optyId='+opty.Id);  
        pageRef.setRedirect(true);
        return  pageRef; 
    
    }
    
    public PageReference cancel() {
        PageReference pageRef = new PageReference('/'+opty.Id);
        pageRef.setRedirect(true);
        return  pageRef;
    }   
    
}

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Ispita_NavatarIspita_Navatar

Hi Akhil,

           If you want to open the window in either the new window or parent window, you can use target="_blank" or target="_parent"  respectively in the window.open() method call. If you are getting any error in  opening a window, you can check the javascript error console, may be the code is encountering some javascript error.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

All Answers

stcforcestcforce

doesn't window.open() always open a new window?

Ispita_NavatarIspita_Navatar

Hi Akhil,

           If you want to open the window in either the new window or parent window, you can use target="_blank" or target="_parent"  respectively in the window.open() method call. If you are getting any error in  opening a window, you can check the javascript error console, may be the code is encountering some javascript error.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

This was selected as the best answer
SF7SF7

HI 

 

i got it using window.open(url,'parent',true);

 

 

Thanks