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

Help with a field update trigger
I am trying to write a simple trigger for a custom field update(text to text)
trigger UpdateCompanyOverviewField on Trip_Report__c (before insert) {
for( Trip_Report__c obj: trigger.new){
if(Company_Name__c=Name){
Company_Over__c = Company_Overview__c;
}
}
}
error: Variable does not exist: Company_Over__c
I am stumpmed as the API name for Company_Over__c checks out. Any help please
trigger UpdateCompanyOverviewField on Trip_Report__c (before insert) {
for( Trip_Report__c obj: trigger.new){
if(Company_Name__c=Name){
Company_Over__c = Company_Overview__c;
}
}
}
error: Variable does not exist: Company_Over__c
I am stumpmed as the API name for Company_Over__c checks out. Any help please
So for Company_Name__c, Company_Overview__c and Company_Over__c, you would have to add a 'obj.' in front of them.
Also, in your if statement, you have to have 2 equal signs (==). One equal signs (=) mean you're assigning the left value to the right value. Two equal signs checks for equality.
I tried it and it still throws an error. Company Overview Fields are Text Area on both Tabs
trigger UpdateCompanyOverviewField on Trip_Report__c (before insert)
{
for(Trip_Report__C trip:Trigger.new)
{
if(trip.Company_Name__c==[SELECT Name from Account])
{
trip.Company_Overview__c=[SELECT Company_Overview__c from Account];
}
}
}
Problem: Illegal assignment from LIST<Account> to String at Line 7
There's two errors in your code, and it is because your logic is flawed. [SELECT Name From Account] does not return Name, nor does [SELECT Company_Overview__c from Account] returns Company_Overview__c. These two SOQL returns the OBJECT with the information you selected. So for your first query, your query would return the object Account with the accessible information Name (all other fields are not accessible because you didn't select them). For your second query, your query would return the object Account with the Company_Overview__c information.
WHAT'S MORE is that you haven't set any prerequesites, so your queries will return ALL Accounts, returning a List rather than a single object.
To understand queries, this is how I view it:
[SELECT x FROM y] => Return all y with only the information x (disregarding any other possible fields from y). Now, to add prerequisites in order to get only the y/y's you want, you add a WHERE => [SELECT x FROM y WHERE z] => Return all y that meets the requirement(s) z with only the information x.
So, now back your situation, you would have to add a WHERE to both your queries in order to have a query search that returns ONE result (the result that concerns your trip object)
Here's more information on queries:
http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL.htm
If you need more clarification, please ask.