• Kellan Scheiber
  • NEWBIE
  • 8 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 11
    Replies
public class MaintenanceRequestHelper {
    
    Public Static List<Case> oldCase = new List<Case>();
    Public Static List<Case> case1 = [select ID from Case Where status = 'Closed' and Type IN ('Repair', 'Routine Maintenance')];
    Public Static AggregateResult[] minCycleDay2 = [Select min(Equipment__r.Maintenance_Cycle__c) FROM Work_Part__c WHERE Equipment__r.Maintenance_Cycle__c != null
                                         AND Maintenance_Request__c IN: case1];
    
    
    public static void updateWorkOrders(List<Case> closedCase){        
        oldCase = closedCase;
   		List<Case> newCase = new List<Case>();
        
    		for (Case newCase2 : oldCase) {
            			newCase.add(new Case(type = 'Routine Maintenance',
                                status = 'New',
                                origin = 'Web',
                                Subject = null,
                                Date_Reported__c = date.today(),
                                Vehicle__c = newCase2.Vehicle__c,
                                Equipment__c = newCase2.Equipment__c,
                                Date_Due__c = cycleCalc2()));  
        }
       insert newCase;
       
       
     
      
    }
       
    private static Date cycleCalc2() {
        Integer minCycleNum = ((Decimal)minCycleDay2[0].get('expr0')).intValue();
        Date returnDate = Date.today().addDays(Integer.valueOf(minCycleNum));
        return returnDate;
        } 
        
    }
 
@isTest
private class MaintenanceRequestTest {

    @isTest static void TestWithCycleDays() {

        
             Account acct = new Account(Name= 'testAcct');
             insert acct;
             Contact cont = new Contact(LastName = 'contactTest', AccountID = acct.id, email = 'testcont@test.com');
             insert cont;
             Product2 prd1 = new Product2(Name = 'ProductTest1', Maintenance_Cycle__c = 2, Replacement_Part__c = true);
             insert prd1;
             Vehicle__c vhcl1 = new Vehicle__c(Name = 'VehicleTest1');
             insert vhcl1;
             Case MntRequest = new Case(description = 'test123',
                                Subject = 'Other',
                                type = 'Repair',
                                status = 'New',
                                origin = 'Web',
                                Date_Reported__c = date.today(),
                                Vehicle__c = vhcl1.id,
                                Equipment__c = prd1.id,
                                Date_Due__c = date.today(),
                                ContactId = cont.id,
                                AccountId = acct.id); 
        
        insert MntRequest;
        
        Work_Part__c wp1 = new Work_Part__c(Equipment__c = prd1.Id, Maintenance_Request__c = MntRequest.id);
        
        insert wp1;
        
        MntRequest.status = 'Closed';                                    
     
        update MntRequest;
        
        }
    
    @isTest static void testCaseBulkInsert(){
    List<Case> testCaseList = new List<Case>();
        For(Integer i=1 ;i<=300 ; i++) {

            Case MntRequest = new Case(
                                type = 'Routine Maintenance',
                                status = 'Closed',
                                origin = 'Web',
                                Subject = null,
                                Date_Reported__c = date.today(),
                                Vehicle__c = null,
                                Equipment__c = null,
                                Date_Due__c = date.today());
            testCaseList.add(MntRequest);
        }
            system.assertEquals(testCaseList.size(), 300);                   
    } 
    
}
 
trigger MaintenanceRequest on Case (after update, after insert) {
    
    Public List<Case> closedCase = new List<Case>();
    List<Case> caseA = [select ID, vehicle__c, equipment__c, date_due__c from Case Where Id IN :Trigger.new AND status = 'Closed' and Type IN ('Repair', 'Routine Maintenance')];
    for(Case a : caseA) {
        closedCase.add(a);
    }
           MaintenanceRequestHelper.updateWorkOrders(closedCase);  
}

 
public class BusSchedule {
	

    public Time [] schedule1;
    public String busName;
    public Map<String, Time[]> schedule2 = new Map<String, Time[]>();
    
    public void putSchedule(String busLine, Time [] schedule){
        
        busName = busLine;
        schedule2.put(busName, schedule);
        schedule1 = schedule2.get(busName);
             
        
    }

    public Time[] getSchedule(String busLine){
        Time[] bSched = new Time[]{};
        busName = busLine;
            if (busLine != null && schedule2.containsKey(busName)) {
            bSched = schedule1;
        } else {
            bSched.add(Time.newInstance(11,0,0,0));
            bSched.add(Time.newInstance(21,0,0,0));
       }
        
        return bSched;
    }
}

 
public class BusSchedule {
	
    
    
    public Time [] busSchedule;
        
       
    public void putSchedule(string busLine, Time[] schedule){
        Map<String, Time[]> schedule2 = new Map<String, Time[]>();
        schedule2.put(busLine, schedule);
        busSchedule = schedule2.get(busLine);
        }

