function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ramkramk 

retreive account records

hi

i have method which retreives account records...

 

how do i retreive  account records after the for loop.....

 

public List<Account> searchPhones(String phone)
        
          {
                    
               
             Account [] acc = [Select FirstName, LastName, MiddleName__pc, PersonMailingCity, PersonMailingState,
                               PersonHomePhone, PersonMobilePhone, Fax, 
                                PersonBirthdate, PersonMailingPostalCode
                               // ,
                              //  (Select FirstName__c, LastName__c, MiddleName__c From NameHistories__r)
                               From Account
                              where SearchWorkPhone7__c = :phone
                              or SearchMobilePhone7__c  = :phone 
                                 or SearchFax7__c = :phone limit 100];
                   
                          
                              for ( Account account: acc ) {
                         
                 
                                                   
                     }
              return account; 
          }

sourav046sourav046

What is your requirement ?your method seems to be working  fine .

 

But why do you want to retrieve it after the for loop ?and do you want to do the same using a APEX trigger ?

 

Please clarify we'll be able to help you asap .

TrinayTrinay

Hi ram,

  I dont get clear thought from your ques. I think the following will help for u.

 

    1. Declare your acc variable as public, then you can access it anywhere in the method.

     

    2. you need to retrive ur child (NameHistories__r) record, just use iteration over a two for loops. first one for parent another one child.

 

i hope this will help for u.

 

 

crop1645crop1645

I think this is even easier than you think -- 

 

public List<Account> searchPhones(String phone) {
     // returns list of Accounts where phone present in searchworkphone7__c, searchMobilePhone7__c or searchfax7__c
     return [Select FirstName, LastName, MiddleName__pc, PersonMailingCity, PersonMailingState,
                               PersonHomePhone, PersonMobilePhone, Fax, 
                                PersonBirthdate, PersonMailingPostalCode
                               From Account
                              where SearchWorkPhone7__c = :phone
                              or SearchMobilePhone7__c  = :phone 
                                 or SearchFax7__c = :phone limit 100];  
}