• Alejandro Hartoch
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Apologies if my question my be so dumb but my programming skills are really limited and I'm on a hurry for a PoC.
I have the apex class below which was developed for Classic. I would like to make it work with lighting and I'm not sure if the only thing I need to replace are the url's. I have created a developer account for my PoC and everytime I launch the class I'm redirected to Classic.
 
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, '/');
    }
    
}

In addition if anyone can tell where to being looking in the documentation to simply launch to new customer record form, or what are the redirect URLS?

Thanks,
Alex
Apologies if my question my be so dumb but my programming skills are really limited and I'm on a hurry for a PoC.
I have the apex class below which was developed for Classic. I would like to make it work with lighting and I'm not sure if the only thing I need to replace are the url's. I have created a developer account for my PoC and everytime I launch the class I'm redirected to Classic.
 
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, '/');
    }
    
}

In addition if anyone can tell where to being looking in the documentation to simply launch to new customer record form, or what are the redirect URLS?

Thanks,
Alex

My Salesforce environment is configured for Salesforce single sign-on, and I would like to render a Visualforce page within an existing application web page, external to Salesforce.

 

By adusting the clickjack protection settings, I can render a Visualforce page in an iframe on a page external to Salesforce, but only if the browser has already authenticated to Salesforce.  But if the user has not yet authenticated to Salesforce, the iframe render stops once it reaches login.salesforce.com because x-frame-options: deny tells the browser that the page may not be rendered in an iframe.  Specifically, login.salesforce.com returns x-frame-options:deny on the final call to login.salesforce.com, if you're familiar with the sequence of redirects used for SSO.  I can post a trace if that would help explain better.

 

It would be high value to be able to render visual force pages, and the associated single sign-on authentication, as an iframe.

 

Is this possible using a configuration setting or is there another workaround possible?  Is there any possibility that this may change in a future release?