• davix
  • NEWBIE
  • 20 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 8
    Replies
Apex code :
public class myClass {
    public ID seekAccount(String e164) {
        ID ref = NULL ;
        List<List< SObject>> searchList = [ FIND :e164 IN PHONE FIELDS RETURNING Account(ID LIMIT 1) ] ;

        Account[] searchAccounts = (Account[])searchList[0];
        for(Account a : searchAccounts)
        {
            ref = a.ID ;
        }
        return ref ;
    }        
}

Why Apex Test Code don't covere 100%, no " ref = a.ID " ?
@isTest
private class myClassTest {
    @isTest
    static void seekAccountTest() {     
        Id elt = null ; 
        Account a = new Account(Phone='33618181800', Name='33618181800') ;
        insert a ;

        myClass test = new myClass() ;
        elt = test.seekAccount('33618181800')  ;
        System.assertNotEquals(null, elt) ;
        System.assertEquals(a.ID, elt) ;
        elt = test.seekAccount('33618181801')  ;
        System.assertEquals(null, elt) ;
    } 
}

But It work if I use this solution, but I don't wish use it, because I must check severals objects :
 
public class myClass {
        public ID seekAccount(String e164) {
            ID ref = NULL ;
            List<Account> searchList = [ SELECT ID FROM Account WHERE Phone=:e164 ] ;
            for(Account a : searchList)
            {
                ref = a.ID ;
            }
            return ref ;
         }        
    }

 
  • August 08, 2016
  • Like
  • 0
I must be missing something but I'm new enough to not know what it is.  Thanks for any help.
Error : Variable does not exist: ApexPages
 
public class myClass {

    public String getIP() {
        String ip = null ;
        /* Don't work
         * String ip = ApexPages.currentPage().getHeaders().get('True-Client-IP');
        if (ip == '') {
            ip = ApexPages.currentPage().getHeaders().get('X-Salesforce-SIP');
        }*/
        system.debug(ApexPages);
        Map<String, String> entetes = ApexPages.currentPage().getHeaders();
        if(entetes != null) {
            ip = entetes.get('True-Client-IP');
            system.debug('-------Client IP------'+ip);
            if(ip == null)
                ip = entetes.get('X-Salesforce-SIP');
                system.debug('-------Salesforce IP------'+ip);  
        }
       return ip ;
    }
}


 
  • August 08, 2016
  • Like
  • 0
Apex code :
public class myClass {
    public ID seekAccount(String e164) {
        ID ref = NULL ;
        List<List< SObject>> searchList = [ FIND :e164 IN PHONE FIELDS RETURNING Account(ID LIMIT 1) ] ;

        Account[] searchAccounts = (Account[])searchList[0];
        for(Account a : searchAccounts)
        {
            ref = a.ID ;
        }
        return ref ;
    }        
}

Why Apex Test Code don't covere 100%, no " ref = a.ID " ?
@isTest
private class myClassTest {
    @isTest
    static void seekAccountTest() {     
        Id elt = null ; 
        Account a = new Account(Phone='33618181800', Name='33618181800') ;
        insert a ;

        myClass test = new myClass() ;
        elt = test.seekAccount('33618181800')  ;
        System.assertNotEquals(null, elt) ;
        System.assertEquals(a.ID, elt) ;
        elt = test.seekAccount('33618181801')  ;
        System.assertEquals(null, elt) ;
    } 
}

But It work if I use this solution, but I don't wish use it, because I must check severals objects :
 
public class myClass {
        public ID seekAccount(String e164) {
            ID ref = NULL ;
            List<Account> searchList = [ SELECT ID FROM Account WHERE Phone=:e164 ] ;
            for(Account a : searchList)
            {
                ref = a.ID ;
            }
            return ref ;
         }        
    }

 
  • August 08, 2016
  • Like
  • 0
I must be missing something but I'm new enough to not know what it is.  Thanks for any help.
Error : Variable does not exist: ApexPages
 
public class myClass {

    public String getIP() {
        String ip = null ;
        /* Don't work
         * String ip = ApexPages.currentPage().getHeaders().get('True-Client-IP');
        if (ip == '') {
            ip = ApexPages.currentPage().getHeaders().get('X-Salesforce-SIP');
        }*/
        system.debug(ApexPages);
        Map<String, String> entetes = ApexPages.currentPage().getHeaders();
        if(entetes != null) {
            ip = entetes.get('True-Client-IP');
            system.debug('-------Client IP------'+ip);
            if(ip == null)
                ip = entetes.get('X-Salesforce-SIP');
                system.debug('-------Salesforce IP------'+ip);  
        }
       return ip ;
    }
}


 
  • August 08, 2016
  • Like
  • 0