0 votes
4 views
by

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 Answer

0 votes
by
 
Best answer

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.

Welcome to Memory Exceeded, where you can ask questions and receive answers from other members of the community.
...