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
- :
- retreiving custom object type from what field
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
retreiving custom object type from what field
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-07-2012 01:52 PM
I wanted to build a simple trigger on the Event that would make a checkbox true if the What field looked up to one of our custom objects, and false otherwise. But with my attempt at this, it keeps making the checkbox true regardless of what is related to the event and I don't understand why. Here's the code:
trigger WorkOrderCheckbox on Event (before insert, before update) {
for(Event newEvent : trigger.new) {
if(newEvent.What instanceof SVMXC__Service_Order__c) {
newEvent.Work_Order__c = true;
} else {
newEvent.Work_Order__c = false;
}
}
}What am I doing wrong here?
Solved! Go to Solution.
Re: retreiving custom object type from what field
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-07-2012 02:56 PM
Try this:
trigger WorkOrderCheckbox on Event (before insert, before update) {
for(Event newEvent : trigger.new) {
Schema.SObjectType objType;
string target = newEvent.whatID;
Map<String, Schema.SObjectType> GD = Schema.getGlobalDescribe();
string keyPrefix;
for(Schema.SObjectType describe: GD.values() ){
keyPrefix = describe.getDescribe().getKeyPrefix();
if(keyPrefix != null && target.startsWith(keyPrefix)){
objType = describe;
break; //no need to keep looking
}
}
if(string.valueof(objType) == 'SVMXC__Service_Order__c') {
newEvent.Work_Order__c = true;
}
else {
newEvent.Work_Order__c = false;
}
}
}
Twitter: www.twitter.com/kirkevonphilly
LinkedIn: http://www.linkedin.com/in/kirksteffke
Re: retreiving custom object type from what field
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-07-2012 02:59 PM
Thank you so much, this worked! Now to study this to figure out why this worked and the other didn't...
Re: retreiving custom object type from what field
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-10-2012 07:07 PM
In order to avoid govern limit, it should be like this,
Re: retreiving custom object type from what field
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-10-2012 07:10 PM
Sorry, Like this,

