You need to sign in to do that
Don't have an account?
Sree valli 12
I want help with this Inserting a new Maintenance Request of type 'Routine Maintenance' and then closing it did not create of a new Maintenance Request based upon the original record correctly.
Below is my code
public class MaintenanceRequestHelper {
public static void updateWorkOrders(List<case>ClosedCaseList){
// update workorders
list<case> insertCaseList = new list<case>();
for(Case c : ClosedCaseList)
{
Case newCase = new Case();
newCase.Type = 'Routine Maintenance';
newCase.Status = 'New';
newCase.Vehicle__c = c.Vehicle__c;
newCase.Subject = c.Subject;
newCase.Date_Reported__c = Date.today();
newCase.Date_Due__c = Date.today();
newCase.Equipment__c = c.Equipment__c;
insertCaseList.add(newCase);
}
if(insertCaseList.size()>0){
insert insertCaseList;
}
}
}
Trigger
trigger MaintenanceRequest on Case (before update, after update) {
List<case>ClosedCaseList = [SELECT Id, subject, Vehicle__c, vehicle__r.Name, equipment__c, type FROM Case WHERE status = 'closed'];
for(case c : Trigger.New){
if(c.type == 'Repair' || c.type =='Routine Maintenance'){
MaintenanceRequestHelper.updateWorkOrders(ClosedCaseList);
}
}
}
public class MaintenanceRequestHelper {
public static void updateWorkOrders(List<case>ClosedCaseList){
// update workorders
list<case> insertCaseList = new list<case>();
for(Case c : ClosedCaseList)
{
Case newCase = new Case();
newCase.Type = 'Routine Maintenance';
newCase.Status = 'New';
newCase.Vehicle__c = c.Vehicle__c;
newCase.Subject = c.Subject;
newCase.Date_Reported__c = Date.today();
newCase.Date_Due__c = Date.today();
newCase.Equipment__c = c.Equipment__c;
insertCaseList.add(newCase);
}
if(insertCaseList.size()>0){
insert insertCaseList;
}
}
}
Trigger
trigger MaintenanceRequest on Case (before update, after update) {
List<case>ClosedCaseList = [SELECT Id, subject, Vehicle__c, vehicle__r.Name, equipment__c, type FROM Case WHERE status = 'closed'];
for(case c : Trigger.New){
if(c.type == 'Repair' || c.type =='Routine Maintenance'){
MaintenanceRequestHelper.updateWorkOrders(ClosedCaseList);
}
}
}
Let us know if this will help you
Thamks for your reply
But still am facing the same issue. Can you explain me clearly what to do after renaming the standard objects. Iam thinking that after renaming i am doing mistake.So can you tell me the steps which you followed
Can you please let us know your requirement ?
Sure Amit .Please find the requirement
Automate record creation
Install the unmanaged package for the schema and stubs for Apex classes and triggers. Rename cases and products to match the HowWeRoll schema, and assign all profiles to the custom HowWeRoll page layouts for those objects. Use the included package content to automatically create a Routine Maintenance request every time a maintenance request of type Repair or Routine Maintenance is updated to Closed. Follow the specifications and naming conventions outlined in the business requirements
Then try to update your code like below
Let us know if this will work
And in maintenanceRequest class am facing some errors
public class MaintenanceRequestHelper {
public static void updateWorkOrders(List<case> ListOfCases){
List<Product2> equipments = [select id,Maintenance_Cycle__c from product2];
map<id,Decimal> productmap = new Map<id,Decimal>();
for(product2 p : equipments){
productmap.put(p.Id, p.Maintenance_Cycle__c);
}
List<Case> newCasesToInsert = new List<case>();
for(case oldCase : ListOfCases){
Case newCase = new Case();
if(oldCase.Status == 'Closed' && (oldCase.Type =='Repair' || oldCase.Type == 'Routine Maintenance')){
system.debug('Status Closed');
newCase.Equipment__c = oldcase.Equipment__c;
newCase.Type ='Routine Maintenance';
newCase.Status = 'New';
newCase.Vehicle__c = oldcase.Vehicle__c;
newCase.Date_Reported__c = system.today();
newCase.Subject = 'Check Up';
newCasesToInsert.add(newCase);
}
}
insert newCasesToInsert;
}
}
ERROR at Row:1:Column:11
No such column 'Maintenance_Cycle__c' on entity 'Product2'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.
Variable does not exist: Equipment__c
please assist on this issue
If below code is not in use then please remove same