• CLites
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 3
    Replies

Hi folks,

Running into an error and not quite sure why. I am trying to schedule a cron job for the last day of the month. My cron expression is:

0 30 22 L * ?

Which should fire at 10:30 PM on the last day of the month, for every month, specifying no day of week as far as I can tell from the documentation:

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_scheduler.htm

However, I am getting the error:

"Support for specifying 'L' and 'LW' with other days of the month is not implemented"

I was getting this error before when I WAS trying to specify some days of the month in addition to the last day, but now I am stumped as to why I am hitting this when I am only specifying "L" in the Day of Month portion of the cron expression. Any ideas would be appreciated.

Thanks,

Chris

  • September 21, 2021
  • Like
  • 0
Hi,

From everything I have seen, if I want to do a REST based callout or schedule or abort a scheduled job programatically, there is no good way to bulkify that process. I realize that batch APEX could be used, but from what I have seen, there is no way to run system.schedule or system.abort using a list as an argument or run something like:
 
HttpRequest req = new HttpRequest();
            req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID()); 
            req.setHeader('Content-Type', 'application/json');
            req.setEndpoint(endpointUrl);
            req.setMethod('GET');
            Http h = new Http();
            HttpResponse res = new HttpResponse();
            try{
                res = h.send(req);
            }
            catch(System.CalloutException e){
            	calloutError1 = e.getMessage();
            }

using a list. So if I need to do something like this multiple times due to updates on multiple records, the best way I have seen to deal with it is to do the scheduled job or callout in a loop with an iterator that only allows a maximum number of iterations and then does exception handling if it goes over that number. 

Am I missing anything here? Is there any way to bulkify these sorts of things or any best practices about this type of situation?

Thanks,

Chris
 
  • August 25, 2021
  • Like
  • 0
Hi,

I am running in to an issue that I was hoping someone might have some insight in to. I have a method in a class triggered by contact insert or update. This method will check to see if a contact has a box checked and if it does, it will create a correspondinng user record with the ContactId set to the Id of the contact that was being created/edited. 

The issue that I am having is with the test code coverage. I am getting the error "UNKNOWN_EXCEPTION, portal account owner must have a role". Now I have seen the workaround for this by creating a user with a role and then putting the community user creation code inside System.runAs context with the user you created. This works for community users created in the test class itself, however, if the test class is not actually creating the community user directly, but rather by creating a contact which triggers the class mentioned above to create a community user, it fails with the same role error mentioned above. 

In all my searching, all I have found is a solution to the first issue where the community user is being created in the test class itself. I have not found any info for resolving it if the test class it then calling out to another class that creates the user. Any info on how I might be able to resolve would be greatly appreciated.

Thanks,

Chris
 
  • April 13, 2020
  • Like
  • 0

Hi,

 

I am a bit stuck on a problem and I was hoping that someone might be able to help. I am creating an inline visualforce page with a page block table. the table displays different images on each row when a user clicks on the image but when the table refreshes, the rows in the table reorder themselves. the image changes correctly but I need the order of the rows to remain constant. I am really stuck as to trying to figure out why these rows are reordering themselves. any help would be greatly appriciated. the page and controller are below.

 

