SalesforceXyToolsCore/Python上でApexClassを作成・更新・削除

Topic

ApexClassの作成

  • Salesforce組織のユーザ名、パスワード、Apiバージョン、Product/Sandboxを設定してください。
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
from SalesforceXytoolsCore import *
import pprint
config = {
"api_version": 42.0,
"username": "sfdc username",
"password": "sfdc password",
"security_token": "",
"is_sandbox": True
}
tooling_api = ToolingApi(username=config["username"],
password=config["password"],
security_token=config["security_token"],
sandbox=config["is_sandbox"],
version=config["api_version"]
)
"""createApexClass"""
name = "HelloWorld"
body = """public class HelloWorld {
private String mystr;
}"""
status_code, result = tooling_api.createApexClass(name, body)
print(status_code)
pprint.pprint(result)

結果確認:

1
{'errors': [], 'id': '01pxxxxxxxxxxxxxxxxx', 'success': True}

ApexClassの更新

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from SalesforceXytoolsCore import *
import pprint
config = {
"api_version": 42.0,
"username": "sfdc username",
"password": "sfdc password",
"security_token": "",
"is_sandbox": True
}
tooling_api = ToolingApi(username=config["username"],
password=config["password"],
security_token=config["security_token"],
sandbox=config["is_sandbox"],
version=config["api_version"]
)
apexclass_id = "set your apex class id"
body = """public class HelloWorld {
private String mystr1;
}"""
tooling_api.updateApexClass(apexclass_id, body)

ApexClassの削除

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from SalesforceXytoolsCore import *
import pprint
config = {
"api_version": 42.0,
"username": "sfdc username",
"password": "sfdc password",
"security_token": "",
"is_sandbox": True
}
tooling_api = ToolingApi(username=config["username"],
password=config["password"],
security_token=config["security_token"],
sandbox=config["is_sandbox"],
version=config["api_version"]
)
apexclass_id = "set your apex class id"
body = """public class HelloWorld {
private String mystr1;
}"""
tooling_api.updateApexClass(apexclass_id, body)

その他

Triggerの作成

1
2
"""createTrigger"""
tooling_api.createTrigger(tableEnumOrId, name, body)

VisualForceの作成

1
2
"""createApexPage"""
tooling_api.createApexPage(MasterLabel, name, markup)

ApexComponentの作成

1
2
"""createApexComponent"""
tooling_api.createApexComponent(MasterLabel, name, markup)