You need to sign in to do that
Don't have an account?
Losintikfos
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;
}
}
}
}
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;
}
}
}
}
http://wiki.apexdevnet.com/index.php/Apex_and_Visualforce
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
Imagine i do the loop query like this:
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
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.
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?
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;
Any help please!
Message Edited by Losintikfos on 09-19-2008 04:47 AM
It will solve your problem
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;
Do you know how to go abt this?
Pls. Help
B
Message Edited by Losintikfos on 09-19-2008 05:58 AM
Trying to do something like this;
String id = a.Id;
But wount' work. Any suggestions experts?
B
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