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

fflib_QueryFactory support for toLabel()? #163

Open
dudunato opened this issue Apr 8, 2017 · 9 comments
Open

fflib_QueryFactory support for toLabel()? #163

dudunato opened this issue Apr 8, 2017 · 9 comments

Comments

@dudunato
Copy link

dudunato commented Apr 8, 2017

Is there a way to use QueryFactory and get the translation for a picklist? Like:

SELECT Id, Name, toLabel(ServiceType__c)
FROM Time__c
@dudunato
Copy link
Author

Anyone?

@afawcett
Copy link
Contributor

Sorry @dudunato for the delayed response. I don't see a way of doing this currently no. @capeterson and proposals on the best API design to accomplish this, maybe overload the select method with a boolean param 'toLabel' ?

@dudunato
Copy link
Author

Thanks for the reply @afawcett!

Wouldn't it be better if we would have the option on a field level?
Something like query.selectField('toLabel(FieldName__c)')

Or even query.selectField('FieldName__c', true) and this boolean parameter would be a flag to add the field to a Map to be converted to toLabel() when the method toSOQL be called.

Idk, just ideas!

@afawcett
Copy link
Contributor

Yes, your second idea is the one i was suggesting actually. Though your first is more flexible, it just means the query factory cannot validate the field as its an expression being passed.

@tomjansen13
Copy link

Is there already a solution for this? I'm trying to get the label of a Data Category in a subquery on Knowledge Articles.

@dudunato
Copy link
Author

HI @tomjansen13,

I don't think this solutions was implemented. What I ended up doing was to use replace() function after building up the whole query. Super ugly, but... ¯_(ツ)_/¯

@tomjansen13
Copy link

Hi @dudunato Thanks for the 'solution'. I guess this is better than nothing at all!

@anirudhs2005
Copy link

I was actually working on a similar requirement and I believe you can specify an alias to the field. SObject.get('') gives you the correct answer.

Example

  1. List records = Database.query('select id, Rating, toLabel(Rating) myAccountRating from Account LIMIT 1' );
  2. String translatedValue = records[0].get('myAccountRating');
  3. system.debug(translatedValue);

I am guessing it must be possible to add an alias to a toLabel field somewhere.

@foxysolutions
Copy link
Contributor

Suggested PR change to allow toLabel within the fflib framework can be found here: #258

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

No branches or pull requests

5 participants