• Dchris222
  • NEWBIE
  • 24 Points
  • Member since 2011

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 18
    Questions
  • 35
    Replies

I have a VF page that is being populated via a standard controller and a extension. It works just fine in the sandbox, but in production I am recieving the following error: " PDF generation failed. Check the page markup is valid. "

 

Any input on why this is happing would be appreciated:

 

edit: I have determined it has to do with the public case comments rendered. It works if I just have the comment body rendered as public, but if I add the created date as well then the error arises.

 

Page:

 

<apex:page renderas="pdf" standardController="Case" extensions="PDFServiceExtension">
<apex:stylesheet value="{!$Resource.PDFHeaderFooter}"/>
<center>
    <apex:image url="{!$Resource.MIRLetterhead}" width="700" height="97" />
</center>
    <apex:panelGrid columns="2" id="theGrid">
        <apex:outputLabel value="Case #: " for="Case#" style="font-weight: bold"/>
        <apex:outputField value="{!Case.CaseNumber}" id="CaNumber"/>
        
        <apex:outputLabel value="Date & Time Opened: " for="CaseOpen" style="font-weight: bold"/>
        <apex:outputField value="{!Case.CreatedDate}" id="CaseOpen"/>
        
        <apex:outputLabel value="Date & Time Closed: " for="CaseClosed" style="font-weight: bold"/>
        <apex:outputField value="{!Case.ClosedDate}" id="CaseClosed"/>
        
        <apex:outputLabel value="Status:" for="CaseStatus: " style="font-weight: bold"/>
        <apex:outputField value="{!Case.Status}" id="CaseStatus"/>
        
        <apex:outputLabel value="Type:" for="CaseType: " style="font-weight: bold"/>
        <apex:outputField value="{!Case.Type}" id="CaseType"/>
        
        <apex:outputLabel value="Account: " for="Name" style="font-weight: bold"/>
        <apex:outputField value="{!Case.Account.name}" id="Name"/>
        
        <apex:outputLabel value="Subject: " for="Case#" style="font-weight: bold"/>
        <apex:outputField value="{!Case.Subject}" id="CaSubj"/>
        
        <apex:outputLabel value="Description: " for="Case#" style="font-weight: bold"/>
        <apex:outputField value="{!Case.Description}" id="CaDesc"/>

    </apex:panelGrid>
    
    <br></br>
    <apex:outputLabel value="Service Activities:" for="Name" style="font-weight: bold"/>
    <apex:dataTable value="{!SA}" var="LIs" width="50%" border="1px" >
		<apex:column headerValue="Service Engineer" value="{!LIs.Contact__c}" headerClass="tableHead"/>
		<apex:column headerValue="Total Hours" value="{!LIs.Total_Hours__c}"/>
		<apex:column headerValue="Date Performed" value="{!LIs.Date_Performed__c}"/>
	</apex:dataTable>
	
	<br></br>
    <apex:outputLabel value="Case Comments:" for="Name2" style="font-weight: bold"/> 

    <apex:pageBlock >
        <apex:pageBlockTable value="{!case.casecomments}" var="c" width="50%" border="1px" >
            <apex:column value="{!c.commentbody}" rendered="{!c.isPublished = true}"/>
            <apex:column value="{!c.createddate}" rendered="{!c.isPublished = true}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>   
</apex:page>

 Extension:

public with sharing class PDFServiceExtension {
	
	private final Case Ca;
  
	public PDFServiceExtension(ApexPages.StandardController CaseController) {
		this.Ca = (Case)CaseController.getRecord();
	}
  
	//For Testing Purposes  
	public PDFServiceExtension(Case tcase) {
        this.Ca = tcase;
	}
  
  // Create a list of type Suite__c and call the query method
    public List<Service_Activity__c> activityRecords() {
         return (List<Service_Activity__c>) activityRecords.getRecords();
    }
    
  // Query the db for the list of Suite__c records to use on the vf page and return a list
    public ApexPages.StandardSetController activityRecords{
      get {
            if(activityRecords == null) {
                activityRecords = new ApexPages.StandardSetController(Database.getQueryLocator([Select s.Contact__c, s.Case__c, s.Total_Hours__c, s.Description__c, s.Date_Performed__c  from Service_Activity__c s Where s.Case__c =:ApexPages.currentPage().getParameters().get('id')]));
            }
            return activityRecords;
        }
        set;
    }
    
    public List<Service_Activity__c> getSA() {
        return (List<Service_Activity__c>) activityRecords.getRecords();
    }
}

 

Run Failures:
  OppPoliceSchedulerTestClass.testOppPoliceScheduler System.DmlException: Update failed. First exception on row 1000 with id 0063000000kF2uuAAC; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, oppUpdateInventoryInfo: execution of AfterUpdate

caused by: System.LimitException: Too many script statements: 200001

Trigger.oppUpdateInventoryInfo: line 18, column 4: []


 

I don't understand how to fix this error. Do I need to go through this code that has allready been deployed and eliminate scripts?

How do you querry a reference/lookup field and then read what that ID is and based on that ID, populate another reference/lookup field. I know what the values of both Id's are I am just having trouble getting it to insert and read correctly.

 

This is the code I am having problems with.

 

 

Equip2 = [SELECT Name, Modality__c, Modality_Name__c, CT_Models__c, CT_Modality_Picklist__c FROM Equipment__c WHERE Modality__c != NULL ORDER BY Name ASC];  

 

for(Equipment__c Eqp : Equip2)    {
        
            
                if(Eqp.Modality__c =  'a0a30000004XQiKAAW') {          // If lookup field modality = this id, then insert below
                
                      Eqp.Modality_Name__c = 'a0a30000004XQiKAAW';    //Populate the other lookup field
                      Eqp.CT_Modality_Picklist__c = 'CT Unknown';    // Specify Picklist Value
                      Eqp.CT_Models__c = 'Unknown';     // Specify Picklist Value
                }

             ....

             .....

             ....

               else  {
                    
                      system.debug('No modalities match');
                         
                }                       
        }    
           insert Equip2;

             ....

             .....

             ....

 

I am looking to create a report to combine inventory with product assignment along with all sale opportunities, leasing opportunities and assets. I created a Custom Report Type with the following object relationship:

 

Products (A)
with or without related records from Inventory (B)
with or without related records from Opportunities (C)

with or without related records from Assets (D)

 

The problem is when I run the report I am not returning any Assets for my Products and I can't figure out why. Any help would be appreciated!

 

Chris

I am recieving the following error when I try to deploy my apex class and test class: visualforce CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, opptySwarm: execution of AfterUpdate.  Is this because I am trying to update too many field at once?? Or some other issue? What is my best option to fix this?

 

Thank you in advance, I am new to Salesforce development.

 

Chris


Apex Class:

 

 

