GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [apex] New rule EagerlyLoadedDescribeSObjectResult by jonathanwiesel · Pull Request #3538 · pmd/pmd

Conversation

@jonathanwiesel

@jonathanwiesel jonathanwiesel commented Oct 3, 2021

Copy link
Copy Markdown
Contributor

Describe the PR

New rule to promote the usage of SObjectDescribeOptions when calling getDescribe() to:

  • Avoid wasting resources on older API versions when it could not be necessary
  • Make it more consistent across implementations

Related issues

  • Fixes [apex] Promote usage of consistent getDescribe() info #3532

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jonathanwiesel
Add GetDescribeShouldUseSObjectDescribeOptions Apex rule
bd479e4
@jonathanwiesel jonathanwiesel changed the title Add GetDescribeShouldUseSObjectDescribeOptions Apex rule [apex] Add GetDescribeShouldUseSObjectDescribeOptions Apex rule Oct 3, 2021
@ghost

ghost commented Oct 3, 2021

Copy link
Copy Markdown
1 Message
📖 No java rules are changed!

Generated by 🚫 Danger

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adangel adangel self-assigned this Oct 5, 2021
adangel
adangel reviewed Oct 7, 2021
View reviewed changes

@adangel adangel left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

I've some suggestions for the rule documentation - could you please review/incorporate that in?

While reading https://www.ca-peterson.com/apex/2020/01/21/apex-describe-calls-what-you-need-to-know.html?utm_source=pocket_mylist I was wondering, whether this rule should additionally find usages of the following kind:

Schema.describeSObjects(new String[]{'User'})[0].isAccessible();

This seems to eagerly load the attributes as well.
It's described here: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_describeSObject.htm

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pmd-apex/src/main/resources/category/apex/performance.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-apex/src/main/resources/category/apex/performance.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-apex/src/main/resources/category/apex/performance.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-apex/src/main/resources/category/apex/performance.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

@adangel adangel added this to the 6.40.0 milestone Oct 7, 2021
@jonathanwiesel

jonathanwiesel commented Oct 9, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Thanks for the PR!

I've some suggestions for the rule documentation - could you please review/incorporate that in?

While reading https://www.ca-peterson.com/apex/2020/01/21/apex-describe-calls-what-you-need-to-know.html?utm_source=pocket_mylist I was wondering, whether this rule should additionally find usages of the following kind:

Schema.describeSObjects(new String[]{'User'})[0].isAccessible();

This seems to eagerly load the attributes as well. It's described here: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_describeSObject.htm

I would also like to point out that explicitly using the SObjectDescribeOptions also benefits on readability and consistency, similar to the intention of the DebugsShouldUseLoggingLevel rule.

Yes you're right, I will add it along with the other things you mentioned, thanks a lot

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jonathanwiesel
Fixing docs and add other describer fetcher
c331fa1
@jonathanwiesel
jonathanwiesel requested a review from adangel October 9, 2021 13:05
adangel
adangel approved these changes Oct 10, 2021
View reviewed changes

@adangel adangel left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks good now!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pmd-apex/src/main/resources/category/apex/performance.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-apex/src/main/resources/category/apex/performance.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

@adangel adangel changed the title [apex] Add GetDescribeShouldUseSObjectDescribeOptions Apex rule [apex] New rule EagerlyLoadedDescribeSObjectResult Oct 10, 2021
@adangel adangel added the a:new-rule Proposal to add a new built-in rule label Oct 14, 2021
adangel added a commit that referenced this pull request Oct 14, 2021
@adangel
[doc] Update release notes (#3532, #3538)
eeaa300
adangel added a commit to adangel/pmd that referenced this pull request Oct 14, 2021
@adangel
Merge pull request pmd#3538 from jonathanwiesel:consistent-describe
7e54213
[apex] New rule EagerlyLoadedDescribeSObjectResult pmd#3538
@adangel
adangel merged commit c331fa1 into pmd:master Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@adangel adangel adangel approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@adangel adangel

Labels

a:new-rule Proposal to add a new built-in rule

Projects

None yet

Milestone

6.40.0

Development

Successfully merging this pull request may close these issues.

[apex] Promote usage of consistent getDescribe() info

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@jonathanwiesel @adangel
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.