public without sharing class StandardFieldDefaultsController {

    public String SObjId{get;set;}
    public String SObjName{get;set;}
    public String linkId{get;set;}
    public String Pagefrom{get;set;}
    public String Pageto{get;set;}
    
    public StandardFieldDefaultsController() {

    }

    public StandardFieldDefaultsController(ApexPages.StandardController controller) {
        String sobject_type = controller.getRecord().getSObjectType().getDescribe().getName();
        if (sobject_type == 'LastbuyProduct__c') {
            Apexpages.currentPage().getParameters().put('Pageto', 'LastbuyProduct');
        }
    }

    public PageReference init(){

        this.SObjId =Apexpages.currentPage().getParameters().get('SObjId');
        this.SObjName = Apexpages.currentPage().getParameters().get('SObjName');
        this.linkId = Apexpages.currentPage().getParameters().get('linkId');
        this.Pagefrom =Apexpages.currentPage().getParameters().get('Pagefrom');
        this.Pageto =Apexpages.currentPage().getParameters().get('Pageto');

        //'retURL=%2F' + this.SObjId + 
        String url = '';
        switch on Pageto {
            when 'LastbuyProduct'{
                url = '/' + System.Label.LastBuyUrl + '/e?' + 'Name=*';
                if ('Product'.equals(this.Pagefrom)) {
                    url += '&CF' + this.linkId + '=' + this.SObjName + '&CF' + this.linkId + '_lkid=' + this.SObjId;
                }
            }
        }
        url += '&nooverride=1';   //跳转到标准页面用
        PageReference pg = new Pagereference(System.Url.getSalesforceBaseUrl().toExternalForm() + url);
        pg.setRedirect(true);
        return pg;
    }
}