I'm trying to get a page to redirect to a custom object that is being created in the below class but it's not doing it at the moment.

Can I call this class from a trigger and get the page to redirect?

public class CAWarrantyToMaintenance {

public static PageReference createMaint(id oldId){
    Maintenance_Contract__c oldmc =[select id, End_Date_Editable__c from Maintenance_Contract__c where id =:oldId];
    Maintenance_Contract__c newmc = new Maintenance_Contract__c();
    newmc.Contract_Type__c = 'MCD';
    newmc.New_Contract__c = oldmc.id;
    newmc.Start_Date__c = oldmc.End_Date_Editable__c;
    insert newmc; 

    PageReference maintPage = new PageReference ('https://cs80.salesforce.com/' + newmc.id);
    return maintPage;

1 Answer 1


No, you can't redirect from a trigger. You'd have to create a Visualforce page to call the code and then perform your redirect. Also, you should always use StandardController to redirect:

return new ApexPages.StandardController(newmc).view();

You must log in to answer this question.

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