global class OppPoliceController {
 
  public void Opportunity1() {
  	
  	 List<Opportunity> Opptys2 = [SELECT CreatedDate, StageName, LastActivityDate, Activity_Status__c, (SELECT CreatedDate FROM Feeds ORDER BY CreatedDate DESC limit 1), (SELECT Status FROM Tasks) FROM Opportunity WHERE StageName != 'Closed Won' AND StageName != 'Closed Lost' AND StageName != 'Closed Other' AND StageName != 'Qualified Lost' AND StageName != 'Prospect' AND CloseDate != Today ORDER BY LastActivityDate DESC];
 
	
        for(Opportunity Op : Opptys2){
        
        datetime d = Date.today();  //Current Date Formated
        datetime LastActivityDate = Op.LastActivityDate; //Last Activity Date in datetimeformat
        
        datetime CreatedDate1;
        if(Op.Feeds != Null && !Op.Feeds.isEmpty()) {
        	
           CreatedDate1 = Op.Feeds[0].CreatedDate;  //Created Date in datetime format 	
          
        }
        else {
        	system.debug('<--------------Error CreatedDate for Feeds is Null---------------->');
        	CreatedDate1 = Op.CreatedDate;
        	
        }
         	 
        string Status1;
        if(Op.Tasks != Null && !Op.Tasks.isEmpty())  {
        	
        	Status1 = Op.Tasks[0].Status;
        	
        }
        else {
        	system.debug('<----------------ERROR Staus for Tasks is Null-------------------->');
        	Status1 = null;
        	
        }
        

        System.debug('This is the created date: ' + CreatedDate1);
        System.debug('This is the status: ' + Status1);
        System.debug('This is todays date: ' + d); 
        
            if(LastActivityDate == Null) { 
            	
            	if(Status1 == 'In Progress' || Status1 == 'Waiting on someone else' || Status1 == 'Deferred') {
            		
            		 Op.Activity_Status__c = 'Low'; 
            		 	 
            	}
            	 else if(Status1 == null || Status1 == 'Not Started' || d > CreatedDate1.addDays(14)) {
            	
            	 Op.Activity_Status__c = 'High'; 
            	     	 
            	}
            	 else if(d >= CreatedDate1.addDays(7) && d < CreatedDate1.addDays(14)) {
         
                 Op.Activity_Status__c = 'Medium'; 
               
                  }
                  else {
                  	
                  	 Op.Activity_Status__c = 'error';  
                  }
                          	
            }
           
            else if(d > LastActivityDate.addDays(14) || d > CreatedDate1.addDays(14)) {
              
              Op.Activity_Status__c = 'High';
              
            }
            
            else if((d >= CreatedDate1.addDays(7) && d < CreatedDate1.addDays(14))
            	|| (d >= LastActivityDate.addDays(7) && d < LastActivityDate.addDays(14)) ) {
         
               Op.Activity_Status__c = 'Medium'; 
               
            }
              
            else if(d < LastActivityDate.addDays(7) || d < CreatedDate1.addDays(7) || Status1 == 'In Progress' || Status1 == 'Waiting on someone else' || Status1 == 'Deferred') {
            	
                Op.Activity_Status__c = 'Low';
                
            }
            	
            else {
            
                Op.Activity_Status__c = 'Error';
                   
            }
        }    
           update Opptys2;
  
  }   
}

 

 

 

Apex Test Class

 

 

@isTest
private class OppPoliceTestClass {

    static testMethod void testOpportunity1() {
        
      date d = Date.today() + 7;
      
      System.debug('The close date is: ' + d);
        
      Opportunity Opp = new Opportunity();
      Opp.name = 'Op-Test9';
      Opp.StageName = 'Open';
      Opp.CloseDate = d;
   
      insert Opp;
      
      Task t = new Task();
      t.Subject='Send out Notice';
      t.Status = 'Not Started';
      t.Priority = 'Normal';
      t.WhatId = Opp.id;
      
      insert t;
      
      System.debug('This is the Opp id: ' + Opp.id);
      System.debug('This is the WhatId: ' + t.WhatId);
      
      OppPoliceController myClass = new OppPoliceController();
      myClass.Opportunity1();
      
      List<Opportunity> OppStatus = [select o.name, o.Activity_Status__c from Opportunity o WHERE o.name= 'Op-Test9' LIMIT 1];
      
      string OpName = OppStatus[0].name;
      System.debug('The name of the Opp is ' + OpName);    
      
      for(Opportunity Op2 : OppStatus){
          
          System.assertEquals('High',Op2.Activity_Status__c);
          System.debug('The Activity Status for the Test is: ' + Op2.Activity_Status__c);
          
      }                              
   }
}



 

 

 

 

This is my first salesforce project endeveour and I am struggling to get it done on time. I have tested my apex class and it works as expected, but now I need to create test methods so that I can deploy it into Salesforce but I am struggling to grasp what I need to do.  I have read the documentation, but not still am not sure how to best setup this up. I would really appreciate it if you could help a beginner out!

 

Thanks in advance!

 

Here is my apex class:

 

 

global class OppPoliceController {
 
  public void Opportunity1() {
 
     List<Opportunity> Opptys2 = [SELECT name, LastActivityDate, Activity_Status__c, StageName, (SELECT CreatedDate FROM Feeds ORDER BY CreatedDate DESC limit 1), (SELECT Status FROM Tasks) FROM Opportunity WHERE StageName != 'Closed Won' AND StageName != 'Closed Lost' ORDER BY LastActivityDate DESC];
 
	
        for(Opportunity Op : Opptys2){
        
        datetime LastActivityDate = Op.LastActivityDate; //Last Activity Date in datetimeformat
        datetime CreatedDate = null;
       
        datetime CreatedDate1 = Op.Feeds[0].CreatedDate;  //Created Date in datetime format 
        datetime d = Date.today();  //Current Date Formated
        
        string status1 = '';
        
        if(Op.Tasks != Null && !Op.Tasks.isEmpty())  {
        	
        	 Status1 = Op.Tasks[0].Status;
        }
        else {
        	
        	system.debug('error');
        }
        	
        System.debug('This is the created date: ' + CreatedDate1);
        System.debug('This is the status: ' + Status1);
        System.debug('This is todays date: ' + d); 
        
            if(LastActivityDate == Null) { 
            	
            	if(d < CreatedDate1.addDays(7) || Status1 == 'In Progress' || Status1 == 'Waiting on someone else' || Status1 == 'Deferred') {
            		
            		 Op.Activity_Status__c = 'Low'; //low
            		 	 
            	}
            	 else if(Status1 == 'Not Started' && d > CreatedDate1.addDays(14)) {
            	
            	 Op.Activity_Status__c = 'High'; //High
            	     	 
            	}
            	 else if(d >= CreatedDate1.addDays(7) && d < CreatedDate1.addDays(14)) {
         
                 Op.Activity_Status__c = 'Medium'; //Medium
               
                  }
                  else {
                  	
                  	 Op.Activity_Status__c = 'error';
                  }
                          	
            }
           
            else if(d > LastActivityDate.addDays(14) || d > CreatedDate1.addDays(14)) {
              
              Op.Activity_Status__c = 'High'; //High
              
            }
            
            else if((d >= CreatedDate1.addDays(7) && d < CreatedDate1.addDays(14))
            	&& (d >= LastActivityDate.addDays(7) && d < LastActivityDate.addDays(14)) ) {
         
               Op.Activity_Status__c = 'Medium'; //Medium
               
            }
              
            else if(d < LastActivityDate.addDays(7) || d < CreatedDate1.addDays(7) || Status1 == 'In Progress' || Status1 == 'Waiting on someone else' || Status1 == 'Deferred') {
            	
                Op.Activity_Status__c = 'Low'; //Low
                
            }
            	
            else {
            
                Op.Activity_Status__c = 'Error';
                   
            }
        }    
           update Opptys2;
  }     
}

 

 

This is the start of my Test Class..

 

 

@isTest
private class OppPoliceTestClass {
  static testMethod void testOpportunity1()  {
  
    

  }
}
    

 

 

When I query the Policy class below I expect to retrieve the latest post date on  the Opportunity feed for a particular Opportunity, but it appears that It is not returning what I expected. My end goal is to evaluate the date as low, medium or high based on the criteria in the if statements. Everything else works as expected, I am just running into problems with the last Chatter post date. Any help would be appreciated.

 

 