<apex:page standardController="Project__c" extensions="ProjectRequirementLinkController">

     <apex:form >
     	<apex:actionFunction action="{!methodOne}" name="methodOneInJavascript" rerender="selectLineItemsTable">
	        <apex:param name="firstParam" assignTo="{!testId}" value="" />
	    </apex:actionFunction>
	    			    
		<apex:pageBlock >
			<apex:pageBlockButtons >
			<div>
			<apex:commandLink action="{!CreateRequirements}" target="_top" value="Link/Unlink Requirements" styleClass="btn" oncomplete="window.top.location='/{!Project__c.id}'; return false"/>
			<apex:commandLink action="{!URLFOR($Action.Requirement__c.New)}" target="_top" value="New Requirement" styleClass="btn" type="image/png"/>
			</div>
			</apex:pageBlockButtons>
			<apex:pageBlockSection title="Requirements for Account: {!Project__c.Account__r.Name}" columns="1">
		  		<apex:pageBlockTable id="selectLineItemsTable" value="{!linkedRequirements}"  var="item" width="95%">
		    		
		    		
		    		<apex:column >
		      			<div>
					    <apex:outputPanel onclick="methodOneInJavascript('{!item.requirement.Id}')" > 
					        <apex:image id="added" value="{!URLFOR($Resource.Checkboxes, item.picture)}"/> 
					    </apex:outputPanel>
       					 </div>
		    		</apex:column>
       					
       					
		    		<apex:column >
		      			<apex:facet name="header">Requirement Name</apex:facet>
		      			<apex:outputLink value="/{!item.requirement}" target="_blank">{!item.requirement.Name}</apex:outputLink>
		    		</apex:column>
		    		
		    		<apex:column >
		      			<apex:facet name="header">Requirement Subject</apex:facet>
		      			<apex:outputText value="{!item.requirement.Subject__c}"/>
		    		</apex:column>
		    		
		    		<apex:column >
		      			<apex:facet name="header">Requirement's Project</apex:facet>
		      			<apex:outputLink value="/{!item.requirement.Project__c}" target="_blank">{!item.requirement.Project__r.Name}</apex:outputLink>
		    		</apex:column>
		    		
		  		</apex:pageBlockTable>
			</apex:pageBlockSection>			
		</apex:pageBlock>
	</apex:form>
	
</apex:page>

 

 

public with sharing class ProjectRequirementLinkController {


/*Initialization*/
    public ProjectRequirementLinkController(ApexPages.StandardController controller) {
    	
    	projId=controller.getId();
    	
        proj2 = [SELECT Id, Name, Account__r.Id, Account__r.Name
				FROM Project__c 
        		WHERE Project__c.Id =: projId limit 1];		
        
       	loadRequirements();
       	
    }
    
/*End Initialization*/

/*Properties*/
 
    private final Project__c proj2;
    public Map<Id, SelectAddDeleteSObject> linkedRequirements2 {get; set;}
    public List<SelectAddDeleteSObject> linkedRequirements {
    	get{return linkedRequirements2.values();}
    	set;}
    private Id projId {get; set;}
     
    
/*End Properties*/

/*Action Methods*/


	private SelectableSObject SSO;
	public Id testId {get; set;}
	public String state = 'Checkboxes/SF_Checkbox_Unchecked.jpg';
	
    public void methodOne() {
    	if(linkedRequirements2.get(testId).status == SelectAddDeleteSObject.State.selected)
        {
        	linkedRequirements2.get(testId).status = SelectAddDeleteSObject.State.deleted;
        	linkedRequirements2.get(testId).picture = 'Checkboxes/SF_Checkbox_Red_X.jpg';
        }
        else if(linkedRequirements2.get(testId).status == SelectAddDeleteSObject.State.deleted)
        {
        	linkedRequirements2.get(testId).status = SelectAddDeleteSObject.State.selected;
        	linkedRequirements2.get(testId).picture = 'Checkboxes/SF_Checkbox_Checked.jpg';
        }
        else if(linkedRequirements2.get(testId).status == SelectAddDeleteSObject.State.unselected)
        {
        	linkedRequirements2.get(testId).status = SelectAddDeleteSObject.State.added;
        	linkedRequirements2.get(testId).picture = 'Checkboxes/SF_Checkbox_Checked_Green.jpg';
        }
        else if(linkedRequirements2.get(testId).status == SelectAddDeleteSObject.State.added)
        {
        	linkedRequirements2.get(testId).status = SelectAddDeleteSObject.State.unselected;
        	linkedRequirements2.get(testId).picture = 'Checkboxes/SF_Checkbox_Unchecked.jpg';
        }

    }
    
    
    
    
    public PageReference CreateRequirements()
    {
    	try
    	{
	    	List<Requirement__c> toUpdate = new List<Requirement__c>();
	    	for(SelectAddDeleteSObject currentRequirement : linkedRequirements2.values()){
	    		
	    		if(currentRequirement.status == SelectAddDeleteSObject.State.added){
	    			
	    			currentRequirement.requirement.Project__c = projId;
	    			toUpdate.add(currentRequirement.requirement);
	    		}
	    		else if(currentRequirement.status == SelectAddDeleteSObject.State.deleted){	
	    			currentRequirement.requirement.Project__c = null;
	    			toUpdate.add(currentRequirement.requirement);
	    		}
	    	}
	    	update toUpdate;
    	}
    	catch (DmlException e)
    	{
    		system.debug(LoggingLevel.ERROR, e.getMessage());
    	}
    	loadRequirements();
    	return null;
    }
/*End Action Methods*/

/*Helper Methods*/
	public void loadRequirements() {
		linkedRequirements2 = new Map<Id, SelectAddDeleteSObject>();
		linkedRequirements = new List<SelectAddDeleteSObject>();
		
		for(Requirement__c current_req : [SELECT Id, Name, Subject__c, Project__c, Project__r.Name
	        	  							FROM Requirement__c
	        	  							WHERE (Requirement__c.Account__r.Id =: proj2.Account__r.Id)
	        	  							])
		{
		    SelectAddDeleteSObject SAD_req = new SelectAddDeleteSObject(current_req);
		    
		    if(current_req.Project__c == projId){
		    	SAD_req.status = SelectAddDeleteSObject.State.selected;
		    	SAD_req.picture = 'Checkboxes/SF_Checkbox_Checked.jpg';
		    } 
		    linkedRequirements2.put(current_req.Id, SAD_req);
		}  
	}
/*End Helper Methods*/   






}

 

 

