• Sarthak Patil 15
  • NEWBIE
  • 25 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
Hi everybody,

I am trying to access subquery field which is in a list.
ex: List<Account> newList = new List<Account>([Select Name,phone,(Select name,phone from Contacts)  from Account]);
In the above code the values can be accessed for account by using "newList.Name". But when i try to access contacts of that account i.e.(newList.Contacts.name).It is giving me error.

So,is there any way to access the subquery(Contacts) field values.

Thanks.
Hi everybody,
I am stuck with how to modify security settings using triigers.
Please help me to write the following trigger.
Set the OWD on the opportunity as private and Remove modify all permission on a profile using trigger.
Hi everybody,
I am trying to write the following trigger on contact.
"When a new contact is created for a existing account then set contact otherphone as account phone."

I have written this which is working fine.

Trigger TestNewCon on Contact (before insert){        
        for(Contact c : Trigger.new){
        for(Account acc: [Select id,phone from Account where id = :c.AccountId]){
            c.otherphone = acc.phone; 
        }
        }

Is there any other way to write this trigger because i want to avoid writing SOQL query inside for loop(NOT a best practise).
My plan is to fetch all the Accounts which are related to contacts first.
Hi everybody,

I am trying to access subquery field which is in a list.
ex: List<Account> newList = new List<Account>([Select Name,phone,(Select name,phone from Contacts)  from Account]);
In the above code the values can be accessed for account by using "newList.Name". But when i try to access contacts of that account i.e.(newList.Contacts.name).It is giving me error.

So,is there any way to access the subquery(Contacts) field values.

Thanks.
Hi everybody,
I am trying to write the following trigger on contact.
"When a new contact is created for a existing account then set contact otherphone as account phone."

I have written this which is working fine.

Trigger TestNewCon on Contact (before insert){        
        for(Contact c : Trigger.new){
        for(Account acc: [Select id,phone from Account where id = :c.AccountId]){
            c.otherphone = acc.phone; 
        }
        }

Is there any other way to write this trigger because i want to avoid writing SOQL query inside for loop(NOT a best practise).
My plan is to fetch all the Accounts which are related to contacts first.