global class OppPoliceController {

public void Opportunity1() {

List<Opportunity> Opptys2 = [SELECT o.LastActivityDate, o.Activity_Status__c, o.StageName, (SELECT CreatedDate from Feeds), (SELECT Status FROM Tasks) FROM Opportunity o WHERE o.StageName != 'Closed Won' AND o.StageName != 'Closed Lost' ORDER BY o.LastActivityDate DESC];

for(Opportunity Op : Opptys2){

datetime LastActivityDate = Op.LastActivityDate; //Last Activity Date in datetimeformat
datetime CreatedDate = null;
datetime CreatedDate1 = Op.feeds[0].CreatedDate; //Created Date in datetime format
date d = Date.today(); //Current Date Formated

string Status = '';
Status = Op.tasks[0].Status;
System.debug('This is the created date: ' + CreatedDate1);
System.debug('This is the status: ' + Status);
System.debug('This is todays date: ' + d);

if(LastActivityDate == Null) {

if(Status == 'In Progress' || Status == 'Waiting on someone else' || Status == 'Deferred') {

Op.Activity_Status__c = 'Low';


}
else if(Status == 'Not Started') {

Op.Activity_Status__c = 'High';


}
}

else if(d > LastActivityDate.addDays(14) && d > CreatedDate1.addDays(14)) {

Op.Activity_Status__c = 'High';

}

else if((d >= CreatedDate1.addDays(7) && d < CreatedDate1.addDays(14))) {

Op.Activity_Status__c = 'Medium';

}
else if(d >= LastActivityDate.addDays(7) && d < LastActivityDate.addDays(14)) {

Op.Activity_Status__c = 'Medium';

}



else if(d < LastActivityDate.addDays(7) || d < CreatedDate1.addDays(7) || Status == 'In Progress' || Status == 'Waiting on someone else' || Status == 'Deferred') {

Op.Activity_Status__c = 'Low';

}

else {

Op.Activity_Status__c = 'Error';

}
}
update Opptys2;
}
}

 

 

Have an apex class that has been tested to work, but I am having problems understanding the documentation for creating a Scheduler class. The documentation here makes it seem like all I have to do is create the following scheduler class, but when I schedule it to run in salesforce nothing happens. Any help would be appreciated.

 

Scheduler Class

 

 

global class OppPoliceScheduler1 implements Schedulable{
	
   global void execute(SchedulableContext sc) {
   	
      OppPoliceController O = new OppPoliceController();
   }
}

 

 

Apex Class

 

 

public with sharing class OppPoliceController {
 
  public void Opportunity() {
 
     List<Opportunity> Opptys2 = [SELECT id, LastActivityDate, Activity_Status__c, StageName, (SELECT id, CreatedDate from Feeds ) FROM Opportunity WHERE StageName != 'Closed Won' AND StageName != 'Closed Lost' ORDER BY LastActivityDate DESC];
     
        for(Opportunity Op : Opptys2){
       
        datetime LastActivityDate = Op.LastActivityDate; //Last Activity Date in datetimeformat
        datetime CreatedDate = Op.Feeds[0].CreatedDate;  //Created Date in datetime format 
        
        
        date d = Date.Today();  //Current Date Formated
       
            if(LastActivityDate == null || d > LastActivityDate.addDays(14) || d > CreatedDate.addDays(14)) {
              
              Op.Activity_Status__c = 'High';
              
               
            }
            
            else if((d >= LastActivityDate.addDays(7) && d < LastActivityDate.addDays(14)) 
                     || (d >= CreatedDate.addDays(7) && d < CreatedDate.addDays(14))) {
         
               Op.Activity_Status__c = 'Medium';
               
               
            }
            
            else if(d < LastActivityDate.addDays(7) || d < CreatedDate.addDays(7)) {
                Op.Activity_Status__c = 'Low';
                
            }
            	
            else {
            
                Op.Activity_Status__c = 'Error';
                   
            }
        }    
      
           update Opptys2;
  }     
}

 

 

Morning,

 

I am running into this error when I run my apex class in the system log: "Cannot Modify a Collection While It Is Being Iterated"  What can I do to resolve this issue?

 

I also have a question regarding my logic for the code. Currently I have two lists: one for all the Opportunites and one for all the Opportunitiy feed items. I want to evaluate them both and assign a value to the Activity Status field in Opportunity based on the critera in the If statements.

 

My question is, how do I make sure when it is evaluating the Opportunity feed that it updates the correct corresponding Opportunity?? Is the Opportunity feed id the same as the original Opportunity Id?? If so what would be the best way to implement that in my code when the critera is met?

 

Here is my code, I am very new to Salesforce development and still learning so help would be greatly appreciated.

 

 

public with sharing class OppPoliceController {

public void Opportunity() {

List<Opportunity> Opptys2 = [SELECT id, LastActivityDate, Activity_Status__c FROM Opportunity WHERE LastActivityDate != NULL ORDER BY LastActivityDate DESC];
List<OpportunityFeed> Opptys = [SELECT id, CreatedDate, (SELECT CreatedDate FROM FeedComments ORDER BY CreatedDate DESC) FROM OpportunityFeed];

for(OpportunityFeed o : Opptys) {

for(Opportunity Op : Opptys2){

datetime LastActivityDate = Op.LastActivityDate; //Last Activity Date in datetimeformat
datetime CreatedDate = o.CreatedDate; //Created Date in datetime format

datetime t = System.now(); // Current date unformated
date d = Date.newInstance(t.year(),t.month(),t.day()); //Current Date Formated

if(LastActivityDate == null || d > LastActivityDate.addDays(14) || d > CreatedDate.addDays(14)) {

string strStatus = 'High';
Opportunity Opp = New Opportunity(Activity_Status__c = strStatus);
Opptys2.add(Opp);
}

else if(d >= LastActivityDate.addDays(7) && d < LastActivityDate.addDays(14)
|| d >= CreatedDate.addDays(7) && d < CreatedDate.addDays(14)) {

string strStatus = 'Medium';
Opportunity Opp = New Opportunity(Activity_Status__c = strStatus);
Opptys2.add(Opp);
}

else if(d < LastActivityDate.addDays(7) || d < CreatedDate.addDays(7)) {

string strStatus = 'Low';
Opportunity Opp = New Opportunity(Activity_Status__c = strStatus);
Opptys2.add(Opp);
}
else {

string strStatus = 'Error';
Opportunity Opp = New Opportunity(Activity_Status__c = strStatus);
Opptys2.add(Opp);
}
}
}

update Opptys2;
}
}

 

 

 

 

 

 

 

 

How do you format the output of a date field in Visualforce? I want to evalute the date in a series of if else statements, but I am  recieving a long number such as 1299542400000 when the querry runs. How can I format the output to be usefull?? Thanks in advance.

 

 

List<Opportunity> Opptys2 = [SELECT LastActivityDate, Activity_Status__c FROM Opportunity ORDER BY LastActivityDate DESC];	

List<OpportunityFeed> Opptys = [SELECT id, (SELECT CreatedDate FROM FeedComments ORDER BY CreatedDate DESC) FROM OpportunityFeed];

 

 

 

Chris

I developed an apex class that I need to test but don't understand how to develop a test class for it. The class creates two lists: all Opportunities and the Opportunity Feed with comments. I then evaluate each list and assign a value to the Activity Status based on date fields in each list.

 

I want to test the apex class to see if it works so I am assuming I need to create a test class. I have read the limited documentation, but still don't understand where to go from here. Help would be appreciated as I am very new at this.

 

Here is my Apex class:

 

 

public class OppPoliceController {
	
