You need to sign in to do that
Don't have an account?

Redundant List
Hi I'm new to Salesforce
In the follwing code, how can I avoid using the con List.
Is there a way in which you can use SOQL query on trigger.new directly instead of bringing in another List ??
trigger ContactTest on Contact (before insert, before update) {
List<Contact> con = [Select Id, Account.Phone from Contact where Id in : trigger.new];
for(Contact c: trigger.new)
{
for(Integer i=0; i< trigger.new.size() ; i++)
{
c.OtherPhone = con[i].Account.Phone;
}
}
}
Also, can the above update be done with WOrkflow Rules ??
Thanks,
Murthy
In the follwing code, how can I avoid using the con List.
Is there a way in which you can use SOQL query on trigger.new directly instead of bringing in another List ??
trigger ContactTest on Contact (before insert, before update) {
List<Contact> con = [Select Id, Account.Phone from Contact where Id in : trigger.new];
for(Contact c: trigger.new)
{
for(Integer i=0; i< trigger.new.size() ; i++)
{
c.OtherPhone = con[i].Account.Phone;
}
}
}
Also, can the above update be done with WOrkflow Rules ??
Thanks,
Murthy
Mark resolved. If it resolves your query
You can achieve this using the formula field on the Contact. But the field will be readonly if you make it as a formula filed.
(or)
Using the below trigger:
If it is only one field then you can proceed with formula field, if incase if you want to go with trigger then the advantage of using it is, if you want to populate more fields in the future, it will be very easy.
Please let me know if this helps for you.
Regards,
Mahesh