0

Hi I am trying to write a trigger on custom object Quote_Request__c - where I want to run the trigger when any field changes are performed on the Quote request records (except profile ids id1 or id2)

trigger QuoteRequestChangeTrigger on Quote_Request__c (Before update) {
Schema.DescribeSObjectResult objSchema = Quote_Request__c.sObjectType.getDescribe();
Set<String> fields = objSchema.fields.getMap().keySet();

String[] changedFields  = new String[]{};
for(Quote_Request__c c; trigger.new;){
    for(string s: fields){
        if(c.get(s) != trigger.oldMap.get(c.Id).get(s)){
            changedFields.add('Contact: ' + c.Id + ' - ' + s + ' - old:' + trigger.oldMap.get(c.Id).get(s) + ' new:' + c.get(s));
        }
    }
}

The intent of the trigger is to update the rich text field (Via Process Builder) on quote request with changed field script that is defined on the trigger

changedFields.add('Contact: ' + c.Id + ' - ' + s + ' - old:' + trigger.oldMap.get(c.Id).get(s) + ' new:' + c.get(s));

However, my trigger is coming with the error for the line 6:

 for(Quote_Request__c c; trigger.new;){

The error is: Condition expression must of type Boolean: List

Also how can I exclude profile ids ID1 or iD2 by triggering the changes?

What I am missing? Thank you for the help.

1
  • I'm intrigued by your mention of Process Builder. From the sounds of it, you are using the trigger to set a value on the record which a Process Builder will then pick up and do further updates. Can you not do the Process Builder's work in the trigger? Process Builder has no concept of "before" or "after", it's all after, so that update will cause this trigger to fire again, and you're not checking whether this rich text field has already bee set. – barrick Apr 8 at 21:36
1

The syntax for a for loop over an iterable (like sets and lists) is

for(<Type> <loop variable name> :<iterable>)

for(Quote_Request__c c; trigger.new;) is not proper syntax (those semicolons are incorrect).

What you're looking to write here is instead
for(Quote_Request__c c :trigger.new)
though I would recommend coming up with a more descriptive variable name. Something like quoteReq is superior to c. It may not be an issue with your trigger now (since it's short enough), but it's good practice.

As for making certain profiles not execute the actual work of the trigger, the simplest approach would be to simply return; if you detect one of your target profiles. The Userinfo class can help you figure out information about the user who caused the trigger to fire.

0

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.