  public void Opportunity() {
	
     List<Opportunity> Opptys2 = [SELECT Opportunity_Number__c, LastActivityDate, Activity_Status__c FROM Opportunity ORDER BY LastActivityDate];	
     List<OpportunityFeed> Opptys = [SELECT id, (SELECT CreatedById, CreatedDate FROM FeedComments ORDER BY CreatedDate DESC) FROM OpportunityFeed];
     
 	 
       for(OpportunityFeed o : Opptys) { 
       	 for(Opportunity Op : Opptys2){
          
            if(system.now() > Op.LastActivityDate.addDays(14) || system.now() > o.CreatedDate.addDays(14)) {
              
               string strStatus = 'High';
               Opportunity Opp = New Opportunity(Activity_Status__c = strStatus);
               Opptys2.add(Opp);
                
            }
            
            else if(system.now() >= Op.LastActivityDate.addDays(7) || system.now() < Op.LastActivityDate.addDays(14) 
                     || system.now() >= o.CreatedDate.addDays(7) && system.now() < o.CreatedDate.addDays(14)) {
         
               string strStatus = 'Medium';
               Opportunity Opp = New Opportunity(Activity_Status__c = strStatus);
               Opptys2.add(Opp);
               
            }
            
            else if(system.now() < Op.LastActivityDate.addDays(7) || system.now() < o.CreatedDate.addDays(7)) {
            	
                string strStatus = 'Low';
                Opportunity Opp = New Opportunity(Activity_Status__c = strStatus);
                Opptys2.add(Opp);
               
            }
            else {
            	
            	string strStatus = 'Error';
            	Opportunity Opp = New Opportunity(Activity_Status__c = strStatus);
                Opptys2.add(Opp);
            	
            }
       	 }    
       }
         try {
          upsert Opptys2;
         } catch (DmlException e) {
         	system.debug('Error: ' + e.getMessage());
         }
  }     
}

 

 

Afternoon everyone,

 

Running into problems debugging this apex class. It has no runtime errors so it's obiviously logic errors. I am attemping to querry all Opportunity "Last Activitity Date" and also Chatter "Created Date" and then update the Activity Status field based on critera. This apex class will be ran everynight for a report. Any ideas on why the Activity status field is not updating?

 

public with sharing class OppPoliceController {
    
    public void Opportunity() {
    
     List<OpportunityFeed> Opptys = [SELECT id, (SELECT CreatedDate FROM FeedComments ORDER BY CreatedDate DESC) FROM OpportunityFeed];
     List <Opportunity> Opptys2 = [SELECT LastActivityDate, Activity_Status__c FROM Opportunity ORDER BY LastActivityDate];
  
       for(OpportunityFeed o : Opptys){   
            for(Opportunity Op : Opptys2){
         
            if(system.now() > o.CreatedDate.addDays(14) || system.now() > Op.LastActivityDate.addDays(14)) {

                Op.Activity_Status__c = 'High';
                update Opptys2;  
            }
            
            else if(system.now() >= o.CreatedDate.addDays(7) && system.now() < o.CreatedDate.addDays(14)
                      ||  system.now() >= Op.LastActivityDate.addDays(7) || system.now() < Op.LastActivityDate.addDays(14)) {
            
               Op.Activity_Status__c = 'Medium';
                update Opptys2;
            }
            
            else if(system.now() > o.CreatedDate.addDays(7) || system.now() > Op.LastActivityDate.addDays(7)) {

                Op.Activity_Status__c = 'Low';
                update Opptys2;    
            }
            }   
       }         
    }     
}

I am attemping to querry all Oppertunities and Chatter feed posts on all the oppertunites. I then would to evalute the Oppertunities based on LastActivityDate and Chatter feed posts by CreatedDate and update a picklist named Activity Status with High, Medium, or Low. This would be ran nightly and would be eventually fed into a report.

 

This is what I have so far. I don't think I did the query correctly because it is giving me the error: "Error: Compile Error: Didn't understand relationship 'FeedComments' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 3 column 32"

 

To sum it up: Am I querrying this correctly and also am I assigning the value (High, Medium, Low) correctly to the Activity_Status Picklist?

 

public class OppPoliceController {

    List<Opportunity> Opptys = [SELECT LastActivityDate, Activity_Status__c, (SELECT CreatedDate FROM FeedComments ORDER BY CreatedDate DESC) FROM Opportunity]];
    
    //Loop through Opportunities only once
    for(Opportunity o : Opptys){
        
         //Loop through related FeedComments only once
         for(FeedComments f : o.Opportunity){
         
            if(f.CreatedDate > (today() - 14) Or o.LastActivityDate > (today() - 14)){
                
                Opp = Database.query(Opptys);
                Activity_Status__c = 'High';
                update Opptys;
                return null;
            }
            else if(f.CreatedDate >= (today() - 7) Or o.LastActivityDate >= (today() - 7)){
            
                Opp = Database.query(Opptys);
                Activity_Status__c = 'Medium';
                update Opptys;
                return null;
            }
            else if(f.CreatedDate < (today() - 14) Or o.LastActivityDate < (today() - 14)){
                
                Opp = Database.query(Opptys);
                Activity_Status__c = 'Medium';
                update Opptys;
                return null;
            }
            else if(f.CreatedDate > (today() - 7) Or o.LastActivityDate > (today() - 7)){
                
                Opp = Database.query(Opptys);
                Activity_Status__c = 'Low';
                update Opptys;
                return null;
            }
         }
    
   }
}

I am trying to figure out why this is not compling corrrectly. The error I recieve is: "Error: Compile Error: Constructor not defined: [System.SelectOption].<Constructor>(Id) at line 14 column 25." Would appreciate it if you guys could help a new developer out.

 

Chris

 


public class ModalityExtension {
    private Trade_in__c t; //User sobject
    
   
    public ModalityExtension(ApexPages.StandardController stdController) {
        this.t = (Trade_in__c)stdController.getRecord();
    }
    

    public List<selectOption> getModality() {
        List<selectOption> options = new List<selectOption>(); //new list for holding all of the picklist options
        options.add(new selectOption('', '- None -')); //add the first option of '- None -' in case the user doesn't want to select a value or in case no values are returned from query below
        for (Trade_in__c TradeIns : [SELECT Modality2__c FROM Trade_in__c]) {
            options.add(new selectOption(TradeIns.Modality2__c)); //for all records found - add them to the picklist options
        }
        return options; //return the picklist options
    }
}

I am trying to display two object on the same page in tables and then have search bars that search across both objects (Oppertunites and Tradeins) on all fields being shown.

 

Currently, I have the page populate all Oppertunities and TradeIns upon page load and display them in seperate tables (This is working just fine, but I plan on disabling b/c it is useless).

 

I first wanted to tackle geting the Tradein search to work so I then have textboxes that will allow the user to search on each field. I started with TradeIns search and I can't figure out what i am doing wrong. I would like the TradeIn table to update upon a user changing the search fields and have added the action to the fields, but it is not working. I then tried a button that runs the action, but that to is not working. I am not recieving any errors so it is really hard to diagnose what is wrong.

 

 

I am trying to do somthing very similiar to what has been done on this site, but with two objects.

 

Any assistance would be really appreciated.

 

Chris

 

Here is my code

 

Controller for TradeIn Component


