0

This is the class:

public class overrideButtonExtension 
{ 
    //public string callfunc{get;set;}   
    //public Task t {get; set;}
    //Public Account acc{get;set;}
     PageReference pageRef;
    public Opportunity opp{get;set;}
    public Id opid {get; set;}

    public overrideButtonExtension(ApexPages.StandardController controller)
    {

        //acc = NEW Account(); 
        PageReference pageRef;
        opp = NEW Opportunity(); 
        opid = ApexPages.currentPage().getParameters().get('what_Id');

        System.debug('/////////////'+ApexPages.currentPage().getParameters());
        opp =  [SELECT Name, AccountId, Account.Name FROM Opportunity WHERE Id =:opid ];
        //acc = [SELECT Id, Name FROM Account WHERE Id=:opp.AccountId];

        System.debug('/////////////'+opp);

               /*if(opp.Account.Name == 'ACME')
               {                           
                   ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Task cant be generated'));

               }
               else
               {
                   openTask();
               }*/

               //openTask();

     }
       public PageReference openTask()
       {

           /*String sfdcURL = URL.getSalesforceBaseUrl().toExternalForm() ; */
           if(opp.Account.Name == 'ACME')
               {                           
                   ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Task is already Exist for this account'));
                   return null;
               }
               else
               {
                   pageRef = NEW PageReference('https://ap2.salesforce.com/00T/e?what_id='+opid+'&retURL=%2F00628000008ysV6');
                   System.debug('/////////////'+pageref); 
                   return pageRef;
               }   



       }
}

Here in that else part the url is contineously redirecting.I need to redirect the Task standard page after clicking New Task button.

Please help me out

3
  • what do you mean that it is 'contineously redirecting'? Is it not landing on to the redirected URL or is it stuck in URL redirection ?
    – Sf_Noob
    Commented Apr 26, 2016 at 11:34
  • it is stuck in url
    – sivanee
    Commented Apr 26, 2016 at 12:04
  • Try setting pageRef.setRedirect(False);
    – Sf_Noob
    Commented Apr 26, 2016 at 13:40

1 Answer 1

1

Appending:

&nooverride=1

to the URL should give you the standard Salesforce page.

PS

On Adrian's point, hard coding the instance into your code means the code won't work should your org be moved (which happens occasionally to redistribute load) and also won't work in a sandbox. So better to use relative URLs i.e. new PageReference('/00T/e?what_id...').

1
  • Can you mention why it's bad practice to construct a url bound to a specific instance (ap2) and how to fix it?
    – Adrian Larson
    Commented Apr 26, 2016 at 14:30

You must log in to answer this question.

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