0
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Salesforceのプロファイルのメタデータの取得

Posted at

要件

プロファイルのメータデータをリストしたい場合、簡単のSfdxができないです。

プロファイル関連のオブジェクト、Tab、Flowなどpackage.xmlに入れて、Retrieveしたら、Profileに関連オブジェクト、項目セキュリティ、Apex、Pageの制御が出で来る。

 ※標準オブジェクトは一々に指定しないと、オブジェクトと項目のセキュリティがでない

実行

①package.xml

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>Account</members>
        <members>Case</members>
        <members>Contact</members>
        <members>Document</members>
        <members>Individual</members>
        <members>Task</members>
        <members>Event</members> 
        <members>*</members>
        <name>CustomObject</name>
    </types>
    <types>
        <members>*</members>
        <name>ApexClass</name>
    </types>
    <types>
        <members>*</members>
        <name>Flow</name>
    </types>
     <types>
        <members>*</members>
        <name>ApexPage</name>
    </types>
     <types>
        <members>*</members>
        <name>Layout</name>
    </types>
     <types>
        <members>*</members>
        <name>ApexClass</name>
    </types>
  <types>
    <members>*</members>
    <name>Workflow</name>
  </types>
   <types>
        <members>*</members>
        <name>Profile</name>
    </types>

    <types> 
        <members>*</members>
        <name>CustomApplication</name>
    </types>
    <types> 
        <members>*</members>
        <name>CustomTab</name>
    </types>
<version>48.0</version>
</Package>

②コマンド
sfdx force:source:retrieve -x manifest\package.xml -u deforg

excelでリストする

あるProfileから、Excelの指定シート名に書き込み
「settings」シートにフォルタとファイル名を指定(下記6行、C,D)
image.png

「ObjectPermissions」シートにオブジェクトの読み書き権限
image.png

VBA

Sub readXml()
On Error Resume Next
    Dim objDom As Object
    Dim fso As Object, buf As String
    Set fso = CreateObject("Scripting.FileSystemObject")
    Dim arrn As Variant
    
    Set srSht = Sheets("settings")
    fn0 = srSht.Cells(6, 4).Value
    fn = srSht.Cells(6, 3).Value & "\" & fn0
    
    
    ''C:\Work\Sample.txtの全ての文字を読み込んで表示します
    With fso.GetFile(fn).OpenAsTextStream
        buf = .ReadAll
        .Close
    End With
    Set fso = Nothing
    
    Set objDom = CreateObject("Msxml2.DOMDocument.3.0")

    objDom.LoadXML buf
    'objectPermissions
    Set tgSht = Sheets("ObjectPermissions")
    tgSht.Range("A1:AA10000").ClearContents
    Set recs = objDom.SelectNodes("//objectPermissions")
    arrn = Array("No.", "object", "allowCreate", "allowDelete", "allowEdit", "allowRead", "modifyAllRecords", "viewAllRecords")
    
    tgSht.Cells(1, 1) = fn0
    tgSht.Cells(2, 2) = arrn(0)
    tgSht.Cells(2, 3) = arrn(1)
    tgSht.Cells(2, 4) = arrn(2)
    tgSht.Cells(2, 5) = arrn(3)
    tgSht.Cells(2, 6) = arrn(4)
    tgSht.Cells(2, 7) = arrn(5)
    tgSht.Cells(2, 8) = arrn(6)
    tgSht.Cells(2, 9) = arrn(7)
    ii = 3
    For Each rec In recs
      tgSht.Cells(ii, 2) = ii - 2
      tgSht.Cells(ii, 3) = rec.SelectSingleNode(arrn(1)).Text
      For jj = 2 To 7
      If rec.SelectSingleNode(arrn(jj)).Text = "false" Then
        tgSht.Cells(ii, jj + 2) = ""
      Else
         tgSht.Cells(ii, jj + 2) = "O"
      End If
      Next jj
      ii = ii + 1
    Next
msgbox "Ok"

0
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?