You need to sign in to do that
Don't have an account?
Kristi Gray
Rich Text Trigger
Hi! I am REALLY new to coding. I cannot seem to get this simple trigger to work. I want the rich text from my Service__c.Deliverables__c to be copied to Selected_Service__c.Custom_Description__c. What am I doing wrong? It gives me the error 'A value cannot be stored to Custom_Description__c in type Selected_Service__c
trigger updtrichtextfld on Selected_Service__c (before insert) {
for(Selected_Service__c u:trigger.new){
Selected_Service__c.Custom_Description__c=Service__c.Deliverables__c;
}
}
trigger updtrichtextfld on Selected_Service__c (before insert) {
for(Selected_Service__c u:trigger.new){
Selected_Service__c.Custom_Description__c=Service__c.Deliverables__c;
}
}
If the trigger is meant only for the above mentioned field update, you can use process builder rather than a trigger.
If not, Assuming Service__c is an object related to Selected_Service__c, and Service__c is the lookup field on Selected_Service__c object, below should help
trigger updtrichtextfld on Selected_Service__c (before insert) {
Set<Id> serviceIds = new set<Id>();
Map<Id, string> serviceMap = new Map<Id, string>();
for(Selected_Service__c ss : Trigger.new)
{
serviceIds.add(ss.Service__c); //to fetch related Id
}
//Description field needs to be queried else will result in null
for(Service__c ser : [select id, Deliverables__c from Service__c where id in: serviceIds])
{
serviceMap.put(ser.id, ser.Deliverables__c );
}
for(Selected_Service__c u : trigger.new)
{
//Selected_Service__c.Custom_Description__c=Service__c.Deliverables__c; This is wrong
u.Custom_Description__c = serviceMap.get(u.Service__c);
}
All Answers
If the trigger is meant only for the above mentioned field update, you can use process builder rather than a trigger.
If not, Assuming Service__c is an object related to Selected_Service__c, and Service__c is the lookup field on Selected_Service__c object, below should help
trigger updtrichtextfld on Selected_Service__c (before insert) {
Set<Id> serviceIds = new set<Id>();
Map<Id, string> serviceMap = new Map<Id, string>();
for(Selected_Service__c ss : Trigger.new)
{
serviceIds.add(ss.Service__c); //to fetch related Id
}
//Description field needs to be queried else will result in null
for(Service__c ser : [select id, Deliverables__c from Service__c where id in: serviceIds])
{
serviceMap.put(ser.id, ser.Deliverables__c );
}
for(Selected_Service__c u : trigger.new)
{
//Selected_Service__c.Custom_Description__c=Service__c.Deliverables__c; This is wrong
u.Custom_Description__c = serviceMap.get(u.Service__c);
}
trigger updtrichtextfld on Selected_Service__c (before insert) {
for(Selected_Service__c selected :trigger.new){
selected .Custom_Description__c=selected .Deliverables__c;
}
}
If I try the following, it gives me the error 'extra ';', at Service__c.Deliverables__c' and the error ' Illegal assignment from Selected_Service__c to String'
trigger updtrichtextfld on Selected_Service__c (before insert) {
for(Selected_Service__c selected :trigger.new){
selected .Custom_Description__c=selected Service__c.Deliverables__c;
}
}