Thanks,

 

Chris

 

  • November 14, 2013
  • Like
  • 0

Hi folks,

Running into an error and not quite sure why. I am trying to schedule a cron job for the last day of the month. My cron expression is:

0 30 22 L * ?

Which should fire at 10:30 PM on the last day of the month, for every month, specifying no day of week as far as I can tell from the documentation:

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_scheduler.htm

However, I am getting the error:

"Support for specifying 'L' and 'LW' with other days of the month is not implemented"

I was getting this error before when I WAS trying to specify some days of the month in addition to the last day, but now I am stumped as to why I am hitting this when I am only specifying "L" in the Day of Month portion of the cron expression. Any ideas would be appreciated.

Thanks,

Chris

  • September 21, 2021
  • Like
  • 0
Hi,

From everything I have seen, if I want to do a REST based callout or schedule or abort a scheduled job programatically, there is no good way to bulkify that process. I realize that batch APEX could be used, but from what I have seen, there is no way to run system.schedule or system.abort using a list as an argument or run something like:
 
HttpRequest req = new HttpRequest();
            req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID()); 
            req.setHeader('Content-Type', 'application/json');
            req.setEndpoint(endpointUrl);
            req.setMethod('GET');
            Http h = new Http();
            HttpResponse res = new HttpResponse();
            try{
                res = h.send(req);
            }
            catch(System.CalloutException e){
            	calloutError1 = e.getMessage();
            }

using a list. So if I need to do something like this multiple times due to updates on multiple records, the best way I have seen to deal with it is to do the scheduled job or callout in a loop with an iterator that only allows a maximum number of iterations and then does exception handling if it goes over that number. 

Am I missing anything here? Is there any way to bulkify these sorts of things or any best practices about this type of situation?

Thanks,

Chris
 
  • August 25, 2021
  • Like
  • 0
Hi,

I am running in to an issue that I was hoping someone might have some insight in to. I have a method in a class triggered by contact insert or update. This method will check to see if a contact has a box checked and if it does, it will create a correspondinng user record with the ContactId set to the Id of the contact that was being created/edited. 

The issue that I am having is with the test code coverage. I am getting the error "UNKNOWN_EXCEPTION, portal account owner must have a role". Now I have seen the workaround for this by creating a user with a role and then putting the community user creation code inside System.runAs context with the user you created. This works for community users created in the test class itself, however, if the test class is not actually creating the community user directly, but rather by creating a contact which triggers the class mentioned above to create a community user, it fails with the same role error mentioned above. 

In all my searching, all I have found is a solution to the first issue where the community user is being created in the test class itself. I have not found any info for resolving it if the test class it then calling out to another class that creates the user. Any info on how I might be able to resolve would be greatly appreciated.

Thanks,

Chris
 
  • April 13, 2020
  • Like
  • 0