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
AAlex11AAlex11 

Custom button doesn't redirect on VF page correctly

Hi Guys!I wrote this custom controller to create a custom button new for my custom object Family__c that has two lookup relations one on account and an other on opportunity.
I need to rebuild in my controller this url
/a04/e?CF00N4E000000MBgM={!Opportunity.Name}&CF00N4E000000MBgM_lkid={!Opportunity.Id}
&CF00N4E000000MBfn={!Account.Name}&CF00N4E000000MBfn_lkid={!Account.Id}&retURL=%2F{!Opportunity.Id}  in order to have the new Family__c record page with lookup fields automatically filled.
This is my controller
public without sharing class Guest_Stud_BottonCtrl {</span>
  public Family__c hfs { get; set; } 
  public Opportunity opp{ get; set; }
  public String opp1{ get; set; }
  public String retURL {get; set;}
  public String saveNewURL {get; set;}

  public String opps {get; set;}
  public String cancelURL {get; set;}
  public String ent {get; set;}
  public String confirmationToken {get; set;}



  public Guest_Stud_BottonCtrl (ApexPages.StandardSetController controller) {
   hfs = (Family__c)controller.getRecord();
   
  // Id Opportunity_Id = [SELECT Id FROM opportunity WHERE AccountId=:Account_Id  LIMIT 1].id;
  Id Opportunity_Id=ApexPages.CurrentPage().getParameters().get('opp.id');
   Id Account_Id = ApexPages.CurrentPage().getParameters().get('acc.id');
   retURL = ApexPages.currentPage().getParameters().get('retURL');

       opps=[SELECT Id FROM opportunity WHERE AccountId=:Account_Id  LIMIT 1].id;
  
       
  
        cancelURL = ApexPages.currentPage().getParameters().get('cancelURL');

        ent = ApexPages.currentPage().getParameters().get('ent');
 
        confirmationToken = ApexPages.currentPage().getParameters().get('_CONFIRMATIONTOKEN');

        saveNewURL = ApexPages.currentPage().getParameters().get('save_new_url');
     }

    
    
public PageReference urlredirect() {

  PageReference newPage;

  PageReference returnURL;

            returnURL = new PageReference('/a04/e');

            returnURL.getParameters().put('retURL', retURL);

            returnURL.getParameters().put('opp.id', opps);

            returnURL.getParameters().put('cancelURL', cancelURL);

            returnURL.getParameters().put('ent', ent);

            returnURL.getParameters().put('_CONFIRMATIONTOKEN', confirmationToken);

            returnURL.getParameters().put('save_new_url', saveNewURL);

            returnURL.getParameters().put('nooverride', '1');

            returnURL.setRedirect(true);

            return returnURL;
             }

  }

the problem is that when I launch the button the page redirect on standard  page new family__c record and doesn't fill the lookup field automatically as I want.
Where am I wrong?
Anyone could help me please?
Thanks