    public Time[] getSchedule(string busLine){
        Time[] bSched = new Time[]{};
        
            if (busLine !=null) {
            bSched = busSchedule;
        } else {
            bSched.add(Time.newInstance(8,0,0,0));
            bSched.add(Time.newInstance(17,0,0,0));
       }
        
        return bSched;
    }
}

 
Dear all,

I am new to Salesforce. I created a developer environment, and a test Connected App, so that I can test making REST API calls.
The problem is that I cannot locate the consumer key and consumer secret for my app. I have read people had similar issues in the past, but their solution didn't work for me.
I attach a screenshot of my app details. According to the docs, this is where I should see consumer key and consumer secret.

User-added image

Thanks for the help!

Daniele 
public class MaintenanceRequestHelper {
    
    Public Static List<Case> oldCase = new List<Case>();
    Public Static List<Case> case1 = [select ID from Case Where status = 'Closed' and Type IN ('Repair', 'Routine Maintenance')];
    Public Static AggregateResult[] minCycleDay2 = [Select min(Equipment__r.Maintenance_Cycle__c) FROM Work_Part__c WHERE Equipment__r.Maintenance_Cycle__c != null
                                         AND Maintenance_Request__c IN: case1];
    
    
    public static void updateWorkOrders(List<Case> closedCase){        
        oldCase = closedCase;
   		List<Case> newCase = new List<Case>();
        
    		for (Case newCase2 : oldCase) {
            			newCase.add(new Case(type = 'Routine Maintenance',
                                status = 'New',
                                origin = 'Web',
                                Subject = null,
                                Date_Reported__c = date.today(),
                                Vehicle__c = newCase2.Vehicle__c,
                                Equipment__c = newCase2.Equipment__c,
                                Date_Due__c = cycleCalc2()));  
        }
       insert newCase;
       
       
     
      
    }
       
    private static Date cycleCalc2() {
        Integer minCycleNum = ((Decimal)minCycleDay2[0].get('expr0')).intValue();
        Date returnDate = Date.today().addDays(Integer.valueOf(minCycleNum));
        return returnDate;
        } 
        
    }
 
@isTest
private class MaintenanceRequestTest {

    @isTest static void TestWithCycleDays() {

        
             Account acct = new Account(Name= 'testAcct');
             insert acct;
             Contact cont = new Contact(LastName = 'contactTest', AccountID = acct.id, email = 'testcont@test.com');
             insert cont;
             Product2 prd1 = new Product2(Name = 'ProductTest1', Maintenance_Cycle__c = 2, Replacement_Part__c = true);
             insert prd1;
             Vehicle__c vhcl1 = new Vehicle__c(Name = 'VehicleTest1');
             insert vhcl1;
             Case MntRequest = new Case(description = 'test123',
                                Subject = 'Other',
                                type = 'Repair',
                                status = 'New',
                                origin = 'Web',
                                Date_Reported__c = date.today(),
                                Vehicle__c = vhcl1.id,
                                Equipment__c = prd1.id,
                                Date_Due__c = date.today(),
                                ContactId = cont.id,
                                AccountId = acct.id); 
        
        insert MntRequest;
        
        Work_Part__c wp1 = new Work_Part__c(Equipment__c = prd1.Id, Maintenance_Request__c = MntRequest.id);
        
        insert wp1;
        
        MntRequest.status = 'Closed';                                    
     
        update MntRequest;
        
        }
    
    @isTest static void testCaseBulkInsert(){
    List<Case> testCaseList = new List<Case>();
        For(Integer i=1 ;i<=300 ; i++) {

            Case MntRequest = new Case(
                                type = 'Routine Maintenance',
                                status = 'Closed',
                                origin = 'Web',
                                Subject = null,
                                Date_Reported__c = date.today(),
                                Vehicle__c = null,
                                Equipment__c = null,
                                Date_Due__c = date.today());
            testCaseList.add(MntRequest);
        }
            system.assertEquals(testCaseList.size(), 300);                   
    } 
    
}
 
trigger MaintenanceRequest on Case (after update, after insert) {
    
    Public List<Case> closedCase = new List<Case>();
    List<Case> caseA = [select ID, vehicle__c, equipment__c, date_due__c from Case Where Id IN :Trigger.new AND status = 'Closed' and Type IN ('Repair', 'Routine Maintenance')];
    for(Case a : caseA) {
        closedCase.add(a);
    }
           MaintenanceRequestHelper.updateWorkOrders(closedCase);  
}

 
public class BusSchedule {
	

    public Time [] schedule1;
    public String busName;
    public Map<String, Time[]> schedule2 = new Map<String, Time[]>();
    
    public void putSchedule(String busLine, Time [] schedule){
        
        busName = busLine;
        schedule2.put(busName, schedule);
        schedule1 = schedule2.get(busName);
             
        
    }