public with sharing class TradeInController2 {
                
    // the soql without the order and limit
  private String soql {get;set;}
  // the collection of contacts to display
  public List<Trade_in__c> TradeIn{get;set;}
 
  // the current sort direction. defaults to asc
  public String sortDir {
    get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;  }
    set;
  }
 
  // the current field to sort by. defaults to last name
  public String sortField {
    get  { if (sortField == null) {sortField = 'name'; } return sortField;  }
    set;
  }
 
  // format the soql for display on the visualforce page
  public String debugSoql {
    get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
    set;
  }
 
  // init the controller and display some sample data when the page loads
  public TradeInController2() {
    soql = 'select name, Deinstall_Date__c, Status__c, Modality2__c, Modality__c from Trade_in__c';
    runQuery();
  }
 
  // toggles the sorting of query from asc<-->desc
  public void toggleSort() {
    // simply toggle the direction
    sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
    // run the query again
    runQuery();
  }
 
  // runs the actual query
  public void runQuery() {
 
    try {
      TradeIn = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');
    } catch (Exception e) {
      ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
    }
 
  }
 
  // runs the search with parameters passed via Javascript
  public PageReference runSearch() {
 
    String name1= Apexpages.currentPage().getParameters().get('name');
    String Ddate1= Apexpages.currentPage().getParameters().get('Ddate');
    String EquipmentState1 = Apexpages.currentPage().getParameters().get('EquipmentState');
    String IncomingModality1= Apexpages.currentPage().getParameters().get('IncomingModality');
    String ExternalModality1= Apexpages.currentPage().getParameters().get('ExternalModality');
 
    soql = 'select name, Deinstall_Date__c, Status__c, Modality2__c,  Modality__c from Trade_in__c';
    if (!name1.equals(''))
      soql += ' and name LIKE \''+String.escapeSingleQuotes(name1)+'%\'';
    if (!Ddate1.equals(''))
      soql += ' and Deinstall_Date__c LIKE \''+String.escapeSingleQuotes(Ddate1)+'%\'';
    if (!EquipmentState1.equals(''))
      soql += ' and Status__c LIKE \''+String.escapeSingleQuotes(EquipmentState1)+'%\'';
    if (!IncomingModality1.equals(''))
      soql += ' and Modality2__c LIKE \''+String.escapeSingleQuotes(IncomingModality1)+'%\'';
    if (!ExternalModality1.equals(''))
      soql += ' and Modality__c LIKE \''+String.escapeSingleQuotes(ExternalModality1)+'%\'';

    // run the query again
    runQuery();
 
    return null;
  }
}



Component


<apex:component controller="TradeInController2">

        <apex:form >
        <apex:pageMessages id="errors" />

        <apex:pageBlock mode="edit" id="criteria">

        <script type="text/javascript">
          function doSearch() {
            searchServer(
          document.getElementById("name1").value,
          document.getElementById("Ddate1").value,
          document.getElementById("EquipmentState1 ").value,
          document.getElementById("IncomingModality1").value,
          document.getElementById("ExternalModality1").value
          );
      }
      </script>
 
      <apex:actionFunction id="Test" name="searchServer" action="{!runSearch}" rerender="results,debug,errors">
          <apex:param name="name1" value="" />
          <apex:param name="Ddate1" value="" />
          <apex:param name="EquipmentState1 " value="" />
          <apex:param name="IncomingModality1" value="" />
          <apex:param name="ExternalModality1" value="" />

      </apex:actionFunction>
      
      <apex:commandButton value="Search" onclick="{function doSearch()}"/>
      
      <table cellpadding="2" cellspacing="2">
      <tr>
        <td style="font-weight:bold;">Trade-In Number<br/>
        <input type="text" id="name1" onkeyup="doSearch();"/>
        </td>
      </tr>
      <tr>
        <td style="font-weight:bold;">De-Install Date<br/>
        <input type="text" id="Ddate1" onkeyup="doSearch();"/>
        </td>
      </tr>
      <tr>
        <td style="font-weight:bold;">Equipment State<br/>
        <input type="text" id="EquipmentState1" onkeyup="doSearch();"/>
        </td>
      </tr>
      <tr>
        <td style="font-weight:bold;">Incoming Modality<br/>
        <input type="text" id="IncomingModality1" onkeyup="doSearch();"/>
        </td>
      </tr>
      <tr>
        <td style="font-weight:bold;">External Modality<br/>
        <input type="text" id="ExternalModality1" onkeyup="doSearch();"/>
        </td>
      </tr>

      </table>
      </apex:pageBlock>
      
      
      <apex:pageBlock mode="edit" id="results">
      
       <apex:pageBlockTable value="{!TradeIn}" var="trade">
 
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Trade-In Number" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="name" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!trade.name}"/>
            </apex:column>
 
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="De-Install Date" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="Deinstall_Date__c" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!trade.Deinstall_Date__c}"/>
            </apex:column>
 
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Equipment State" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="Status__c" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!trade.Status__c}"/>
            </apex:column>
 
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Incoming Modality" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="Modality2__c" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!trade.Modality2__c}"/>
            </apex:column>
            
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="External Modality" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="Modality__c" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!trade.Modality__c}"/>
            </apex:column>
 
        </apex:pageBlockTable>
     
     <apex:pageBlock title="Debug - SOQL" id="debug">
      <apex:outputText value="{!debugSoql}"/>           
     </apex:pageBlock>    

     
     </apex:pageBlock>
     
     
        </apex:form>
</apex:component>




Salesforce Page


<apex:page standardController="Account">

    <apex:pageBlock title="Search">
   
        <apex:dataTable value="{!account.Opportunities}" var="opportunity" cellPadding="4" border="1">
              <apex:column >
               <apex:facet name="header">Opportunity Name</apex:facet>
                {!opportunity.Name}
              </apex:column>
              <apex:column >
               <apex:facet name="header">Close Date</apex:facet>
                {!opportunity.CloseDate}
              </apex:column>
              <apex:column >
                <apex:facet name="header">Equipment state</apex:facet>
                  {!opportunity.Equipment_State__c}
              </apex:column>
              <apex:column >
                <apex:facet name="header">Incoming Equipment</apex:facet>
                 <apex:outputField value="{!opportunity.Incoming_Equipment__c}"/>
              </apex:column>
               <apex:column >
                <apex:facet name="header">Outgoing Equipment</apex:facet>
                 <apex:outputField value="{!opportunity.Outgoing_Equipment__c}"/>
              </apex:column>
        </apex:dataTable>
     </apex:pageBlock>
    
     
      <apex:pageblock title="Trade-Ins">
           <c:TradeInComponent />
     </apex:pageBlock> -->
     
     
   <apex:detail subject="{!$CurrentPage.parameters.cid}" relatedList="false" title="false"/>
</apex:page>

What I would like to accomplish is a apex class that will trigger everytime a report is generated. It will query all Oppourtunities and then assign them a Activity Status based on the last Activity date. This is what I have so far with the current error I am recieving. I know it needs ton of work and any help would be apprecited.

 

 

Here is the requirements:

 

Activity Status wil be High
If Opportunity.LAST_ACTIVITY_DATE  is greater than 14 days

Medium
If Opportunity.LAST_ACTIVITY_DATE  is in-between 7 and 14
days

Low

If Opportunity.LAST_ACTIVITY_DATE  is less than 7 days.

 

Chris

 

 

Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST<Opportunity> at line 7 column 16


 

Public class OppPoliceController    {

       List<Opportunity> O = [SELECT LastActivityDate, Activity_Status__c FROM Opportunity]; {
       
        
            If (O.LastActivityDate > (today() - 14))    {
               O.Activity_Status__c = 'High';
            }
        
            else if (O.LastActivityDate >= (today() - 7))    {
               O.Activity_Status__c = 'Medium';    
            }
        
            else if (O.Last_Activity_Date < (today() - 14))    {
               O.Activity_Status__c = 'Medium';
            }
        
            else if (O.LastActivityDate > (today() - 7))
               O.Activity_Status__c = 'Low';
            
           update O;
           }
        
       }                
 

