• Admin Process
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies
How can I program the execution of a class 3 times a day at 30 minutes after the hour?

For example:

7:30 hrs
12:30 hrs
19:30 hrs

Please help me with the code completed I am begginer of code apex.
Hi forum,

I need you help, I have a trigger when  I run it send the following message error:
"System.LimitException: Too many SOQL queries: 101"
this is the code:

It is necessary that the product codes that are in the SAF266ORDOOpenOrders _ C object  that in the Product2 object in SAPDELETED _ c = ' 0 ' field, in the Product object must pass SAPDELETED _ c = ' 1 '



trigger SAF266ORDOOpenOrders_tgr on SAF266ORDOOpenOrders__c (after insert, after update) {

 if (Trigger.isAfter){

 for (SAF266ORDOOpenOrders__c a : Trigger.New)
         {
             List<Product2> GetProdInactive = [SELECT id, CODESKU__c, SAPDELETED__c  FROM Product2 WHERE CODESKU__c =  :a.PRODCODEO__c and SAPDELETED__c  = '0' ];
             
             for(Product2 prodActive : GetProdInactive)
                {
                  prodActive.SAPDELETED__c = '1';
                }
                update GetProdInactive;    
              
         }

]


Please help to check and modify it. Thanks in advance.

Regards.
Hi,

It is my first post in this Community, I have not experience in Apex Code, I am learning it.

We need to update two custom fields based on the fiscal calendar set in my organization.

We have the custom field INVOICEDATE _ C which contains the date on which the invoice was made, based on this date we have to look for the year and fiscal period that corresponds for each invoice.

The following code was made in the window execute Anonymous but sent the following error message.

Line: 20, Column: 1
Invalid loop variable type expected SObject was SAF263SPPISalesPaymentPromotionInvoice__c

CODE APEX

Map<Date, String> mapYear;
Map<Date, Integer> mapPeriod;
mapYear = new Map<Date, String>();
mapPeriod = new Map<Date, Integer>();

//List<SAF263SPPISalesPaymentPromotionInvoice__c> dINVOICEDATE = [SELECT ID, INVOICEDATE__c FROM SAF263SPPISalesPaymentPromotionInvoice__c WHERE FiscalYear__c = NULL AND     FiscalPeriod__c = NULL];
    
for(Period GetYearPeriod : [SELECT FiscalYearSettings.Name, Number, StartDate, EndDate 
            FROM Period where FiscalYearSettings.YearType = 'Custom' And Type = 'Month'])
{
    mapYear.put(GetYearPeriod.StartDate, GetYearPeriod.FiscalYearSettings.Name);
    mapPeriod.put(GetYearPeriod.StartDate, GetYearPeriod.Number);
}
System.debug('En SAF263 mapYear: ' + mapYear.KeySet());
System.debug('En SAF263 mapYear: ' + mapYear.Values());
System.debug('En SAF263 mapPeriod: ' + mapPeriod.KeySet());
System.debug('En SAF263 mapPeriod: ' + mapPeriod.Values());


for (SAF263SPPISalesPaymentPromotionInvoice__c objYearPeriod : Trigger.new)
{
    
    if(mapYear.containsKey(objYearPeriod.INVOICEDATE__c))
    {
        objYearPeriod.FiscalYear__c = mapYear.get(objYearPeriod.INVOICEDATE__c);
    }
    System.debug('EN CuotaUsuario_tgr objYearPeriod.FiscalYear__c: ' + objYearPeriod.FiscalYear__c);
    
    if(mapPeriod.containsKey(objYearPeriod.INVOICEDATE__c))
    {
        objYearPeriod.FiscalPeriod__c = mapPeriod.get(objYearPeriod.INVOICEDATE__c);
    }
    System.debug('EN CuotaUsuario_tgr objYearPeriod.FPeriod__c: ' + objYearPeriod.FPeriod__c);
}    

Could you help me? to know what I have wrong or if there is any other way to perform the update of the two custom fields.

I'll thank you very much for your support.
 
How can I program the execution of a class 3 times a day at 30 minutes after the hour?

For example:

7:30 hrs
12:30 hrs
19:30 hrs

Please help me with the code completed I am begginer of code apex.
Hi forum,

I need you help, I have a trigger when  I run it send the following message error:
"System.LimitException: Too many SOQL queries: 101"
this is the code:

It is necessary that the product codes that are in the SAF266ORDOOpenOrders _ C object  that in the Product2 object in SAPDELETED _ c = ' 0 ' field, in the Product object must pass SAPDELETED _ c = ' 1 '



trigger SAF266ORDOOpenOrders_tgr on SAF266ORDOOpenOrders__c (after insert, after update) {

 if (Trigger.isAfter){

 for (SAF266ORDOOpenOrders__c a : Trigger.New)
         {
             List<Product2> GetProdInactive = [SELECT id, CODESKU__c, SAPDELETED__c  FROM Product2 WHERE CODESKU__c =  :a.PRODCODEO__c and SAPDELETED__c  = '0' ];
             
             for(Product2 prodActive : GetProdInactive)
                {
                  prodActive.SAPDELETED__c = '1';
                }
                update GetProdInactive;    
              
         }

]


Please help to check and modify it. Thanks in advance.

Regards.
Hi,

It is my first post in this Community, I have not experience in Apex Code, I am learning it.

We need to update two custom fields based on the fiscal calendar set in my organization.

We have the custom field INVOICEDATE _ C which contains the date on which the invoice was made, based on this date we have to look for the year and fiscal period that corresponds for each invoice.

The following code was made in the window execute Anonymous but sent the following error message.

Line: 20, Column: 1
Invalid loop variable type expected SObject was SAF263SPPISalesPaymentPromotionInvoice__c

CODE APEX

Map<Date, String> mapYear;
Map<Date, Integer> mapPeriod;
mapYear = new Map<Date, String>();
mapPeriod = new Map<Date, Integer>();

//List<SAF263SPPISalesPaymentPromotionInvoice__c> dINVOICEDATE = [SELECT ID, INVOICEDATE__c FROM SAF263SPPISalesPaymentPromotionInvoice__c WHERE FiscalYear__c = NULL AND     FiscalPeriod__c = NULL];
    
for(Period GetYearPeriod : [SELECT FiscalYearSettings.Name, Number, StartDate, EndDate 
            FROM Period where FiscalYearSettings.YearType = 'Custom' And Type = 'Month'])
{
    mapYear.put(GetYearPeriod.StartDate, GetYearPeriod.FiscalYearSettings.Name);
    mapPeriod.put(GetYearPeriod.StartDate, GetYearPeriod.Number);
}
System.debug('En SAF263 mapYear: ' + mapYear.KeySet());
System.debug('En SAF263 mapYear: ' + mapYear.Values());
System.debug('En SAF263 mapPeriod: ' + mapPeriod.KeySet());
System.debug('En SAF263 mapPeriod: ' + mapPeriod.Values());


for (SAF263SPPISalesPaymentPromotionInvoice__c objYearPeriod : Trigger.new)
{
    
    if(mapYear.containsKey(objYearPeriod.INVOICEDATE__c))
    {
        objYearPeriod.FiscalYear__c = mapYear.get(objYearPeriod.INVOICEDATE__c);
    }
    System.debug('EN CuotaUsuario_tgr objYearPeriod.FiscalYear__c: ' + objYearPeriod.FiscalYear__c);
    
    if(mapPeriod.containsKey(objYearPeriod.INVOICEDATE__c))
    {
        objYearPeriod.FiscalPeriod__c = mapPeriod.get(objYearPeriod.INVOICEDATE__c);
    }
    System.debug('EN CuotaUsuario_tgr objYearPeriod.FPeriod__c: ' + objYearPeriod.FPeriod__c);
}    

Could you help me? to know what I have wrong or if there is any other way to perform the update of the two custom fields.

I'll thank you very much for your support.