Redirect back to original visualforce page

I have created a custom page for an object client. The client object is having relationship with contact object. For this a custom lookup window has been designed with a new button for creating new record of contact. Now after clicking the save button I want it to redirect me on the client page with the value saved as populated in the contact relationship field.

Below is my code:

function openLookup(baseURL, width, modified, searchParam){ var originalbaseURL = baseURL; var originalwidth = width; var originalmodified = modified; var originalsearchParam = searchParam;

var lookupType = baseURL.substr(baseURL.length-3, 3); if (modified == '1') baseURL = baseURL + searchParam;  var isCustomLookup = false;  // Following "001" is the lookup type for Account object so change this as per your standard or custom object if(lookupType == "003"){    var urlArr = baseURL.split("&");   var txtId = '';   if(urlArr.length > 2) {     urlArr = urlArr[1].split('=');     txtId = urlArr[1];   }    // Following is the url of Custom Lookup page. You need to change that accordingly   baseURL = "/apex/test2?txt=" + txtId;    // Following is the id of apex:form control "myForm". You need to change that accordingly   baseURL = baseURL + "&frm=" + escapeUTF("{!$Component.myForm}");   if (modified == '1') {     baseURL = baseURL + "&lksearch=" + searchParam;   }    // Following is the ID of inputField that is the lookup to be customized as custom lookup   if(txtId.indexOf('contact') > -1 ){     isCustomLookup = true;   } }  if(isCustomLookup == true){   openPopup(baseURL, "lookup", 350, 480, "width="+width+",height=480,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no", true); } else {   if (modified == '1') originalbaseURL = originalbaseURL + originalsearchParam;   openPopup(originalbaseURL, "lookup", 350, 480, "width="+originalwidth+",height=480,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no", true); }  

}

public with sharing class MyCustomLookupController3 {

public Id accId;

public string name;

public client__c sap {get;set;}

public contact contact {get;set;} // new account to create

public List results{get;set;} // search results

public string searchString{get;set;} // search keyword

public MyCustomLookupController3() {

contact = new Contact();  //account = new Account();  // get the current search string  searchString = System.currentPageReference().getParameters().get('lksrch');  runSearch();   

}

// performs the keyword search

public PageReference search() {

runSearch();  return null; 

}

// prepare the query and issue the search command

private void runSearch() {

// TODO prepare query string for complex serarches & prevent injections  results = performSearch(searchString);                

}

private List performSearch(string searchString) {

String soql = 'select id, name from contact';  if(searchString != '' && searchString != null)    soql = soql +  ' where name LIKE \'%' + searchString +'%\'';  soql = soql + ' limit 25';  System.debug(soql);  return database.query(soql);   

}

public PageReference savecontact() {

insert contact;  // reset the account  Id redirectId = contact.Id;     PageReference newocp = new PageReference('/apex/test1?accId='+redirectId);/*Redirect to Parent page*/            newocp.setRedirect(true);          return newocp;             

}

// used by the visualforce page to send the link to the right dom element

public string getFormTag() {

return System.currentPageReference().getParameters().get('frm'); 

}

// used by the visualforce page to send the link to the right dom element for the text box

public string getTextBox() {

return System.currentPageReference().getParameters().get('txt'); 

}

public MyCustomLookupController3(ApexPages.StandardController controller) {

contact = new contact();      this.sap = (client__c) controller.getRecord();      if (ApexPages.currentPage().getParameters().get('accId') != NULL) 

{ accId = ApexPages.currentPage().getParameters().get('accId');

        name = ApexPages.currentPage().getParameters().get('name');     }     if ( accId != null ) {      this.sap.contact__c = (Id)accId;      this.sap.name = name; }     /* if (accId != NULL) {          account = [SELECT ID, name from Account where id = : accId];     }*/ }      

}

Name {!a.Name}

  <!-- NEW ACCOUNT TAB -->   <apex:tab label="New Account" name="tab2" id="tabTwo">      <apex:pageBlock id="newAccount" title="New Account" >        <apex:pageBlockButtons >         <apex:commandButton action="{!savecontact}" value="Save"/>       </apex:pageBlockButtons>       <apex:pageMessages />        <apex:pageBlockSection columns="2">         <apex:repeat value="{!$ObjectType.contact.FieldSets.CustomContactLookup}" var="f">           <apex:inputField value="{!contact[f]}"/>         </apex:repeat>       </apex:pageBlockSection>      </apex:pageBlock>    </apex:tab> </apex:tabPanel> 

Replay

Category: visualforce Time: 2016-07-29 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.133 (s). 12 q(s)