Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

Fields defined on an extension can only be private, internal or public but not protected.

(0) ShareShare
ReportReport
Posted on by

Hi Team,

I have created an extension class for SalesConfirmDP but got below error while rebuilding.

pastedimage1680192569099v1.png

I guess, it is happening because of final keyword declaration. If yes , than how I can resolve this issue?

Pls give me more shed on this.

thanks!

  • Martin Dráb Profile Picture
    Martin Dráb 230,853 Most Valuable Professional on at
    RE: Fields defined on an extension can only be private, internal or public but not protected.

    The general recommendation is never using public instance variables. Such a design allows other classes to take dependency on implementation details of your class and it may harm maintainability and extensibility a lot.

    Instead, expose the value through a public method. Then you can change the implementation (e.g. change the value how you store the data or add extra logic, such as raising an event on value change) without changing the public interface of the class.

  • @rp@n Profile Picture
    @rp@n on at
    RE: Fields defined on an extension can only be private, internal or public but not protected.

    Thanks Girish

  • Verified answer
    GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Fields defined on an extension can only be private, internal or public but not protected.

    It depends on your requirement. Mostly it will be public only. If you declare it as public it will be accessible in all the methods.

    Thanks,

    Girish S.

  • @rp@n Profile Picture
    @rp@n on at
    RE: Fields defined on an extension can only be private, internal or public but not protected.

    Thanks Girish,

    Is it always public access modifier to declare in extension class?

    Pls give me more shed on this

  • Verified answer
    GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Fields defined on an extension can only be private, internal or public but not protected.

    Hi,

    In extension classes if you declare variables globally then you must give access specifier to a variables like below.

    Public SalesConfirmDetialsTmp confirmDetailsTmp;

    Public int i;

    Public int serialization;

    Thanks,

    Girish S.

  • Martin Dráb Profile Picture
    Martin Dráb 230,853 Most Valuable Professional on at
    RE: Fields defined on an extension can only be private, internal or public but not protected.

    I'm sorry, but I still don't know what you want to solve.

  • @rp@n Profile Picture
    @rp@n on at
    RE: Fields defined on an extension can only be private, internal or public but not protected.

    Let me know how can I solve this? What changes are required?

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,853 Most Valuable Professional on at
    RE: Fields defined on an extension can only be private, internal or public but not protected.

    What problem do you see there to solve?

    Protected members are used with inheritance and you can't inherit from final classes. And there is no point in having anything else than a final class, because the extension class is instantiated by the system (in a very special way) and it would never use a child class if there was any. Therefore it's all as it should be.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,996 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,853 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans