You need to sign in to do that
Don't have an account?
Field Update Trigger Help
Hi, I am not very experienced with APEX development, but I am trying to write a trigger that places the value of the Last_AM_Verbal_Contact, Last_AS_Verbal_Contact, Last_BD_Verbal_Contact, and Last_SF_Verbal_Contact fields on the account level onto the same fields on the Opportunity level. This is what I have so far:
trigger UpdateOppLastVerbalContactfromAcct on Account (after insert) {
Set<Id> Ids= new Set<Id>();
for (Account acc : Trigger.new)
{
Ids.add(acc.Id);
}
List<Account> accountList = new List<Account>([Select Id,Last_AM_Verbal_Contact__c,Last_AS_Verbal_Contact__c,Last_BD_Verbal_Contact__c,Last_SF_Verbal_Contact__c From Account a where Id in :Ids]);
for(Account temp : accountList )
{
Opportunity opp = new Opportunity();
opp.Last_AS_Verbal_Contact__c = temp.Last_AS_Verbal_Contact;
insert opp;
}
}
Error: Compile Error: Invalid field Last_AS_Verbal_Contact for SObject Account at line 12 column 41 |
I'm kinda confused why it's the field is invalid. On the Account level, these fields are populated from a trigger. I would figure that once the trigger populates it, then it wouldn't matter. Also the field type is a date, so that might be the issue too?
I realized, I forgot the __c at the end of the one field. Oops.
Now I am getting this error:
Hi brozinick,
Apex cannot implicitly cast from Date to String types. Try String s=String.ValueOf(dateobject);
Daniel Reid
Contact us - We can help!
Salesforce Superheroes
------------------------------
help@salesforcesuperheroes.com
www.salesforcesuperheroes.com
1-888-407-9578 x102
Hi,
This Error occurred because of changes in the field type.
Here you are trying to assign Field for type date to String.
So you face this issue.
However if you want to assign that you need to use Type casting techniques for this, as apex cannot type cast implicitly