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
LosintikfosLosintikfos 

Apex SQL

Hi Experts,

I am using an appex class and a trigger(before create) to update the address field of the account with its' parent address.
I am using below code, but keeps getting error:
Error: Compile Error: expecting a semi-colon, found '' at line 6 column 31

Can someone tell me what i am doing wrong in here?

public class addParent{

 public static void addAddress(Account[] a){
  // Account a:acc;
     String parent = a.ParentId;    
                    apex.query(select Id, BillingState, BillingCity, BillingCountry, BillingPostalCode, from Account where Id = 'parent');
                    function(qry:QueryResult):void {
                        if (qry.size > 0){
                            a.BillingState = qry.BillingState;
                            a.BillingCit = qry.BillingCity;
                            a.BillingPostalCode = qry.BillingPostalCode;
                            a.BillingCountry = qry.BillingCountry;
                        }
                    }
            }
     }
SuperfellSuperfell
I'm not sure how you came up with that syntax. You should probably start by reading some of the apex docs on the wiki
http://wiki.apexdevnet.com/index.php/Apex_and_Visualforce
LosintikfosLosintikfos
SimonF!

Was trying to work out how i can use SOQL in apex and loop through the result! didn't come accross anything useful in the language reference. Any samples?


B
SuperfellSuperfell
http://www.salesforce.com/us/developer/docs/apexcode/index_CSH.htm#langCon_apex_SOQL_VLSQ.htm
LosintikfosLosintikfos
Hi SimonF,

Imagine i do the loop query like this:
for (Account a : [SELECT id, name FROM account 
WHERE name LIKE 'Acme']) {
}

Can i select the values like this;

String id = a.id;
String name = a.name;
SuperfellSuperfell
Yes.
LosintikfosLosintikfos
Cheers!

I'm doing something like this;

public class addParent{

 public static void addAddress(){   
    Account[] ac;
    String parent = ac.ParentId;
                   
         for (Account a : [select Id, BillingState, BillingCity,BillingCountry, BillingPostalCode, from Account where Id LIKE 'parent']) {
              }
         }
     }

But gets error: Error: Compile Error: unexpected token: from at line 8 column 50,
Which is the line highlighted with red above! do you know why this error?

B



Message Edited by Losintikfos on 09-18-2008 09:15 AM
SuperfellSuperfell
you have a comma after BillingPostalCode that shouldn't be there.

also using "like 'parent'" will use the literal value parent, if you want to bind it to your parent variable, use like :parent

This doesn't make much sense either
Account[] ac;
String parent = ac.ParentId;

perhaps you want to pass parent in to the method as a parameter.
LosintikfosLosintikfos
Thanks SimonF! really appreciate your quick walkthrough.

Also you are absolutly right, want to pass parent as parameter to the query.

I did this;

Account[] ac;
String parent = ac.ParentId;

because i want the account ParentId value, to be used as a parameter as soon as a trigger is fired. Meaning the above represent the new account field.


Any suggestions?
SuperfellSuperfell
http://www.salesforce.com/us/developer/docs/apexcode/index_CSH.htm#apex_triggers_context_variables.htm
LosintikfosLosintikfos
Really lost here experts!

I am doing something this;

public class addParent{

 public static void addAddress(){
 
//Account object
 Account[] acc;

//initialize the ParentId field as variable
 String parent = acc.ParentId;

//Pass ParentId as parameter to search
         for (Account a : [select Id, BillingState, BillingCity,
              BillingCountry, BillingPostalCode from
               Account where id = 'parent']) {
              }
             
        //FEED THE RESULT BACK TO APPROPRIATE FIELDS
              acc.BillingPostalCode = a.BillingPostalCode;
          }
         
     }

This is to make sure before the account is created the parent address detail is load to the account, when the trigger is fired. Unfutunatly keeps getting the error below;


Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST:SOBJECT:Account at line 6 column 18

Any help please!


Message Edited by Losintikfos on 09-19-2008 04:47 AM
hisrinuhisrinu


It will solve your problem

Code:
for (Account a : [select Id, BillingState, BillingCity,
              BillingCountry, BillingPostalCode from
               Account where id = :parent]) {
              }

 
LosintikfosLosintikfos
Hi hisrinu,

I am trying to feed the value from the query into the field like this;

        //FEED THE RESULT BACK TO APPROPRIATE FIELDS
              acc.BillingPostalCode = a.BillingPostalCode;

but i get error;


Error: Compile Error: Variable does not exist: a.BillingPostalCode

Do you know how to go abt this?

Pls. Help

B


Message Edited by Losintikfos on 09-19-2008 05:58 AM
LosintikfosLosintikfos
Do you know how to select the value from the query?

Trying to do something like this;

String id = a.Id;

But wount' work. Any suggestions experts?


B
SuperfellSuperfell
Did you read the section in the docs on triggers i posted, that's not a trigger you're writing.
LosintikfosLosintikfos
Sorrry SimonF!
This actually not a trigger - it is the apex class which would be invoked by the trigger. Do you suggest avoiding this method and only use trigger instead?


Message Edited by Losintikfos on 09-22-2008 01:06 AM