function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
brozinickrbrozinickr 

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?

 

 

 

brozinickrbrozinickr

I realized, I forgot the __c at the end of the one field.  Oops.

 

Now I am getting this error:

 

 Error: Compile Error: Illegal assignment from Date to String at line 12 column 9

 

 

  

 

 

Daniel.ReidDaniel.Reid

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

HariDineshHariDinesh

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

 

opp.Last_AS_Verbal_Contact__c = string.valueof(temp.Last_AS_Verbal_Contact__c);

 

brozinickrbrozinickr
Thank you both for your help! I appreciate it! I changed it and it works fine now. Thank you! [Description: signature1] salesforce.com developer rachelbr@angieslist.com 317-396-2692 [Description: Description: salesforce][Description: Description: DSlogo][Description: Description: HooplaLogo]