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
- :
- Problem with raising error in correct format. Ple...
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Problem with raising error in correct format. Please help???
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-15-2012 09:31 AM
trigger CaseCloseNoOpen on Case (Before update) { List<Id> caseIds = new List<Id>(); Id caseRecordTypeId = [SELECT Id FROM RecordType WHERE Name = 'PM Case' AND SObjectType = 'Case'].Id; Id TaskRecordTypeId = [SELECT Id FROM RecordType WHERE Name = 'PM Task' AND SObjectType = 'Task'].Id; for(Case c : Trigger.New) { if(c.RecordTypeId == caseRecordTypeId && (c.Status == 'Completed' || c.Status == 'Closed')) { caseIds.add(c.Id); } } for(Training_Information__c customobj : [Select Id, Status__c,Case__c From Training_Information__c Where Case__c in: caseIds]) { if(customobj.Status__c == 'Pending' || customobj.Status__c == 'Scheduled') { Trigger.newMap.get(customobj.Case__c).addError('Training has not been completed.'); } } for(Development_Request__c customobj : [Select Id, Stage__c,Case__c From Development_Request__c Where Case__c in: caseIds]) { if(customobj.Stage__c != 'Completed' && customobj.Stage__c != 'Cancelled DR/ VOID' && customobj.Stage__c != 'Draft') { Trigger.newMap.get(customobj.Case__c).addError('Th ere are open Development Request associated with this Case.'); } } for(Task T : [Select Id, Status, WhatId From Task Where WhatId in: caseIds]) { if(T.RecordTypeId == TaskRecordTypeId && (T.Status != 'Completed' && T.Status != 'Discarded')) { Trigger.newMap.get(T.WhatId).addError('There are still open PM Task on this Case.'); } } }
The .addError formatting for the Training Information and Development Request above work perfectly. I do not know what the issue is with the .addError issue with Tasks.....
for(Task T : [Select Id, Status, WhatId From Task Where WhatId in: caseIds]) { if(T.RecordTypeId == TaskRecordTypeId && (T.Status != 'Completed' && T.Status != 'Discarded')) { Trigger.newMap.get(T.WhatId).addError('There are still open PM Task on this Case.'); } }The above code is having issues with the line the .addError is on.
Error: Invalid Data.
Review all error messages below to correct your
data.
Apex trigger CaseCloseNoOpen caused an unexpected exception, contact
your administrator: CaseCloseNoOpen: execution of BeforeUpdate caused by:
System.SObjectException: SObject row was retrieved via SOQL without querying the
requested field: Task.RecordTypeId: Trigger.CaseCloseNoOpen: line 40, column 1
Any ideas?
Thank you,
Steve Laycock
Certified Administrator, Certified Advanced Administrator, Beginning Developer Certs. Currently
Solved! Go to Solution.
Re: Problem with raising error in correct format. Please help???
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-15-2012 09:36 AM
Forget it, I got it.... I didn't pull that field.
Thanks anyway.
Steve
Certified Administrator, Certified Advanced Administrator, Beginning Developer Certs. Currently

