You need to sign in to do that
Don't have an account?
Alex Waddell 12
Help Inserting Case from Apex Trigger
Hello everyone,
I am trying to write a trigger that checks to see if a case is open for an account. If there is no case open then i want it to open a case with certain criteria. I have gotten the code to not throw any errors right up into the end. I was wondering if anyone can help me polish off my last 2 lines of code so that the Case will be Inserted.
I am reveiving the following errors;
Variable does not exist: c
Variable does not exist: Case
I am trying to write a trigger that checks to see if a case is open for an account. If there is no case open then i want it to open a case with certain criteria. I have gotten the code to not throw any errors right up into the end. I was wondering if anyone can help me polish off my last 2 lines of code so that the Case will be Inserted.
trigger caseCheck on Account (After update) { for(Account myAccount : Trigger.new){ List<Case> openCase =[Select id From Case Where (Accountid = :myAccount.Id AND Status IN('New','Open')) ]; System.debug(openCase.size() + ' Open case(s) found'); if(openCase.isEmpty()){ Case c = new Case(); c.Accountid = myAccount.Id; c.Type = 'ICM'; c.Origin = 'SHIP'; c.Division__c = 'Case Management'; c.Status = 'New'; c.RecordTypeId = '01236000000OJLq'; } Case.add(c); Insert Case; } }
I am reveiving the following errors;
Variable does not exist: c
Variable does not exist: Case
All Answers
Here is the updated trigger:
trigger caseCheck on Account (After update) {
List<Case> casesToUpdate= new List<Case>();
for(Account myAccount : Trigger.new){
List<Case> openCase =[Select id
From Case
Where (Accountid = :myAccount.Id
AND
Status IN('New','Open')) ];
System.debug(openCase.size() + ' Open case(s) found');
if(openCase.isEmpty()){
Case c = new Case();
c.Accountid = myAccount.Id;
c.Type = 'ICM';
c.Origin = 'SHIP';
c.Division__c = 'Case Management';
c.Status = 'New';
c.RecordTypeId = '01236000000OJLq';
casesToUpdate.add(c);
}
Insert casesToUpdate;
}
}
*** Make sure there is a custom field named Division in cases.
Let me know if it worked for you.
wil,
Can i ask one last thing, what if i only wanted this trigger to fire when a field on the Account called "Fuzion_Status__c" is changed from "Initial Phone call" to anything else (It's a picklist field)? where would i add that in my code to make that work?
I have one last issue with this code, it seems like my SOQL querie isn't working properly because when i go to a test account that already has a case created that fits the criteria, it is still creating a new Case
Any ideas on why that might be?
Create a custom object ‘Case Solution’ with fields Case Description, Resolution.
- Create a custom field ‘Accept Solution’ as a checkbox on Case object.
- Create a custom field ‘Resolution’ as a text area on Case Object.
- Whenever a case has the status ‘Closed’ and its ‘Accept Solution’ checkbox is selected; a new Case Solution record should be created.
please share code for this problem statement .it helps alot..