Wednesday, February 16, 2022

Window command : MS-DOS Doskey native window utility check command prompt history . Make record of cmd command easily

 It can be trouble when we runs a lots of command in command prompt . It made so many changes in short time ,which may need to be recovered later.

But it is not easy to remember every command you types , with native utility , we may retrieve command history with line line below :

Just open your command prompt and type 

doskey /history

#For keeping record in text log file
doskey /history > myCmd20220216.log 

Press "Enter"  , Finished ! 

Finally, very important thing is that the history is session history .
It only keeps command history BEFORE you CLOSE the command prompt. 

Thursday, January 13, 2022

Salesforce concept : Validation rule does not fired after approval process field update

Validation rule will not be fired by Workflow rule or Approval Process field update based on document.

Both API level and UI level change of record honored validation rule , but field update is an exception.

Which means , if you have an validation rule block field_ABC value to be "ABC", if you used a field update to do this, the value of  field_ABC can be set as "ABC".



Official IdeaExchange 1

"because updates to records based on workflow rules doesn't trigger validation rules,workflow rules can invalidate previously valid fields "


Official IdeaExchange 2




Wednesday, January 12, 2022

Salesforce Apex code to detect Chinese or Japanese characters 在字串中尋找漢字 包含中文字 或 日文字

 Sometimes we have to identify the language character inside string . Code below shows how to use Apex code to identify whether a specific string contains "Hanzi" or not . 

#Please be reminded that "Hanzi" NOT just detect Chinese characters , it may also include Japanese Hanzi.  

1
2
3
4
5
6
//true if contain chinese or japanese hanzi
public static Boolean containsChineseCharacters(String InputString){
    Pattern p = Pattern.compile('\\p{IsHan}');
    Matcher m = p.matcher( InputString );
    return m.find();
}

Tuesday, January 11, 2022

Copy files based on file list document 按照文件清單複製檔案 抄送

 Consider of a scenario, partner's SFTP server is down for an hour . A lots of files failed to upload to them.  After comparing the file list of two company, a missing file list text file has been created.
Maybe 100 out of 1000 files are missing.

Hence, you are going to resend those missing files based on the file list.
Batch script below help to do the job in an easy way.

You may just copy all missing files to a new folder, then resend.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
@ECHO ON


SET FileList=C:\Users\XXX\MissingFiles.txt
::The folder that contains the files
SET Source=X:\AllFiles
::The folder that the files should be copied to
SET Destination=Y:\ToBeResend

 

FOR /F "USEBACKQ TOKENS=*" %%F IN ("%FileList%") DO XCOPY /F /Y "%Source%\%%~F" "%Destination%\"

GOTO :EOF

 

Monday, May 31, 2021

Salesforce Permission : Manual Share Record using Apex Bulk API 分享單筆資料代碼

 

 
There are different way of sharing a "private" object record in sfdc.
Include using inherit role hierarchy ,sharing rule , or pressing custom button "Sharing"
on record detail page in user interface. 

Codes below try to use apex API to do the same thing as the "Sharing" button.
#Salesforce分享單筆資料代碼
 

    // Create new sharing object for the custom object named MyCustomObject.
      MyCustomObject__Share myCustomObjectShr  = new MyCustomObject__Share();
   
      // Set the ID of record being shared.
      myCustomObjectShr.ParentId = recordId;
        
      // Set the ID of user or group being granted access.
      myCustomObjectShr.UserOrGroupId = userOrGroupId;
        
      // Set the access level.
      myCustomObjectShr.AccessLevel = 'Read';
        
      // Set rowCause to 'manual' for manual sharing.
      // You may change to other row cause if you have created other sharing reason.
      myCustomObjectShr.RowCause = Schema.myCustomObject__Share.RowCause.Manual;
        
      // Insert the sharing record and capture the save result. 
      Database.SaveResult sr = Database.insert(myCustomObjectShr,false);
 
      // Process the save results.
      if(sr.isSuccess()){
         // Indicates success
         System.debug(LoggingLevel.INFO, 'Done');
      }
	else{
          // read first save result error.
         Database.Error err = sr.getErrors()[0];
         System.debug(LoggingLevel.ERROR, 'Error code :' + err.getStatusCode() );
      }

