Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML for virtual organization #17

Open
Safintim opened this issue Jun 7, 2022 · 3 comments
Open

XML for virtual organization #17

Safintim opened this issue Jun 7, 2022 · 3 comments

Comments

@Safintim
Copy link
Contributor

Safintim commented Jun 7, 2022

I found an article that talks about future plans. Did I understand correctly that there are plans to use XML as object validation? If so, that's a great idea. I would like to analyze it and maybe suggest something.

@brno32 How can you get XML for your organization? I searched and couldn't find it.

kicksaw article

@brno32
Copy link
Contributor

brno32 commented Jun 7, 2022

Yes it's my long-term goal to use an org's definition to provision the virtual salesforce org, but it's a huge task and we haven't started on it yet.

You could use the metadata api to download the source for your org, or use sfdx to retrieve the XML definition of a lot of Salesforce resources, and it would be cool if mockforce read either of those.

@Safintim
Copy link
Contributor Author

Safintim commented Jun 7, 2022

I suggest start with a simpler format - json.
Implement simple checks on the data type nullable, required.

Do you have any ideas yet? I think straightforward checks would be difficult to support (I mean, do JSON, xml analysis every time).

I think in this situation code generation is appropriate. datamodel-code-generator (generate pydantic model for validation) provides such functionality. For example we could analyze JSON, XML - prepare json or yaml for datamodel-code-generator, generate models and do validation based on them. There are a lot of questions here.

Did some research.
Also Salesforce REST API from v54.0 in beta mode generates openapi documentation. I tried it, the file for the test organization is about 18 MB. Unfortunately, there is no data there whether the field is mandatory whether it can be null. datamodel-code-generator generated for 38 thousand lines of python code :)

@brno32
Copy link
Contributor

brno32 commented Jun 10, 2022

Oh sure we'd convert the XML to JSON at runtime, but what I mean is Salesforce can give you an org definition in xml format using the metadata or soap api. From that xml, we could read the schema and use that to build a virtual salesforce org that more closely resembles the org in question.

It'd be cool if we could use the openapi documentation, but I don't think it would work for our needs as you said. I think using sfdx or the metadata api already wrapped in simple-salesforce would work better. From there, we could get the xml schema of all the objects, convert to json with xml2dict, and then write code to more closely mimic the behavior of the real Salesforce API like you suggested: check for required fields, validate data types, check field and object names are correct, etc

I hadn't thought of using a code generation tool, but I'm definitely interested in that idea!

Here's a trailhead for sfdx https://trailhead.salesforce.com/content/learn/modules/sfdx_app_dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants