0

I have a requirement for updating two picklist value if a checkbox is ticked.

  1. Feedback__c is one object which has Status__c and Resolution__c picklists.
  2. Feedback_Comments__c is another that will have a trigger and the checkbox.

If checkbox in Feedback_Comments__c is ticked then status in Feedback__c should be set to 'Closed' and Resolution to 'Fixed'.

I'm new to triggers. Following is my code.

trigger UpdateStatusResolution on Feedback_Comment__c (before insert) {
   for (Feedback_Comment__c fc: Trigger.new) {
        if(fc.Comment_closes_Feedback__c=true ) 
         Feedback__c.Status__c = 'Closed';
         Feedback__c.Resolution__c = 'Fixed';
    }
  }

Error: Compile Error: Expression cannot be assigned at line -1 column -1

Please guide me.

Thanks

  • Trigger will point to only one particular object. Is there any relation between those two objects – Sindoora Apr 16 '14 at 7:12
  • Do the two objects have a lookup relation? If tell us the relationship – highfive Apr 16 '14 at 7:12
  • There is a lookup relation from Feedback to Feedback_Comment – MnZ Apr 16 '14 at 7:13
  • 1
    I am not designer of this.... But shouldn't comment be child in this relationship? o.O – Artur Kępczyński Apr 16 '14 at 7:27
  • You can fix the prompted error with @pbattisson's answer. But looks like this should much tricky according to your business problem since you are using before trigger – highfive Apr 16 '14 at 7:29
3

Try

trigger UpdateStatusResolution on Feedback_Comment__c (before insert) {
    Feedback__c[] feedbacks = new Feedback__c[]{};
    for (Feedback_Comment__c fc: Trigger.new) {
        if(fc.Comment_closes_Feedback__c){ 
            feedbacks.add(new Feedback__c( Status__c = 'Closed',
                                           Resolution__c = 'Fixed'
                                           id = fc.Feedback__c
                                           ));
        }
    }

   if(!feedbacks.isEmpty()){
       update feedbacks;
   } 
}
  • Status__c and Resolutions__c fields are in Feedback__c object as per the question. – highfive Apr 16 '14 at 7:23
  • artur-kepczynski. Your code gave me this error.. Error: Compile Error: Invalid field Status__c for SObject Feedback_Comment__c at line 4 column 14. Status and Resolution are dependent picklists. Only if I select "Closed" value, there will be values in Resolution else blank. – MnZ Apr 16 '14 at 7:23
  • Is there a different way to call picklist values – MnZ Apr 16 '14 at 7:25
  • With the update as if(!feedbacks.isEmpty()){ update feedbacks; } } There is no compilation error. Lemme check the code. Thanks – MnZ Apr 16 '14 at 7:28
  • Working perfectly! May I know, what is the use of "id = fc.Feedback__c" and need of creation of Feedback__c[] ? Thanks – MnZ Apr 16 '14 at 7:37
3

On the line

if(fc.Comment_closes_Feedback__c=true)

You are using a single equals sign which is the assignment operator. Change this to == like

if(fc.Comment_closes_Feedback__c==true)

And your code should save and compile without that error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.