Friday, August 23, 2019

Method to retrieve correct ID from formula field.

One idea that really helpful to be delivered. Please vote
Reduce the compiled formula character cost of CASESAFEID()

Correct way to store ID in formula

Formula field only return 15 char ID and will be treated as String / Text . Which mean it will be treated as case insensitive in SOQL.

SELECT Id,Name,Parent.Id, Parent.Name, Ultimate_Parent_Account_ID1__c FROM Account WHERE Ultimate_Parent_Account_ID1__c ='001xxxxxxxxxQpK'

Will return record regardless the letter case
And also another  risk if  we query this with 18 digit ID as it will return 0 data.

As conclusion, normal formula with text return type is not able to capture the Salesforce Id correctly. 
In order to make it return as ID use CASESAFEID() . However this formula consumes so much character so that is the reason why you need to vote above idea.

Retrieve the correct Id from formula in Apex

If we are not able to use casesafeid in formula field , then we might need to be careful when retrieve record using formula field because SOQL is case-insensitve and ID is case sensitive. Honestly I wish that Salesforce provides a function that I can use directly in SOQL something like this ‘where casesafeid(Ultimate_Parent_Account_ID1__c) = ='001xxxxxxxxxQpKAAU' but unfortunately it is not available for this time being.

In order to ensure the Id is correct , we need to cast it to Id .Please note that I cast String to ID :
 Id ultimateid = (ID)account.Ultimate_Parent_Account_ID1__c . 

With this I can use the actual Id for further processing.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
String accountId15Char = '001xxxxxxxxxQpK';//because it will not entertain Id type or 18 character
Map<Id,Account> mapUltimateAccount =new Map<Id,Account>
                                      ([Select Id ,Parent.Id,Parent.Name  ,Ultimate_Parent_Account_ID1__c from Account where
                Ultimate_Parent_Account_ID1__c=:accountId15Char]);
        
         system.debug('@@@ mapUltimateAccount ' + mapUltimateAccount.size());
        //ultimate id contains complete hierarchy 
        //and exclude the account itself should be more than 1
        if(mapUltimateAccount.size()>1){
            for(Id accountId :mapUltimateAccount.keySet()){
               Account account =mapUltimateAccount.get(accountId);
               Id ultimateid = (ID)account.Ultimate_Parent_Account_ID1__c ;
               system.debug('Original Ultimate Id ' + account.Ultimate_Parent_Account_ID1__c+ ' , after convert to Id '+ ultimateid);
      
      //here you can have mechanism to compare id whether it returns the correct id
  
            }
           
        }

I think that's it for today. See you in next entry.

Monday, August 05, 2019

Soap UI fail to handshake with Salesforce

I faced this when doing Salesforce Trailhead : SOAP API Unit , it has nothing to do with token or password but something to do with TLS version. The solution can be referred here but I will re-write back how I solved this.

Note that I am using Windows 10 and SoapUI 5.3.0 .

Navigate to your SoapUI folder where it should be something C:\Program Files (x86)\SmartBear\SoapUI-5.3.0\bin . Notice there .vmoptions file.


Open that file and paste this

-Dsoapui.https.protocols=SSLv3,TLSv1.2
So it end result will look like this .
-XX:MinHeapFreeRatio=20

-XX:MaxHeapFreeRatio=40

-Xms128m

-Xmx1000m

-Dsoapui.properties=soapui.properties

-Dsoapui.https.protocols=SSLv3,TLSv1.2

-Dsoapui.home=C:\Program Files (x86)\SmartBear\SoapUI-5.3.0/bin

-Dsoapui.ext.libraries=C:\Program Files (x86)\SmartBear\SoapUI-5.3.0/bin/ext

-Dsoapui.ext.listeners=C:\Program Files (x86)\SmartBear\SoapUI-5.3.0/bin/listeners

-Dsoapui.ext.actions=C:\Program Files (x86)\SmartBear\SoapUI-5.3.0/bin/actions

-Dwsi.dir=C:\Program Files (x86)\SmartBear\SoapUI-5.3.0/wsi-test-tools

-Djava.library.path=C:\Program Files (x86)\SmartBear\SoapUI-5.3.0/bin

-Djava.util.Arrays.useLegacyMergeSort=true

-splash:SoapUI-Spashscreen.png
It should working now. Happy developing!