Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Apex Code Development
- :
- Trigger to update user
turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
0
Trigger to update user
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-05-2013 07:56 AM
I'm having trouble creating a basic trigger to update a user record. Basically, we have an object that has a lookup to a user. When the object meets a certain criteria I would like to deactivate the associated User. Here is what I've come up with so far that doesn't seem to be working:
Trigger:
trigger deactivateuser on On_Off_Boarding__c (before update) {
List<On_Off_Boarding__c> oblist = Trigger.new;
for(On_Off_Boarding__c ob : oblist){
if(ob.Last_Day__c == date.today()){
DeactivateUser user = new DeactivateUser (ob);
user.deactivateUser();
}
}
}
Class
public class DeactivateUser {
private On_Off_Boarding__c obAttribute;
//Constructor that accepts a On/Offboarding record
public DeactivateUser(On_Off_Boarding__c constructorob){
obAttribute = constructorob;
}
@future
static public void deactivateUser(){
if(obAttribute != null){
User u = new User();
u = [Select ID, Name, IsActive FROM User Where ID =:obAttribute.Associated_User__c];
u.IsActive=False;
}
Database.update(userAttribute);
}
}
Where am I going wrong? When trying to create the class, I get the "obAttribute.Associated_User__c variable does not exist".
Thanks!
0
Re: Trigger to update user
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-05-2013 08:03 AM
obAttribute is private, which means that it is only accessible inside instances of this class.
The deactivateUser method is static, which means that its associated with the class itself, rather than any instance.
Thus as far as the method is concerned, there is no variable of that name as its not visible in a static context.
The deactivateUser method is static, which means that its associated with the class itself, rather than any instance.
Thus as far as the method is concerned, there is no variable of that name as its not visible in a static context.
--
Certified Salesforce Technical Architect, Developer, Advanced Developer, Administrator, Advanced Administrator, Consultant, Sales Cloud Consultant,Service Cloud Consultant
Force.com MVP | The Bob Buzzard Blog | Linked In | Twitter
I don't respond to private messages/emails asking for help.
Certified Salesforce Technical Architect, Developer, Advanced Developer, Administrator, Advanced Administrator, Consultant, Sales Cloud Consultant,Service Cloud Consultant
Force.com MVP | The Bob Buzzard Blog | Linked In | Twitter
I don't respond to private messages/emails asking for help.
Take the Bob Buzzard Sobject Fields quiz.

