首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SalesForce:从经典到照明

问SalesForce:从经典到照明
EN

Stack Overflow用户
提问于 2021-01-30 16:06:02
回答 1查看 28关注 0票数 0

如果我的问题这么愚蠢,很抱歉,但我的编程技能真的很有限,我急着要一个PoC。

我有一个顶尖类,下面是为Classic开发的。我想让它与照明一起工作,我不确定我唯一需要替换的是url,我已经为我的PoC创建了一个开发人员帐户,每次我启动这个类时,我都会被重定向到Classic。

代码语言:javascript
复制
public class LookupByUrlParamController {

    String accountName;
    String accountNumber;
    String phone;
    String website;
    String email;
    String socialhandle;
    
    public LookupByUrlParamController () { }

    public String redirectToAccount() {
        
        Account account;
        
        Map<String,String> params = ApexPages.currentPage().getParameters();
        if(params.size() > 0) {
            accountName = params.get('account_name');
            accountNumber = params.get('account_number');
            phone = params.get('phone');   
            website =  params.get('website');   
            email =  params.get('email');
            socialhandle =  params.get('SocialHandle');
        }
        
        try {
            if(accountName != null) {
                account = [select ID from Account where name = :accountName limit 1];   
            } 
        } catch (System.queryException e) {//no entry found for lookup item, display empty account page
            return 'https://na7.salesforce.com/001/e';
        }    
          
        try {
            if(accountNumber != null) {
                account = [select ID from Account where AccountNumber = :accountNumber limit 1];   
            }
         } catch (System.queryException e) {//no entry found for lookup item, display empty account page
            return 'https://na7.salesforce.com/001/e';
         }   
            
        try {
             if(phone != null) {
                
                String npa;
                String nnx;
                String extension;
        
                //  Added logic for NA phone numbers

                if (phone.length() == 10) {
                    npa = phone.substring(0,3);
                    nnx = phone.substring(3,6);
                    extension = phone.substring(6,10);
                    phone = '(' + npa + ') ' + nnx + '-' + extension;
                }

                account = [select ID from Account where phone = :phone limit 1]; 
             }
        } catch (System.queryException e) {//no entry found for lookup item, display empty account page
            return 'https://na7.salesforce.com/001/e';
        }        
            
        try {     
             if(website != null) {
                account = [select ID from Account where website = :website limit 1]; 
             }
         } catch (System.queryException e) {//no entry found for lookup item, display empty account page
            return 'https://na7.salesforce.com/001/e';
         }       
            
         try {
              if(email != null) {
                account = [select ID from Account where email__c = :email limit 1]; 
              }
         } catch (System.queryException e) {//no entry found for lookup item, display empty account page
             return 'https://na7.salesforce.com/001/e';
         }   
             
         try {
              if(socialhandle != null) {
                account = [select ID from Account where SocialHandle__c = :socialhandle limit 1]; 
              }
         } catch (System.queryException e) {//no entry found for twitter handle lookup item, display empty account page
             return 'https://na7.salesforce.com/001/e';
         }      
       
        
        String accountUrl;
        if(account != null) {
            accountUrl = '/' + account.Id;
        } else {
            accountUrl = '/';
        }
        
        return accountUrl;
    }   

    public static testMethod void testLookupByUrlParamAccount() {
        LookupByUrlParamController controller = new LookupByUrlParamController();
        controller.accountName = 'Avaya';
        String redirectUrl = controller.redirectToAccount();
        System.assertEquals(redirectUrl, '/001A0000007UkkFIAS');
    }
    
    public static testMethod void testLookupByUrlParamInvalidAccount() {
        LookupByUrlParamController controller = new LookupByUrlParamController();
        controller.accountName = '';
        String redirectUrl = controller.redirectToAccount();
        System.assertEquals(redirectUrl, 'https://na7.salesforce.com/001/e');
    }
    
    public static testMethod void testLookupByUrlParamPhone() {
        LookupByUrlParamController controller = new LookupByUrlParamController();
        controller.phone = '1234';
        String redirectUrl = controller.redirectToAccount();
        System.assertEquals(redirectUrl, '/001A0000007UkkFIAS');
    }
    
     public static testMethod void testLookupByUrlParamWherePhoneNumberIs10Chars() {
        LookupByUrlParamController controller = new LookupByUrlParamController();
        controller.phone = '1234567891';
        String redirectUrl = controller.redirectToAccount();
        System.assertEquals(redirectUrl, 'https://na7.salesforce.com/001/e');//no record found
       
    }
    
    public static testMethod void testLookupByUrlParamInvalidPhoneNumber() {
        LookupByUrlParamController controller = new LookupByUrlParamController();
        controller.phone = '';
        String redirectUrl = controller.redirectToAccount();
        System.assertEquals(redirectUrl, '/001A0000015EKVPIA4');
        
    }
    
    public static testMethod void testLookupByUrlParamAccountNumber() {
        LookupByUrlParamController controller = new LookupByUrlParamController();
        controller.accountNumber = '4321';
        String redirectUrl = controller.redirectToAccount();
        System.assertEquals(redirectUrl, '/001A0000007UkkFIAS');
    }
    
    public static testMethod void testLookupByUrlParam() {
        LookupByUrlParamController controller = new LookupByUrlParamController();
        String redirectUrl = controller.redirectToAccount();
        System.assertEquals(redirectUrl, '/');
    }
    
}

此外,如果有人可以告诉我们在文档中的什么地方可以简单地启动到新的客户记录表单,或者重定向URLS是什么?

EN

回答 1

Stack Overflow用户

发布于 2021-01-31 06:33:37

不太清楚你所说的是什么意思

每次启动类时,我都会被重定向到Classic

然而,这段代码似乎已经有很多年没有被修改过了,有几件事你应该修改一下。

  1. 您正在对非我的域Salesforce实例URL (na7.salesforce.com)进行硬编码。你应该使用URL.getSalesforceBaseUrl().toExternalForm(),而且你迟早需要打开我的域名。

  1. 您正在使用经典格式的URL,这些URL仍然有效,但会导致额外的重定向。“创建新帐户”URL的Lightning等价物是lightning/o/Account/new,而特定记录的Lightning等价物是lightning/r/Account/<Id>/view。构建Lightning组件时,可以使用导航服务获取这些URL dynamically.

  1. 你有内联测试方法,这在我开始使用这个平台之前的API版本中是不允许的。将这些拆分到单独的测试类中。
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65965894

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档