What I am going for is two dataTables on the same page. I created the one dataTable using the standardController: Opportunity. I then created  a custom controller for TradeIns called TradeInController2 that will be used in a component that will create the other dataTable on the page. I am extremely new at this so I am not sure If i'm on the right track or not and what my problems are in my code.

 

For your help here are the requirements:

 

Develop a visual force page that will allow us to query both opportunities and trade ins on the same page.  It would be able to search on the following fields from each

Opp.
Close date
Equipment state
Modality

Trade in
Deinstallation date
Equipment state
Modality

 

Currently the error I am receiving when trying to save my Component is  "Error: The content of elements must consist of well-formed character data or markup."  This is my first project so any fixes for my code and or help would be extremely appreciated.  I have gone through tons of documentation, but none have good examples of what my boss is asking so I am doing the best I can...

 

Controller for Component:

 

public class TradeInController2{

    private final Trade_in__c tradein;

    public TradeInController2() {
        tradein= [select name, Deinstall_Date__c, Status__c, Modality__c from Trade_in__c ];
    }
    public Trade_in__c getTradeIn() {
        return tradein;
    }
        }

 

Component:

 

<apex:component controller="TradeInController2">

    <apex:dataTable value="{!tradein}" var="tr" cellPadding="4" border="1">
              <apex:column >
                    <apex:facet name="header">Trade-In Number</apex:facet>
                    {!tr.name}
              </apex:column>
               <apex:column >
                    <apex:facet name="header">De-Install Date</apex:facet>
                     {!tr.Deinstall_Date__c}
              </apex:column>
              <apex:column >
                    <apex:facet name="header">Equipment State</apex:facet>
                    {!tr.Status__c}
              </apex:column>
              <apex:column >
                    <apex:facet name="header">Modality</apex:facet>
                    {!tr.Modality__c}
              </apex:column>

    </apex:dataTable>

<</apex:component>

 

 

The Page:

 

<apex:page standardController="Account">
 
    <apex:pageBlock title="Hello {!$User.FirstName}">
    </apex:pageBlock>   
    <apex:pageBlock title="Opportunities">
        <apex:dataTable value="{!account.Opportunities}" var="opportunity" cellPadding="4" border="1">
              <apex:column >
                    <apex:facet name="header">Opportunity Name</apex:facet>
                    {!opportunity.Name}
              </apex:column>
              <apex:column >
                   <apex:facet name="header">Close Date</apex:facet>
                    {!opportunity.CloseDate}
              </apex:column>
              <apex:column >
                     <apex:facet name="header">Equipment state</apex:facet>
                      {!opportunity.Equipment_State__c}
              </apex:column>
              <apex:column >
                    <apex:facet name="header">Modality</apex:facet>
                     {!opportunity.Equipment_State__c}
              </apex:column>
        </apex:dataTable>
     </apex:pageBlock>
    
     <apex:pageblock title="Trade-Ins">
           <c:TradeInComponent/>
    </apex:pageBlock>


   <apex:detail subject="{!$CurrentPage.parameters.cid}" relatedList="false" title="false"/>
</apex:page>

 

Thank you for your help in advance.

 

Chris

Hey guys, I have problem making a page that is requested  by the uppers. This is my first project and I am really struggling with it.

 

The page will allow us to query both opportunities and trade ins at the same time.  It would be able to search on the following field from each

Opportunity:
Close date
Equipment state

Modality

 

Trade In:
DeInstallation date
Equipment state
Modality

 

It should display the result on one page in two separate grids.  The dates should be a date range.  And the equipment state and modality should be optional.  

 

 I have been told this will involve creating a custom visual force page with a custom apex controller, but I have no clue how to even code it. 

 

Any help would be extremly appreciated!

 

Chris

 

 

I have a VF page that is being populated via a standard controller and a extension. It works just fine in the sandbox, but in production I am recieving the following error: " PDF generation failed. Check the page markup is valid. "

 

Any input on why this is happing would be appreciated:

 

edit: I have determined it has to do with the public case comments rendered. It works if I just have the comment body rendered as public, but if I add the created date as well then the error arises.

 

Page:

 

<apex:page renderas="pdf" standardController="Case" extensions="PDFServiceExtension">
<apex:stylesheet value="{!$Resource.PDFHeaderFooter}"/>
<center>
    <apex:image url="{!$Resource.MIRLetterhead}" width="700" height="97" />
</center>
    <apex:panelGrid columns="2" id="theGrid">
        <apex:outputLabel value="Case #: " for="Case#" style="font-weight: bold"/>
        <apex:outputField value="{!Case.CaseNumber}" id="CaNumber"/>
        
        <apex:outputLabel value="Date & Time Opened: " for="CaseOpen" style="font-weight: bold"/>
        <apex:outputField value="{!Case.CreatedDate}" id="CaseOpen"/>
        
        <apex:outputLabel value="Date & Time Closed: " for="CaseClosed" style="font-weight: bold"/>
        <apex:outputField value="{!Case.ClosedDate}" id="CaseClosed"/>
        
        <apex:outputLabel value="Status:" for="CaseStatus: " style="font-weight: bold"/>
        <apex:outputField value="{!Case.Status}" id="CaseStatus"/>
        
        <apex:outputLabel value="Type:" for="CaseType: " style="font-weight: bold"/>
        <apex:outputField value="{!Case.Type}" id="CaseType"/>
        
        <apex:outputLabel value="Account: " for="Name" style="font-weight: bold"/>
        <apex:outputField value="{!Case.Account.name}" id="Name"/>
        
        <apex:outputLabel value="Subject: " for="Case#" style="font-weight: bold"/>
        <apex:outputField value="{!Case.Subject}" id="CaSubj"/>
        
        <apex:outputLabel value="Description: " for="Case#" style="font-weight: bold"/>
        <apex:outputField value="{!Case.Description}" id="CaDesc"/>

    </apex:panelGrid>
    
    <br></br>
    <apex:outputLabel value="Service Activities:" for="Name" style="font-weight: bold"/>
    <apex:dataTable value="{!SA}" var="LIs" width="50%" border="1px" >
		<apex:column headerValue="Service Engineer" value="{!LIs.Contact__c}" headerClass="tableHead"/>
		<apex:column headerValue="Total Hours" value="{!LIs.Total_Hours__c}"/>
		<apex:column headerValue="Date Performed" value="{!LIs.Date_Performed__c}"/>
	</apex:dataTable>
	
	<br></br>
    <apex:outputLabel value="Case Comments:" for="Name2" style="font-weight: bold"/> 

    <apex:pageBlock >
        <apex:pageBlockTable value="{!case.casecomments}" var="c" width="50%" border="1px" >
            <apex:column value="{!c.commentbody}" rendered="{!c.isPublished = true}"/>
            <apex:column value="{!c.createddate}" rendered="{!c.isPublished = true}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>   
</apex:page>

 Extension:

