+ Start a Discussion
Santi Ram RaiSanti Ram Rai 

Trigger (By Defultls select the "Inactive" value from picklist)

Hi everybody,

My intension is; by befultls select the "Inactive" value from picklis.

Here is my code:
trigger UpdateStatus on Project__c (before insert) {
   for (Project__c fc: Trigger.new) {
        if(fc.Project__c=true ) 
         Project__c.Status__c = 'Inactive';
    }
  }

But, i have thiss error:
User-added image
 
Best Answer chosen by Santi Ram Rai
srlawr uksrlawr uk
yes, this is the problem - you say there isn't a field called Project__c on your custom object Project__c ??

On line 7 - you are saying IS the field Project__c on the object fc (which is a Project__c) true. You need to not reference this field if it doesn't exist!!

What are you trying to check before you set Status__c to 'Closed' ?

All Answers

srlawr uksrlawr uk
you're close! but your "if" statement needs a logical comparitor, not an assignment (double == verus single =)
 
trigger UpdateStatus on Project__c (before insert) {
   for (Project__c fc: Trigger.new) {
        if(fc.Project__c == true ) 
         Project__c.Status__c = 'Inactive';
    }
  }

 
Santi Ram RaiSanti Ram Rai
No, still same error.
Tarun J.Tarun J.
Hello Santi,

Update operator under your IF condition. It would be comparision (==) insteaod assignment (=).

if(fc.Project__c == true){

}
Santi Ram RaiSanti Ram Rai
Hi srlawr uk,
Still same error.
srlawr uksrlawr uk
are you absolutely sure you have made the IF a double equals? because that is definitely the cause of the error message. it's a classic typo... as also documented here: https://developer.salesforce.com/forums/?id=906F00000008z3NIAQ (and numerous other places!)
Santi Ram RaiSanti Ram Rai
Yes i made the change.
Here:
trigger StatusUpdate on Project__c (before insert) {
    for (Project__c s: Trigger.new) {
        if(s.Project__c == true ) 
         Project__c.Status__c = 'Inactive';
    }
}

But values are from Picklist. And is has 3 values(Active, inactive and closed)
srlawr uksrlawr uk
that is very weird then. here are some other things I would check:


You don't have another trigger or apex class called UpdateStatus

You do have a custom object called Project__c

This also has a field called Project__c - which can be evaluated

This object also has a field called Status__c - which can be set (ie isn't a read only formula or rollup)
Santi Ram RaiSanti Ram Rai
Hi srlawr uk,

UpdateStatusis my trigger not  apex class.
Yes, Project__c is my custom object.
Actually field called Status__c, picklist field(Inactive, Active, Closed)
srlawr uksrlawr uk
and Project__c has a field called Project__c too?
Santi Ram RaiSanti Ram Rai

No,  Project__c is custom object and it has a field called Status__c not Project__c.
srlawr uksrlawr uk
ok, then there is the problem, on line 3 you are saying 
 
​if(fc.Project__c == true )

and "fc" is the project record, whilst .Project__c is a field on it.

What is it you want to be "true" on the project to set the status?
Santi Ram RaiSanti Ram Rai
No, Project__c is Ovject.
srlawr uksrlawr uk
ok. but in your code "fc" represents a project object... lemmie break it down:

 
trigger UpdateStatus on Project__c (before insert) {

   // for every Project__c going through this trigger.... assign that project to "fc" in each case
   for (Project__c fc: Trigger.new) {

       // if this project__c (known as fc) has the value true in a FIELD called Project__c then do this code
        if(fc.Project__c == true ) 
            // set the value of the FIELD status__c in this project__c (known as fc) to 'inactive'
            fc.Status__c = 'Inactive';

    }
}

 
Santi Ram RaiSanti Ram Rai
How, i have this error:
User-added image
srlawr uksrlawr uk
yes, this is the problem - you say there isn't a field called Project__c on your custom object Project__c ??

On line 7 - you are saying IS the field Project__c on the object fc (which is a Project__c) true. You need to not reference this field if it doesn't exist!!

What are you trying to check before you set Status__c to 'Closed' ?
This was selected as the best answer
Santi Ram RaiSanti Ram Rai
Thanks srlawr uk,

I got the point.