Thursday, May 13, 2021

Batch script commands to split big text file in windows with efficiency comparison 命令提示字元 分割打開超大型檔案

When we try to open the big file (e.g. : server log), we may meet an error when we open with text editor.

Notepad : File is too large for Notepad .

Notepad++ : File is too big to be opened .

At this point, the only way is try to split the file using program. Surely it is always good to use those "close to metal" language like C++ . However , you may not want to install compiler , SDK etc.

Is there any convenient way ? Yes ,using batch script is always a solution .
But always remember , it may takes you more than half hour to split 1GB file into 100 small files.

Code in Batch .bat script (Method 1 Faster)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
@echo off
setLocal EnableDelayedExpansion
set limit=50000 #Rows per file
REM can be in any extension (e.g. csv ) , as long as it is a text file 
set file=YourFileName.txt
set lineCounter=1
set filenameCounter=1

set name=
set extension=
for %%a in (%file%) do (
    set "name=%%~na"
    set "extension=%%~xa"
)

for /f "tokens=*" %%a in (%file%) do (
  
    if !lineCounter! gtr !limit! (
        set /a filenameCounter=!filenameCounter! + 1
        set lineCounter=1
        echo Created !splitFile!.
    )
    REM Output filename pattern YourFileName-part1.csv , YourFileName-part2.csv
    set splitFile=!name!-part!filenameCounter!!extension! 
    echo %%a>> !splitFile!
  
    set /a lineCounter=!lineCounter! + 1
)


Code in Batch .bat script (Method 2 Slower)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
@echo off
setlocal enableextensions disabledelayedexpansion
set STARTTIME=%TIME%
set "nLines=50000" #Rows in each file
set "line=0"
REM can be in any extension (e.g. csv ) , as long as it is a text file 

for /f "usebackq delims=" %%a in ("InputFileName.txt") do (
    set /a "file=line/%nLines%", "line+=1"
    setlocal enabledelayedexpansion
    for %%b in (!file!) do (
        endlocal
         >>"OutputName_%%b.txt" echo %%a 
         REM Ouput filename pattern : OutputName_1.txt , OutputName_2.txt
         REM Filename prefix will NOT follow the input file in this way.
    )
)


  • Efficiency Comparison 

            The way of writing the script could lead to double process time.

  • Test with 100K rows , >18 MB file.

           For example : Split a file 18.7MB into 3 files (each file with max 31670 rows). 

           Using method 1 one takes 23s , while using method 2 takes 46s.

  • Test with 5000K rows , >1 GB file

           With method 1 , if a 1.17GB (1230188 KB , around 5000Krows inside) has to be split into 100                         small files (50K rows @file) , it takes 30m42s .

            With method 2, believer me, you don't want to try.

  • PC configuration reference 

           16GB RAM , with 8 x QuaCores , i5 CPU.  


Conclusion
- Better use C++ to split file over 1GB . ;)

 

Wednesday, April 28, 2021

Kirikiri 2 game error under Window 10 Unable to load the plug-in windowEx.dll - 修正 吉里吉里 2 報錯解決

To run Kirikiri 2 under window 10 environment , error "An exception occurred in the script Unable to load the plug-in windowEx.dll" may be popped up and lead to application crash (or cannot start the game).

Japanese version : 例外が発生 プラグイン windowEx.dll を読み込めません 
English version : An exception occurred in the script Unable to load the plug-in windowEx.dll

The error can be fixed by installing Microsoft Visual C + + 2010 Redistributable Package (x 86) 
Exact file needed : vcredist_x86.exe
Download page : Microsoft Official Link


Migrating from Renpy to Godot

 Due to the limitation of renpy in rendering dynamic screen ,  due the the black border it gives in different UI scale resolution , finally ...