• Patrick Foy
  • NEWBIE
  • 20 Points
  • Member since 2017
  • Developer/ Admin
  • Hotsy cleaning Systems Iowa

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 20
    Replies
I am trying to execute a SOQL query that may return a list. If list is null I want to set default value. I am new to apex so not sure if this is correct.
 
// SET USERNAME STRING
string username = '%'+UserInfo.getFirstName()+'%'; 
//SET DEFAULT PRODUCTid
Id ProductID = '01t46000000nPO0AAM'; 
//MAP  IDMAPPRODUCT2
Map<Id> idmapproduct2 = new Map<Id>([Select Id FROM Product2 WHERE ProductCode like '%LAB %' AND ProductCode like:username]); system.debug(idmapproduct2); 
//CHECK IF MAP IS NULL AND IF NOT SET IT TO PRODUCT ID
if(idmapproduct2 != null)
  {ProductID = idmapproduct2;}

 
I'm just learning APEX and I would appreciate it if someone would look this over. It is supposed to create a new work order line(child) once a button is clicked and updates a check box to = true on the parent. The work order line needs to have Product Code( formula uses product id based on current user, i hope), Status,Parent W/O ID, Start Time (Date and Time). Once I get this figured out I think I can easily program the trigger for the "check out" button.


  For( OptimaPro__Work_Order_Line__c   newWorkOrderLine Trigger.new){
                  if (myVariable_current.Check_In__c = true) {
RecordTypeId = ‘01246000000Q2t9A’;
OptimaPro__MOBSVC_Start_Date_and_Time__c = datetime.now();
OptimaPro__MOBSVC_work_Order__c = // how do I get current parent record?//
 OptimaPro__MOBSVC_Line_Status__c = ‘Open’;   //pick list//
 
//next section picks product code.id based on current user//
IF($User.FirstName = "Cory"){ OptimaPro__MOBSVC_Product__c = '01t46000000nQVKAA2',
IF($User.FirstName = "Jim",){' OptimaPro__MOBSVC_Product__c = 01t46000000nRJFAA2';}
IF($User.FirstName = "Zach") {OptimaPro__MOBSVC_Product__c = '01t46000000nPA2AAM';}
Else [OptimaPro__MOBSVC_Product__c = '01t46000000nPO0AAM';}

             }
}


               
 
I have a custom object called Service Contract. The object contains the following fields Effective Date (date) and Calls Per Year (number) End Contract (checkbox). 

When a user sets up the service contract for a customers machine the customer will decide how many times per year they want the machine serviced.

For example: Starting April 1,2017 I want my machine serviced 2 times per year.
I need the event/reminder to tell the user on October 1 and April 1 to create a work order untill End Contract is checked. 
I have no idea how to work this out. My expirence with Apex is null, I do have other programing expirience and want to learn how to do this just really need some help. 

I had been advised previously to create a custom setting which I have but do not know how to proceed. 
I am trying to execute a SOQL query that may return a list. If list is null I want to set default value. I am new to apex so not sure if this is correct.
 
// SET USERNAME STRING
string username = '%'+UserInfo.getFirstName()+'%'; 
//SET DEFAULT PRODUCTid
Id ProductID = '01t46000000nPO0AAM'; 
//MAP  IDMAPPRODUCT2
Map<Id> idmapproduct2 = new Map<Id>([Select Id FROM Product2 WHERE ProductCode like '%LAB %' AND ProductCode like:username]); system.debug(idmapproduct2); 
//CHECK IF MAP IS NULL AND IF NOT SET IT TO PRODUCT ID
if(idmapproduct2 != null)
  {ProductID = idmapproduct2;}

 
I'm just learning APEX and I would appreciate it if someone would look this over. It is supposed to create a new work order line(child) once a button is clicked and updates a check box to = true on the parent. The work order line needs to have Product Code( formula uses product id based on current user, i hope), Status,Parent W/O ID, Start Time (Date and Time). Once I get this figured out I think I can easily program the trigger for the "check out" button.


  For( OptimaPro__Work_Order_Line__c   newWorkOrderLine Trigger.new){
                  if (myVariable_current.Check_In__c = true) {
RecordTypeId = ‘01246000000Q2t9A’;
OptimaPro__MOBSVC_Start_Date_and_Time__c = datetime.now();
OptimaPro__MOBSVC_work_Order__c = // how do I get current parent record?//
 OptimaPro__MOBSVC_Line_Status__c = ‘Open’;   //pick list//
 
//next section picks product code.id based on current user//
IF($User.FirstName = "Cory"){ OptimaPro__MOBSVC_Product__c = '01t46000000nQVKAA2',
IF($User.FirstName = "Jim",){' OptimaPro__MOBSVC_Product__c = 01t46000000nRJFAA2';}
IF($User.FirstName = "Zach") {OptimaPro__MOBSVC_Product__c = '01t46000000nPA2AAM';}
Else [OptimaPro__MOBSVC_Product__c = '01t46000000nPO0AAM';}

             }
}


               
 
I have a custom object called Service Contract. The object contains the following fields Effective Date (date) and Calls Per Year (number) End Contract (checkbox). 

When a user sets up the service contract for a customers machine the customer will decide how many times per year they want the machine serviced.

For example: Starting April 1,2017 I want my machine serviced 2 times per year.
I need the event/reminder to tell the user on October 1 and April 1 to create a work order untill End Contract is checked. 
I have no idea how to work this out. My expirence with Apex is null, I do have other programing expirience and want to learn how to do this just really need some help. 

I had been advised previously to create a custom setting which I have but do not know how to proceed.