public with sharing class PDFServiceExtension {
	
	private final Case Ca;
  
	public PDFServiceExtension(ApexPages.StandardController CaseController) {
		this.Ca = (Case)CaseController.getRecord();
	}
  
	//For Testing Purposes  
	public PDFServiceExtension(Case tcase) {
        this.Ca = tcase;
	}
  
  // Create a list of type Suite__c and call the query method
    public List<Service_Activity__c> activityRecords() {
         return (List<Service_Activity__c>) activityRecords.getRecords();
    }
    
  // Query the db for the list of Suite__c records to use on the vf page and return a list
    public ApexPages.StandardSetController activityRecords{
      get {
            if(activityRecords == null) {
                activityRecords = new ApexPages.StandardSetController(Database.getQueryLocator([Select s.Contact__c, s.Case__c, s.Total_Hours__c, s.Description__c, s.Date_Performed__c  from Service_Activity__c s Where s.Case__c =:ApexPages.currentPage().getParameters().get('id')]));
            }
            return activityRecords;
        }
        set;
    }
    
    public List<Service_Activity__c> getSA() {
        return (List<Service_Activity__c>) activityRecords.getRecords();
    }
}

 

How do you querry a reference/lookup field and then read what that ID is and based on that ID, populate another reference/lookup field. I know what the values of both Id's are I am just having trouble getting it to insert and read correctly.

 

This is the code I am having problems with.

 

 

Equip2 = [SELECT Name, Modality__c, Modality_Name__c, CT_Models__c, CT_Modality_Picklist__c FROM Equipment__c WHERE Modality__c != NULL ORDER BY Name ASC];  

 

for(Equipment__c Eqp : Equip2)    {
        
            
                if(Eqp.Modality__c =  'a0a30000004XQiKAAW') {          // If lookup field modality = this id, then insert below
                
                      Eqp.Modality_Name__c = 'a0a30000004XQiKAAW';    //Populate the other lookup field
                      Eqp.CT_Modality_Picklist__c = 'CT Unknown';    // Specify Picklist Value
                      Eqp.CT_Models__c = 'Unknown';     // Specify Picklist Value
                }

             ....

             .....

             ....

               else  {
                    
                      system.debug('No modalities match');
                         
                }                       
        }    
           insert Equip2;

             ....

             .....

             ....

 

I am recieving the following error when I try to deploy my apex class and test class: visualforce CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, opptySwarm: execution of AfterUpdate.  Is this because I am trying to update too many field at once?? Or some other issue? What is my best option to fix this?

 

Thank you in advance, I am new to Salesforce development.

 

Chris


Apex Class:

 

 

global class OppPoliceController {
 
  public void Opportunity1() {
  	
  	 List<Opportunity> Opptys2 = [SELECT CreatedDate, StageName, LastActivityDate, Activity_Status__c, (SELECT CreatedDate FROM Feeds ORDER BY CreatedDate DESC limit 1), (SELECT Status FROM Tasks) FROM Opportunity WHERE StageName != 'Closed Won' AND StageName != 'Closed Lost' AND StageName != 'Closed Other' AND StageName != 'Qualified Lost' AND StageName != 'Prospect' AND CloseDate != Today ORDER BY LastActivityDate DESC];
 
	
        for(Opportunity Op : Opptys2){
        
        datetime d = Date.today();  //Current Date Formated
        datetime LastActivityDate = Op.LastActivityDate; //Last Activity Date in datetimeformat
        
        datetime CreatedDate1;
        if(Op.Feeds != Null && !Op.Feeds.isEmpty()) {
        	
           CreatedDate1 = Op.Feeds[0].CreatedDate;  //Created Date in datetime format 	
          
        }
        else {
        	system.debug('<--------------Error CreatedDate for Feeds is Null---------------->');
        	CreatedDate1 = Op.CreatedDate;
        	
        }
         	 
        string Status1;
        if(Op.Tasks != Null && !Op.Tasks.isEmpty())  {
        	
        	Status1 = Op.Tasks[0].Status;
        	
        }
        else {
        	system.debug('<----------------ERROR Staus for Tasks is Null-------------------->');
        	Status1 = null;
        	
        }
        

        System.debug('This is the created date: ' + CreatedDate1);
        System.debug('This is the status: ' + Status1);
        System.debug('This is todays date: ' + d); 
        
            if(LastActivityDate == Null) { 
            	
            	if(Status1 == 'In Progress' || Status1 == 'Waiting on someone else' || Status1 == 'Deferred') {
            		
            		 Op.Activity_Status__c = 'Low'; 
            		 	 
            	}
            	 else if(Status1 == null || Status1 == 'Not Started' || d > CreatedDate1.addDays(14)) {
            	
            	 Op.Activity_Status__c = 'High'; 
            	     	 
            	}
            	 else if(d >= CreatedDate1.addDays(7) && d < CreatedDate1.addDays(14)) {
         
                 Op.Activity_Status__c = 'Medium'; 
               
                  }
                  else {
                  	
                  	 Op.Activity_Status__c = 'error';  
                  }
                          	
            }
           
            else if(d > LastActivityDate.addDays(14) || d > CreatedDate1.addDays(14)) {
              
              Op.Activity_Status__c = 'High';
              
            }
            
            else if((d >= CreatedDate1.addDays(7) && d < CreatedDate1.addDays(14))
            	|| (d >= LastActivityDate.addDays(7) && d < LastActivityDate.addDays(14)) ) {
         
               Op.Activity_Status__c = 'Medium'; 
               
            }
              
            else if(d < LastActivityDate.addDays(7) || d < CreatedDate1.addDays(7) || Status1 == 'In Progress' || Status1 == 'Waiting on someone else' || Status1 == 'Deferred') {
            	
                Op.Activity_Status__c = 'Low';
                
            }
            	
            else {
            
                Op.Activity_Status__c = 'Error';
                   
            }
        }    
           update Opptys2;
  
  }   
}

 

 

 

Apex Test Class

 

 

@isTest
private class OppPoliceTestClass {

    static testMethod void testOpportunity1() {
        
      date d = Date.today() + 7;
      
      System.debug('The close date is: ' + d);
        
      Opportunity Opp = new Opportunity();
      Opp.name = 'Op-Test9';
      Opp.StageName = 'Open';
      Opp.CloseDate = d;
   
      insert Opp;
      
      Task t = new Task();
      t.Subject='Send out Notice';
      t.Status = 'Not Started';
      t.Priority = 'Normal';
      t.WhatId = Opp.id;
      
      insert t;
      
      System.debug('This is the Opp id: ' + Opp.id);
      System.debug('This is the WhatId: ' + t.WhatId);
      
      OppPoliceController myClass = new OppPoliceController();
      myClass.Opportunity1();
      
      List<Opportunity> OppStatus = [select o.name, o.Activity_Status__c from Opportunity o WHERE o.name= 'Op-Test9' LIMIT 1];
      
      string OpName = OppStatus[0].name;
      System.debug('The name of the Opp is ' + OpName);    
      
      for(Opportunity Op2 : OppStatus){
          
          System.assertEquals('High',Op2.Activity_Status__c);
          System.debug('The Activity Status for the Test is: ' + Op2.Activity_Status__c);
          
      }                              
   }
}



 

 

 

 

This is my first salesforce project endeveour and I am struggling to get it done on time. I have tested my apex class and it works as expected, but now I need to create test methods so that I can deploy it into Salesforce but I am struggling to grasp what I need to do.  I have read the documentation, but not still am not sure how to best setup this up. I would really appreciate it if you could help a beginner out!

 

Thanks in advance!

 

Here is my apex class:

 

 

