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

Help with a Field Update Trigger
I need the field on Trip Report>Company Overview to be updated on the Display page with the value from Account>Company Overview once a new trip report is saved.
trigger UpdateCompanyOverviewField on Trip_Report__c (after insert,after update) {
Trip_Report__c trip=trigger.new[0];
if(trip.Company_Name__c!=null){
trip.Company_Overview__c = [SELECT Company_Overview__c FROM Account WHERE Name=:trip.Company_Name__c];
update trip;
}
}
Error: Compile Error: Illegal assignment from LIST<Account> to String at line 4 column 17
I did try using the Formula field and a field update workflow to implement this but it didn't work because
A. Trip Report>COmpany Name field is a lookup field to Account
B. The Company Overview fields are both Text Area fields.
Any help please
trigger UpdateCompanyOverviewField on Trip_Report__c (after insert,after update) {
Trip_Report__c trip=trigger.new[0];
if(trip.Company_Name__c!=null){
trip.Company_Overview__c = [SELECT Company_Overview__c FROM Account WHERE Name=:trip.Company_Name__c];
update trip;
}
}
Error: Compile Error: Illegal assignment from LIST<Account> to String at line 4 column 17
I did try using the Formula field and a field update workflow to implement this but it didn't work because
A. Trip Report>COmpany Name field is a lookup field to Account
B. The Company Overview fields are both Text Area fields.
Any help please
Soql query return a list and you store the result in a field it is not possible.
you have some options-
-
Use LIMIT cause in query. i.e
-
Use this code--
It'll help you.I used your 2 option and even though the trigger got saved- the Details page throws an error on save
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger FetchCompanyOverviewFromAccount caused an unexpected exception, contact your administrator: FetchCompanyOverviewFromAccount: execution of AfterInsert caused by: System.QueryException: List has no rows for assignment to SObject: Trigger.FetchCompanyOverviewFromAccount: line 5, column 1
Firstly Bulkfy your trigger. Iterate the trigger Contaxt.
try this.