    public Time[] getSchedule(String busLine){
        Time[] bSched = new Time[]{};
        busName = busLine;
            if (busLine != null && schedule2.containsKey(busName)) {
            bSched = schedule1;
        } else {
            bSched.add(Time.newInstance(11,0,0,0));
            bSched.add(Time.newInstance(21,0,0,0));
       }
        
        return bSched;
    }
}

 
public class BusSchedule {
	
    
    
    public Time [] busSchedule;
        
       
    public void putSchedule(string busLine, Time[] schedule){
        Map<String, Time[]> schedule2 = new Map<String, Time[]>();
        schedule2.put(busLine, schedule);
        busSchedule = schedule2.get(busLine);
        }

    public Time[] getSchedule(string busLine){
        Time[] bSched = new Time[]{};
        
            if (busLine !=null) {
            bSched = busSchedule;
        } else {
            bSched.add(Time.newInstance(8,0,0,0));
            bSched.add(Time.newInstance(17,0,0,0));
       }
        
        return bSched;
    }
}

 
Hi all,

I have created a VF page with couple of reports. These reports are filtered, based on the selection available. For now assume the filter is just the Owner Name. All works well - I have used to show the report chart and have used cacheResults="false" to ensure the reports get refreshed on load. 

Now coming to the issue I am facing - when the user clicks on the report chart the report opens in existing window/tab. I want it to be opened in new tab/window. I have tried using onclick() and < a >tag, but no luck. 

Can anybody suggest if there is a way to do this? 

Here is the very sample code - without filters - just a simple page with report chart.
<apex:page>
     <a href='/00ON0000000LRNi' target='_blank'>
        <analytics:reportChart reportId="00ON0000000LRNi"></analytics:reportChart>
     </a>
</apex:page>

Interestingly the block becomes clickable and opens in new tab. Please note that including the filters in doesn't work for some reports. So I guess this is not the solution. Also note that there is no attributes available in reportChart to open this in new tab.

Please suggest.
Hi, I am having trouble with the "Attributes and Expressions" module from trailhead.

Here is the challenge:
Create a Lightning Component to display a single item for your packing list.
  • Create a component called campingListItem that displays the name (ui:outputText) and the three custom fields using the appropriate output components.
  • Add an attribute named 'item' for type Camping_Item__c.
I created an component named campingListItem and this is the code:
<aura:component >
    <aura:attribute name="item" type="<my_domain>__Camping_Item__c"/>
    
    <ui:outputText value="{!v.item.Name}"/>
    <ui:outputCheckbox value="{!v.item.<my_domain>__Packed__c}"/>
    <ui:outputCurrency  value="{!v.item.<my_domain>__Price__c}"/>
    <ui:outputNumber value="{!v.item.<my_domain>__Quantity__c}"/>
</aura:component>

The error that I am getting is: "Challenge Not yet complete... here's what's wrong: 
The packingListItem Lightning Component's attribute tag doesn't exist or its attributes are not set correctly."

With this, I tried to create another component, with the name "packingListItem", but It didn't work.

Can anyone help me?

Thanks,
Hello,

When I'm trying to Check Challenge, I receive this king of message : "The 'Number_Of_Contacts__c' field does not exist on the Account object."

I've double/triple checked if this field was present and ... it is.
I don't understand since all the test are goods.

Could you help me with this issue ?

Regards,
I've completed the challenge, it has 100% coverage. I've checked all the method names. The URL is valid. I've used Work Bench and curl to test and even tested with multiple Accounts with and without contacts.

I know on other challenges, punctionation was important.  What about the defination of the return? Are there expected names?

I built a class to hold Account ID & Name along with a List of Contact names and IDs. Is this my issue?  Anyone else have a challenge with this challenge?


Any help or hints will be appreciated.

Here are snippets of my code:

@RestResource(urlMapping='/Accounts/*/contacts')
global with sharing class AccountManager {

....

global class APIAccount {
        public ID Id;
        public String Name;
        List<APIContact> Contacts;

...

@HttpGet
    global static APIAccount getAccount() {
        RestRequest request = RestContext.request;
...
 

I'm trying to make some code that will add up the total value of a select field within a list i have created. I then want to subtract it from a set value. But i just keep getting an error. Can anyone please advise?

public with sharing class Total{

    Private integer allowance=252;
    public integer total_used;
    
    public Total(){
        total_used = [select sum (Hours_Used__c) FROM Holiday_Request__c WHERE Staff_Memeber__r.Name = 'Dan'];
    }
    
    Public Integer gettotal_used() {
        return total_used;
    }
    
    Public Integer getAvailable() {
        return 252-21;
    }
}

 

I'm new to salesforce.com, and looking for some guidance.

 

I need a way to insert a master record, and then its related detail records.

 

I initially though of using the following pseudo-code:

do

     insert master record

     do

           insert detail record and set foriegn key = recently inserted master record

      loop until end of detail records

loop until end of master records

 

This won't work because I will exceed governor limits. Any adivce on how best to proceed?