global class OppPoliceController {
 
  public void Opportunity1() {
 
     List<Opportunity> Opptys2 = [SELECT name, LastActivityDate, Activity_Status__c, StageName, (SELECT CreatedDate FROM Feeds ORDER BY CreatedDate DESC limit 1), (SELECT Status FROM Tasks) FROM Opportunity WHERE StageName != 'Closed Won' AND StageName != 'Closed Lost' ORDER BY LastActivityDate DESC];
 
	
        for(Opportunity Op : Opptys2){
        
        datetime LastActivityDate = Op.LastActivityDate; //Last Activity Date in datetimeformat
        datetime CreatedDate = null;
       
        datetime CreatedDate1 = Op.Feeds[0].CreatedDate;  //Created Date in datetime format 
        datetime d = Date.today();  //Current Date Formated
        
        string status1 = '';
        
        if(Op.Tasks != Null && !Op.Tasks.isEmpty())  {
        	
        	 Status1 = Op.Tasks[0].Status;
        }
        else {
        	
        	system.debug('error');
        }
        	
        System.debug('This is the created date: ' + CreatedDate1);
        System.debug('This is the status: ' + Status1);
        System.debug('This is todays date: ' + d); 
        
            if(LastActivityDate == Null) { 
            	
            	if(d < CreatedDate1.addDays(7) || Status1 == 'In Progress' || Status1 == 'Waiting on someone else' || Status1 == 'Deferred') {
            		
            		 Op.Activity_Status__c = 'Low'; //low
            		 	 
            	}
            	 else if(Status1 == 'Not Started' && d > CreatedDate1.addDays(14)) {
            	
            	 Op.Activity_Status__c = 'High'; //High
            	     	 
            	}
            	 else if(d >= CreatedDate1.addDays(7) && d < CreatedDate1.addDays(14)) {
         
                 Op.Activity_Status__c = 'Medium'; //Medium
               
                  }
                  else {
                  	
                  	 Op.Activity_Status__c = 'error';
                  }
                          	
            }
           
            else if(d > LastActivityDate.addDays(14) || d > CreatedDate1.addDays(14)) {
              
              Op.Activity_Status__c = 'High'; //High
              
            }
            
            else if((d >= CreatedDate1.addDays(7) && d < CreatedDate1.addDays(14))
            	&& (d >= LastActivityDate.addDays(7) && d < LastActivityDate.addDays(14)) ) {
         
               Op.Activity_Status__c = 'Medium'; //Medium
               
            }
              
            else if(d < LastActivityDate.addDays(7) || d < CreatedDate1.addDays(7) || Status1 == 'In Progress' || Status1 == 'Waiting on someone else' || Status1 == 'Deferred') {
            	
                Op.Activity_Status__c = 'Low'; //Low
                
            }
            	
            else {
            
                Op.Activity_Status__c = 'Error';
                   
            }
        }    
           update Opptys2;
  }     
}

 

 

This is the start of my Test Class..

 

 

@isTest
private class OppPoliceTestClass {
  static testMethod void testOpportunity1()  {
  
    

  }
}
    

 

 

Have an apex class that has been tested to work, but I am having problems understanding the documentation for creating a Scheduler class. The documentation here makes it seem like all I have to do is create the following scheduler class, but when I schedule it to run in salesforce nothing happens. Any help would be appreciated.

 

Scheduler Class

 

 

global class OppPoliceScheduler1 implements Schedulable{
	
   global void execute(SchedulableContext sc) {
   	
      OppPoliceController O = new OppPoliceController();
   }
}

 

 

Apex Class

 

 

public with sharing class OppPoliceController {
 
  public void Opportunity() {
 
     List<Opportunity> Opptys2 = [SELECT id, LastActivityDate, Activity_Status__c, StageName, (SELECT id, CreatedDate from Feeds ) FROM Opportunity WHERE StageName != 'Closed Won' AND StageName != 'Closed Lost' ORDER BY LastActivityDate DESC];
     
        for(Opportunity Op : Opptys2){
       
        datetime LastActivityDate = Op.LastActivityDate; //Last Activity Date in datetimeformat
        datetime CreatedDate = Op.Feeds[0].CreatedDate;  //Created Date in datetime format 
        
        
        date d = Date.Today();  //Current Date Formated
       
            if(LastActivityDate == null || d > LastActivityDate.addDays(14) || d > CreatedDate.addDays(14)) {
              
              Op.Activity_Status__c = 'High';
              
               
            }
            
            else if((d >= LastActivityDate.addDays(7) && d < LastActivityDate.addDays(14)) 
                     || (d >= CreatedDate.addDays(7) && d < CreatedDate.addDays(14))) {
         
               Op.Activity_Status__c = 'Medium';
               
               
            }
            
            else if(d < LastActivityDate.addDays(7) || d < CreatedDate.addDays(7)) {
                Op.Activity_Status__c = 'Low';
                
            }
            	
            else {
            
                Op.Activity_Status__c = 'Error';
                   
            }
        }    
      
           update Opptys2;
  }     
}

 

 

Morning,

 

I am running into this error when I run my apex class in the system log: "Cannot Modify a Collection While It Is Being Iterated"  What can I do to resolve this issue?

 

I also have a question regarding my logic for the code. Currently I have two lists: one for all the Opportunites and one for all the Opportunitiy feed items. I want to evaluate them both and assign a value to the Activity Status field in Opportunity based on the critera in the If statements.

 

My question is, how do I make sure when it is evaluating the Opportunity feed that it updates the correct corresponding Opportunity?? Is the Opportunity feed id the same as the original Opportunity Id?? If so what would be the best way to implement that in my code when the critera is met?

 

Here is my code, I am very new to Salesforce development and still learning so help would be greatly appreciated.

 

 

public with sharing class OppPoliceController {

public void Opportunity() {

List<Opportunity> Opptys2 = [SELECT id, LastActivityDate, Activity_Status__c FROM Opportunity WHERE LastActivityDate != NULL ORDER BY LastActivityDate DESC];
List<OpportunityFeed> Opptys = [SELECT id, CreatedDate, (SELECT CreatedDate FROM FeedComments ORDER BY CreatedDate DESC) FROM OpportunityFeed];

for(OpportunityFeed o : Opptys) {

for(Opportunity Op : Opptys2){

datetime LastActivityDate = Op.LastActivityDate; //Last Activity Date in datetimeformat
datetime CreatedDate = o.CreatedDate; //Created Date in datetime format

datetime t = System.now(); // Current date unformated
date d = Date.newInstance(t.year(),t.month(),t.day()); //Current Date Formated

if(LastActivityDate == null || d > LastActivityDate.addDays(14) || d > CreatedDate.addDays(14)) {

string strStatus = 'High';
Opportunity Opp = New Opportunity(Activity_Status__c = strStatus);
Opptys2.add(Opp);
}

else if(d >= LastActivityDate.addDays(7) && d < LastActivityDate.addDays(14)
|| d >= CreatedDate.addDays(7) && d < CreatedDate.addDays(14)) {

string strStatus = 'Medium';
Opportunity Opp = New Opportunity(Activity_Status__c = strStatus);
Opptys2.add(Opp);
}

else if(d < LastActivityDate.addDays(7) || d < CreatedDate.addDays(7)) {

string strStatus = 'Low';
Opportunity Opp = New Opportunity(Activity_Status__c = strStatus);
Opptys2.add(Opp);
}
else {

string strStatus = 'Error';
Opportunity Opp = New Opportunity(Activity_Status__c = strStatus);
Opptys2.add(Opp);
}
}
}

update Opptys2;
}
}

 

 

 

 

 

 

 

 

Hello,

 

I've instaled Milestones PM - Project Management however when I click on Initialize the app I get the following error:

 

Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Milestone1_Task_Trigger: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: LIMIT_EXCEEDED, Maximum per user subscription limit reached.: [] Class.Milestone1_Task_Trigger_Utility.handleTaskAfterTrigger: line 65, column 9 Trigger.Milestone1_Task_Trigger: line 8, column 3: []

 

An unexpected error has occurred. Your development organization has been notified.

 

 

Can anyone help?

 

Thanks

Matt