You need to sign in to do that
Don't have an account?
Praveen N
getting dynamically field value from the object - not able to do
Hi ,
approval__c app=[select id,name,opportunity__r.name,opportunity__r.Account.name from Approval__c limit 1];
string str='name';
if(app.get(str)=='test')
system.debug('passed');
else
system.debug('failed');
// The above is working fine
str='opportunity__r.name';
if(app.get(str)=='test') // this is not working
system.debug('passed');
else
system.debug('failed');
actually str valu will come from another object.
when we have relationship not able to get the value from the object. is there any workaround to get?
Thanks
Praveen
Instead of the .get method on the SObject you will have to use the .getSObject method instead.
From there you can use the .get to get the property from the child Object.
Like so:
All Answers
Instead of the .get method on the SObject you will have to use the .getSObject method instead.
From there you can use the .get to get the property from the child Object.
Like so:
Hi Tan,
Thank you so much. it is working good. i had one more issue.
the order of relationship as like approval__c --> opportunity --> Account. means account is second level parent to approval__c.
i am not able to get these details.
approval__c app=[select id,name,opportunity__r.id,opportunity__r.name,opportunity__r.Account.name from Approval__c limit 1];
system.debug(app.opportunity__r.name);
string str='name';
if(app.get(str)=='test')
system.debug('passed');
else
system.debug('failed');
// The above is working fine
str='opportunityid';
if(((opportunity)app.getSObject('opportunity__r')).get('name')=='test') // this is not working
system.debug('passed');
else
system.debug('failed');
the above was working fine.
Sobject c=app.getSObject('opportunity.Account'); or Sobject c=app.getSObject('opportunity__r.Account');
Sobject c=app.getSObject('opportunity__r.Account__r');
i have tried in above three ways not able to get. could you please tell me is there any way to get.
thanks in advance.
Praveen
You'll have to use the getSObject on the Opporunity SObject that you retrieved from your Approval. You can't specify the relationships fields in the getSObject directly. So it will have to be something like this:
really super......
Thank you somuch Tan................