• uptime_andrew
  • NEWBIE
  • 199 Points
  • Member since 2007

  • Chatter
    Feed
  • 8
    Best Answers
  • 4
    Likes Received
  • 0
    Likes Given
  • 85
    Questions
  • 111
    Replies

Hi all -

 

This is my test class:

 

@isTest
private class testAutomaticFollowUp {

    public static testMethod void unitTestAutomaticFollowUp() {

        Contact acct = new Contact();
        acct.Name = 'Test Contact';
acct.Follow_Up_Date__c = Date.newInstance(2011,5,1);


        insert acct;

        test.startTest();

        acct.Follow_Upcheckbox__c = true;
        update acct;

        test.stopTest();

    }
}

 

I get the error:

 

Error: Compile Error: Field is not writeable: Contact.Name at line 7 column 9

 

Here is the Trigger:

 

trigger AutomaticFollowUp on Contact (before update) {

    ////////////////////////////////////
    // This trigger detects the change of the Followup field
    // and creates an Event
    ////////////////////////////////////
    
    if(trigger.isUpdate && trigger.isBefore) {
        
        // Create empty List to hold new Events (bulk DML) 
        List<Event> lstNewEvents = new List<Event>();
        
        for(Contact a : trigger.new) {
            
            // Determine if the checkbox is TRUE and the user has just flipped it from FALSE.
            if(a.Follow_Upcheckbox__c == true && a.Follow_Upcheckbox__c != trigger.oldMap.get(a.Id).Follow_Upcheckbox__c) {
                
                // Set Start Date
                Date dteStart = a.Follow_Up_Date__c;
                
                // Create Event
                Event newEvent = new Event();
                newEvent.OwnerId = UserInfo.getUserId(); // Sets the current userId as the Event Owner
                newEvent.WhoId = a.id; // Sets the Contact as the Event's Name
                newEvent.Whatid = a.Deal__c;
                newEvent.Subject = a.Follow_Up_Reason__c;
                newEvent.ActivityDate = a.Follow_Up_Date__c;
                newEvent.IsAllDayEvent = true;
                
                lstNewEvents.add(newEvent);
                
            }
        }
        
        if(lstNewEvents.size() > 0) { insert lstNewEvents; }
        
    }

}

Any Ideas or help - more then appreciated


Thanks in advance


  • January 07, 2012
  • Like
  • 0

Hi All, and thanks for taking the time to look at my question.

I recently ran into an error when trying to deploy - not enough coverage across the org. So I've been going through my classes one by one and increasing code coverage. However, I have a problem. Often the coverage that displays in my org's control panel doesn't reflect the values I see when testing in the sandbox.

I found this question:

http://boards.developerforce.com/t5/Apex-Code-Development/Different-code-coverage-in-Sandbox-and-Production/td-p/71962

and decided to run the tests on the prod org in the eclipse ide. I got the same values as in the sandbox, but my org still shows less!

Does anyone have any ideas?

  • September 07, 2011
  • Like
  • 0

Greetings listers,

 

I'm encountering the infamous "AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object" message....  line 70, column 13, here's my code snippet where I'm running into the problem:

 

        AccountTeamMember atm;
        AccountTeamMember[] atmsToInsert = new AccountTeamMember[0];
        User u;
        index=0;
        for(Account a : accts) {
            if (a.OwnerId == Null) system.assertequals(1,2);
//            system.assertequals(3,4);
            atm.UserId = a.OwnerId;                          //this is line 70, where the error is occurring.

 

What am I missing?  Thanks for any assistance.  (a.OwnerId successfully holds the account owner Id).

 

Pete

Hi,

 

I am attempting to query the number of rows I have for a particular object, so that if there are 0 objects, I don't operate.

 

I have tried the following line (this is the first line of code, which is called from an VisualForce ActionButton):

 

Integer Total_size = [select COUNT() from invoice__c where Week__c = :Current_Week_Ending.id];

I get the following error:

System.NullPointerException: Attempt to de-reference a null object

 
Any ideas why this happens? how can I verify that there are no objects before I work on it? for now, I will get the list and check it's size, but I think it's less efficient.

 

Thanks,

 

Ben 

 

  • February 16, 2010
  • Like
  • 0

I'm attempting to set a value for the custom variable "recordOwner".  When I click the "changeOwner" button below, I get the error:

 

"Error: Unknown property 'myLeadConvert.recordOwner'"

 

Any ideas on where I've gone wrong (presumabley a get/set issue):

 

apex:page standardController="Lead" extensions="myLeadConvert" title="Lead">
    <apex:outputField value="{!lead.Company}" rendered="false" />
    <apex:outputField value="{!lead.OwnerId}" rendered="false" />
    <apex:outputField value="{!lead.IsConverted}" rendered="false" />
    <apex:form id="theForm">  
        <apex:pageBlock title="Convert Lead - {!lead.Name} - Confirm Ownership" mode="maindetail">
            <apex:pageMessages escape="false"  />

            <apex:pageBlockSection title="Set Owner" columns="2" collapsible="false" >
				<apex:pageBlockSectionItem >
	        	<apex:outputLabel value="Opportunity Owner" for="userList"/>
	                 <apex:selectList value="{!recordOwner}" id="userList" size="1" >
	                     <apex:selectOptions value="{!userList}" />
	                 </apex:selectList>
				</apex:pageBlockSectionItem>
				<apex:pageBlockSectionItem />
				<apex:commandButton action="{!changeOwner}" value="Change Owner" />
            </apex:pageBlockSection>

            <apex:commandButton action="{!cancel}" value="Cancel" />            
        </apex:pageBlock>     
    </apex:form>
</apex:page>

 

public with sharing class myLeadConvert {
    public Lead myLead;
	public genHelpers gh;
	public sfMailer um;

	// record owner
    public User recordOwner;

    public uptimeLeadConvert (ApexPages.StandardController stdController) {
    	this.gh		= new genHelpers();
    	this.um		= new sfMailer();
        this.myLead = (Lead)stdController.getRecord();
        if(this.myLead.IsConverted == true) {
        	viewConvLead();
        	return;
        } 
        this.myLead.Status = 'Qualified - Pending';
    }

		public PageReference changeOwner() { 
			return null;
		}

	

	// page Reference Methods
        public PageReference viewConvLead() {
        	PageReference pg = new PageReference(this.myLead.Id);
            if(this.myLead.IsConverted == true) { 
                this.myLead.addError( 'ERROR: The lead has already been converted, you cannot convert again' );
	            pg         = new PageReference('/apex/myConvLeadView?id=' + this.myLead.Id);
	            pg.setRedirect(true);
            }
            return pg;
        }



    // Record Owner Routines for created Account/Contact/Opp
		public List<SelectOption> getUserList() { 
			Profile p = this.gh.getProfile('up.time Sales User');
			List<User> uList = [select Id, Name from User where IsActive = true AND ProfileId  = :p.Id AND UserType = 'Standard' order by Name];
			List<SelectOption> selList = new List<SelectOption>();
			
			//if(this.getRecordOwner() <> null)
			//	selList.add(new SelectOption(String.valueOf(this.recordOwner.Id), this.getRecordOwner().Name));
			selList.add(new SelectOption('', '--None--'));
				
	        for(User u : uList) 
	            selList.add(new SelectOption(String.valueOf(u.Id), u.Name));
			return selList;
		}   
    
		public User getRecordOwner() {
	    	if(this.recordOwner == null)
	    		this.recordOwner = [select Id, Name from User where Id = :this.myLead.OwnerId];
			return this.recordOwner;
		}

	    public void setRecordOwner(User myRecordOwner) {
	        this.recordOwner = myRecordOwner;
	    }	




}

 


Hello,

 

Over the weekend, our sandbox was upgraded to Winter '12, and many of my Apex tests have failures now.

 

For instance, I have a test that tries to save a Lead without a Last Name (which should lead to an error for a required field missing).

 

My test:

 

static testMethod void testExceptionsConvertCloseNoLead() { 
  myGenHelpers gh = new myGenHelpers();
		
  Lead testLead = gh.getUptimeTestLead();
  insert testLead;
	            	
  testLead.LastName = null;
	            	
   myLeadConvertCloseExtension lcc = new myLeadConvertCloseExtension(new ApexPages.StandardController(testLead));
   lcc.save();
}

 

Last week, and still in production, this test passes successfully.  However, today, it fails.

 

The problem is in this code segment:

 

                try {
	                update this.myLead;
                } catch (DmlException e) {
                    for (Integer i = 0; i < e.getNumDml(); i++) {
				    	System.debug('myClass.save: error: ' + e.getDmlMessage(i));
                        this.myLead.addError(e.getDmlMessage(i)); 
                    }
                    return null;
                }

 

Instead the error being handled gracefully, the test just fails at the upsert.

 

Any thoughts?

I have a custom page layout where I've had to mimic the related list:

 

            <apex:dataTable styleClass="list" value="{!relatedEmailMessages}" var="h" rows="10" rendered="{!showRelatedEmailMessages}" >
                <apex:column headerValue="Action">
                    <nobr><strong>
					<a href="javascript&colon;srcUp(%27%2F_ui%2Fcore%2Femail%2Fauthor%2FEmailAuthor%3Femail_id%3D{!h.Id}%26replyToAll%3D0%26retURL%3D%252F{!myCase.Id}%27)">Reply</a> | 
					<a href="javascript&colon;srcUp(%27%2F_ui%2Fcore%2Femail%2Fauthor%2FEmailAuthor%3Femail_id%3D{!h.Id}%26replyToAll%3D1%26retURL%3D%252F{!myCase.Id}%27)">To All</a> | 
					<a href="javascript&colon;srcUp(%2Fsetup%2Fown%2Fdeleteredirect.jsp%3Fisdtp%3Dmn%26delID%3D{!h.Id}%26retURL%3D%252F{!myCase.Id}%27)">To All</a> | 

                    <a href='/_ui/core/email/author/EmailAuthor?email_id={!h.Id}&replyToAll=0&retURL=%2F{!myCase.Id}'>Reply</a> | 
                    <a href='/_ui/core/email/author/EmailAuthor?email_id={!h.Id}&replyToAll=1&retURL=%2F{!myCase.Id}'>To All</a> |
                    <a href='/setup/own/deleteredirect.jsp?delID={!h.Id}&retURL=%2F{!myCase.Id}'>Del</a>
                    </strong></nobr>
                </apex:column>
                <apex:column headerValue="Status" value="{!h.Status}"/>
                <apex:column headerValue="Subject">
                    <a href='/{!h.Id}?retURL=%2F{!myCase.Id}'>{!h.Subject}</a> <br />
                    <i>{!IF(LEN(h.TextBody) > 75,LEFT(h.TextBody,75) + '...',h.TextBody)}</i>
                </apex:column>
                <apex:column headerValue="Email Address" value="{!h.FromAddress}"/>
                <apex:column headerValue="Message Date" value="{!h.MessageDate}"/>
            </apex:dataTable>

 

This fits in very well in the classic layout, as it looks like the other related lists.  However, the appearance is drastically different in the new layout.

 

Is it simply a matter of changing the styleClass to something other than "list"?

Hello,

 

I have found some documentation on developing for the Service Cloud console, but this does not seem to be the same as the Console.

 

For example, we have a Console layout for Standard Case, which has the List Views:

 

Case

Account

Contact

 

 

If the standard Case View is used, when a Case is loaded thorugh the console, the related Contact and Account are showin the right pane.

 

If I override with a Visualforce page, the Case appears fine, but the right pane is blank.


Any thoughts?

 

Hello,

 

We have a custom Visualforce page for our Case Detail page. 

 

In the Console, using the standard detail page, the right-pane shows a summary of info (Contact summary, Account summary).  When enabling our Visualforce page to override the "View" link, the right-pane is empty.

 

How do we maintain the console functionality here?

 

AT

Is there a way to detect if the current page has been loaded via the Console?

 

I have a Visualforce page to override our current Case object, and had to do some custom code to display the Case Email related list (this does not render via <apex:relatedList />).

 

The Case Email related list will fire javascript to load emails in another frame of the console - I want to mimic this behaviour by detecting if the user is viewing the Case in the console, and either display a link to fire the javascript or a regular link.

 

I'm trying out the new Jigsaw Functionality in SFDC.  The problem I'm experiencing is when I try to add Accounts from the application, it fails our validation rules.

 

Is there a way to identify, through the API, that the Jigsaw App is attempting to add records, and either skip the validation rules or populate the required fields with default data?

I'm using a commandButton on a Visualforce page to override the Case View.

 

<apex:commandButton action="{!clone}" value="Clone"  />

 

When clicking this, I get the following error:

 

"Return type of an Apex action method must be a PageReference. Found: core.apexpages.el.adapters.ApexObjectValueELAdapter"

 

Do I need to do a custom PageReference function in my extension class to handle this?  I thought I would be able to do this with a standard button?

https://cs3.salesforce.com/apex/uptimeCaseView?id=500Q0000003JhDe

When using dependent picklists on an Edit page (displayed in an apex:inputField), dependent picklists work fine.

 

However, when displaying in an apex:outputField (on a view page) and using inlineEditSupport to allow a change to the field, the dependent picklist doesn't appear to work.

 

 

                <apex:outputField value="{!case.Priority}" >
                    <apex:inlineEditSupport showOnEdit="saveButton, cancelButton"
                    hideOnEdit="editButton"  event="ondblclick"
                    changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>                
                </apex:outputField>

 

Is there a workaround here?  I'm considering doing some experimentation with jquery to switch the input/output field visibility as a workaround, but if there's a better solution, I'm all ears.

 

Is there a way to mimic the "Back to" link and top quick links (to related lists) at the top of a visualforce page?

 

 

I have a Visualforce page to override our Case View page, however, having problems with the following relatedLists:

 

   <apex:relatedlist list="CaseComments" />
   <apex:relatedList list="EmailMessages" />
   <apex:relatedlist list="NotesandAttachments" />
   <apex:relatedList list="CaseHistories" />

 

All are resulting in the "is not a valid child relationship name for entity Case".  Any thoughts?

 

I have setup a utility on our website to create cases in SFDC through the API (rather than Web-to-Case).  However, the result is now that the Case Auto Resposne does not fire.

 

I saw a workaround for this for creating cases via APEX by setting the DMLOptions : http://boards.developerforce.com/t5/General-Development/Case-auto-response-rules-not-firing-when-created-through-API/m-p/150150#M34456

 

Any idea if this can be accomplished via PHP through the API?

 

AT

Hello,


I've created a VF page, and when I load w/o the 'renderAs="pdf"', it loads fine.

 

When I add 'renderAs="pdf"', the browser just spins and takes ages to return.

 

Why would this be happening?

 

 

Has anyone done much work with rendering a Visualforce page as an Excel file, then styling the document.  In particular:

 

- forcing no text wrapping within cell or merging 2 cells to show long lines of content

- borders around blocks of cells

In my apex:pageMessages section, if an error message (from a Validation Rule) is displayed, it changes the quotes to their HTML entity, i.e. instead of ", it displays as &quot;

 

Is there a way to prevent this from happening?

I am trying to use the jQuery library for some visual effects for an Opportunity screen.

 

Currently, the below works fine for the view screen, where the div with id "size_details" will show/hide based on the mouse clicks for the href tag.

 

 

	<apex:includeScript value="{!URLFOR($Resource.jquery, '/js/jquery-1.4.4.min.js')}"  />
	<apex:includeScript value="{!URLFOR($Resource.jquery, '/js/jquery-ui-1.8.10.custom.min.js')}"  />
	<apex:stylesheet value="{!URLFOR($Resource.jquery, '/css/ui-lightness/jquery-ui-1.8.10.custom.css')}"  />
	<script type="text/javascript">
		jQuery.noConflict();
	     
	   jQuery(document).ready(function($) {
	        $("#pnl_details").hide();
	 
	        $('#viewSizeDetails').click(function () {
	            if ($("#size_details").is(":hidden")) {
	                $("#size_details").slideDown("slow");
	                $("#viewSizeDetails").html("Hide Scope and Size Details");
	                 return false;
	            } else {
	                $("#size_details").hide("slow");
	                $("#viewSizeDetails").html("Show Scope and Size Details");
	             return false;
	            }
	        });        

	        $('#viewGapDetails').click(function () {
	            if ($("#gap_details").is(":hidden")) {
	                $("#gap_details").slideDown("slow");
	                $("#viewGapDetails").html("Hide Gap Details");
	                 return false;
	            } else {
	                $("#gap_details").hide("slow");
	                $("#viewGapDetails").html("Show Gap Details");
	             return false;
	            }
	        });   
	        
	        
	        
	        $('#scopeSizeCheckbox').click(function () {
	            if ($("#size_details").is(":hidden")) {
	                $("#size_details").slideDown("slow");
	                $("#viewSizeDetails").html("Hide Gap Details");
	                 return false;
	            } else {
	                $("#size_details").hide("slow");
	                $("#viewSizeDetails").html("Show Gap Details");
	             return false;
	            }
	        });   
	        
	        
	    });
	</script>

 

 

 

            <apex:pageBlockSection title="Do we know the scope and size?" columns="2"  collapsible="false">
                <apex:pageBlockSectionItem labelStyleClass="oppCheckboxLabel" dataStyleClass="oppCheckbox" >
					<apex:outputLabel value="True?" />
                    <apex:outputField value="{!opportunity.Do_we_know_the_scope_and_size__c}" />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem labelStyleClass="oppInfoLabel" 
                    dataStyleClass="oppInfoBox">
                    <apex:outputLabel value="Info" for="primary4Info"/>
                    <apex:outputField id="primary4Info" 
                    value="{!opportunity.Do_we_know_the_scope_and_size_info__c}" 
                    styleClass="oppInfoTextArea" />
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>   
                        

			<p style="padding-left:35px; display:{!if(opportunity.Do_we_know_the_scope_and_size__c==True,'block','none')}"><a id="viewSizeDetails" href="#">Show Scope and Size Details</a></p>
			<!--Use a Standard Div not an apex outputpanel simplifies selection process for jQuery no need for !$Component to get the element id-->  
			<div id="size_details" style='padding-left:35px; display:none'>
	            <c:oppSizeInfoView opportunity="{!opportunity}" rendered="{!if(opportunity.Do_we_know_the_scope_and_size__c==True,True,False)}" />
			</div>
			

 

 

 

However, now I want to get the same effect (showing/hiding the div) when the input Field is changed on the Edit Screen:

 

 

            
            <apex:pageBlockSection title="Do we know the scope and size?" columns="2"  collapsible="false">
                <apex:pageBlockSectionItem id="scopeSizeCheckbox" labelStyleClass="oppCheckboxLabel" dataStyleClass="oppCheckbox" >
					<apex:outputLabel value="True?" />
                    <apex:inputField value="{!opportunity.Do_we_know_the_scope_and_size__c}" />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem labelStyleClass="oppInfoLabel" 
                    dataStyleClass="oppInfoBox">
                    <apex:outputLabel value="Info" for="primary4Info"/>
                    <apex:inputField id="primary4Info" 
                    value="{!opportunity.Do_we_know_the_scope_and_size_info__c}" 
                    styleClass="oppInfoTextArea" />
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>   


			<!--Use a Standard Div not an apex outputpanel simplifies selection process for jQuery no need for !$Component to get the element id-->  
			<div id="size_details" style="padding-left:35px; display:{!if(opportunity.Do_we_know_the_scope_and_size__c==True,'block','none')}">
	            <c:oppSizeInfo opportunity="{!opportunity}" />
			</div>
			             

 

 

The change is not detected for the inputField, because the HTML created from the page does not use that as the actual id of the checkbox field.


Has anyone integrated jquery with onChange events for input Fields?

 

 

 

I know we can set the content-type header in visualforce using the contenttype attribute for <apex:page>, but can we set Content-Disposition?  E.g.

 

Content-Disposition:attachment;filename=myfile.xls

 

 

Is there a way to mimic the standard EmailMessage Screen, to utilize templates, contact lookups, etc?

 

I'm looking for a way to create a new interface, so users can update related Cases while sending out and email, however, don't want to lose any of the existing functionality of the EmailMessage interface.

I have a visualforce page which exports to excel (using contenttype="application/vnd.ms-excel" in the apex:page declaration).

 

The problems I'm having are:

 

1) my static resource (image appears as a broken image:

 

            <apex:pageBlockSectionItem ><apex:image url="{!$Resource.myLogo}" width="218" height="80" /></apex:pageBlockSectionItem>

 

 

2) My styles (borders) aren't exporting:

 

 

        <apex:pageBlockTable title="Part List" value="{!partList}" var="pl">
            <apex:column headerClass="partListHeader" styleClass="partListItem" value="{!pl.ProductCode__c}" headervalue="Part No." />
            <apex:column headerClass="partListHeader" styleClass="partListItem" value="{!pl.Description}"  headervalue="Description" />
....

 

 

Any idea if either of these can be ameliorated?

 

 

 

I have a checkbox field, which in my Visualforce page am displaying as 2 radio fields (by request from the business).

 

When trying to set which option is checked, I am always getting the second checked, even if I have checked="false" or checked="".  I cannot seem to set checked=false.

 

 

<apex:pageBlockSectionItem labelStyleClass="checkboxLabel" dataStyleClass="myCheckbox" id="primary1YesBox">
    <apex:outputLabel value="Yes" for="primary1True"/>
        <input type="radio" name="primary1" value="True" id='primary1True'
        onclick="document.getElementById('{!$Component.customField__c}').checked=true" 
        checked="{!IF(opportunity.customField__c=true,'checked','')}" 
        />
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem labelStyleClass="checkboxLabel" dataStyleClass="myCheckbox">
    <apex:outputLabel value="No" for="primary1False"/>
        <input type="radio" name="primary1" value="False" id='primary1False'
        onclick="document.getElementById('{!$Component.customField__c}').checked=false" 
                       checked="{!IF(opportunity.customField__c=false,'checked','')}" />              
</apex:pageBlockSectionItem>

 

 

Right now, the 2nd options is always checked.  How can I get this running so that the first option is checked when customField__c is true?

 

This afternoon, one of our users started seeing "Insufficient Privileges" messages on a specific case record when trying to reply or send an Email.

 

This is only happening for this specific case, not for other case records.

 

Any thoughts?

I have an APEX Trigger that runs when a Task is created/updated, so it can update the related Case. 

 

Somehow, the trigger is causing the Case Assignment Rules to re-fire, but I don't know what.  Any thoughts?

 

 

 

trigger caseLastActivityDate on Task (after insert, after update) { Map<String, Task> tMap = new Map<String, Task>(); for (Task t : System.Trigger.new) { String whatId = t.WhatId; System.debug('whatId is ' + whatId); if(whatId <> null && whatId.startsWith('500') == true) { Case c = [select Id from Case where Id = :whatId]; if(c.Id <> null) { c.Last_Activity_Date__c = t.LastModifiedDate; update c; } } } }

 

 

 

Hello,

 

I am creating a visualforce page, and want to set the tabStyle attribute based on Record Type.  However, when open the visualforce page with the following (where MyTabStyle is a string like 'contact', 'account', etc).

 

 

 

 

<apex:page standardController="Opportunity" extensions="myOppExtension" tabStyle="{!MyTabStyle}">

 

 

I get an error "Error: Invalid tabStyle '{!MyTabStyle}' specified. If you are trying to reference a custom Visualforce tab, you must append '__tab'".

 

Is setting the tabStyle this way supported?

 

Thank you

 

Hi all -

 

This is my test class:

 

@isTest
private class testAutomaticFollowUp {

    public static testMethod void unitTestAutomaticFollowUp() {

        Contact acct = new Contact();
        acct.Name = 'Test Contact';
acct.Follow_Up_Date__c = Date.newInstance(2011,5,1);


        insert acct;

        test.startTest();

        acct.Follow_Upcheckbox__c = true;
        update acct;

        test.stopTest();

    }
}

 

I get the error:

 

Error: Compile Error: Field is not writeable: Contact.Name at line 7 column 9

 

Here is the Trigger:

 

trigger AutomaticFollowUp on Contact (before update) {

    ////////////////////////////////////
    // This trigger detects the change of the Followup field
    // and creates an Event
    ////////////////////////////////////
    
    if(trigger.isUpdate && trigger.isBefore) {
        
        // Create empty List to hold new Events (bulk DML) 
        List<Event> lstNewEvents = new List<Event>();
        
        for(Contact a : trigger.new) {
            
            // Determine if the checkbox is TRUE and the user has just flipped it from FALSE.
            if(a.Follow_Upcheckbox__c == true && a.Follow_Upcheckbox__c != trigger.oldMap.get(a.Id).Follow_Upcheckbox__c) {
                
                // Set Start Date
                Date dteStart = a.Follow_Up_Date__c;
                
                // Create Event
                Event newEvent = new Event();
                newEvent.OwnerId = UserInfo.getUserId(); // Sets the current userId as the Event Owner
                newEvent.WhoId = a.id; // Sets the Contact as the Event's Name
                newEvent.Whatid = a.Deal__c;
                newEvent.Subject = a.Follow_Up_Reason__c;
                newEvent.ActivityDate = a.Follow_Up_Date__c;
                newEvent.IsAllDayEvent = true;
                
                lstNewEvents.add(newEvent);
                
            }
        }
        
        if(lstNewEvents.size() > 0) { insert lstNewEvents; }
        
    }

}

Any Ideas or help - more then appreciated


Thanks in advance


  • January 07, 2012
  • Like
  • 0

I'm attempting to set a value for the custom variable "recordOwner".  When I click the "changeOwner" button below, I get the error:

 

"Error: Unknown property 'myLeadConvert.recordOwner'"

 

Any ideas on where I've gone wrong (presumabley a get/set issue):

 

apex:page standardController="Lead" extensions="myLeadConvert" title="Lead">
    <apex:outputField value="{!lead.Company}" rendered="false" />
    <apex:outputField value="{!lead.OwnerId}" rendered="false" />
    <apex:outputField value="{!lead.IsConverted}" rendered="false" />
    <apex:form id="theForm">  
        <apex:pageBlock title="Convert Lead - {!lead.Name} - Confirm Ownership" mode="maindetail">
            <apex:pageMessages escape="false"  />

            <apex:pageBlockSection title="Set Owner" columns="2" collapsible="false" >
				<apex:pageBlockSectionItem >
	        	<apex:outputLabel value="Opportunity Owner" for="userList"/>
	                 <apex:selectList value="{!recordOwner}" id="userList" size="1" >
	                     <apex:selectOptions value="{!userList}" />
	                 </apex:selectList>
				</apex:pageBlockSectionItem>
				<apex:pageBlockSectionItem />
				<apex:commandButton action="{!changeOwner}" value="Change Owner" />
            </apex:pageBlockSection>

            <apex:commandButton action="{!cancel}" value="Cancel" />            
        </apex:pageBlock>     
    </apex:form>
</apex:page>

 

public with sharing class myLeadConvert {
    public Lead myLead;
	public genHelpers gh;
	public sfMailer um;

	// record owner
    public User recordOwner;

    public uptimeLeadConvert (ApexPages.StandardController stdController) {
    	this.gh		= new genHelpers();
    	this.um		= new sfMailer();
        this.myLead = (Lead)stdController.getRecord();
        if(this.myLead.IsConverted == true) {
        	viewConvLead();
        	return;
        } 
        this.myLead.Status = 'Qualified - Pending';
    }

		public PageReference changeOwner() { 
			return null;
		}

	

	// page Reference Methods
        public PageReference viewConvLead() {
        	PageReference pg = new PageReference(this.myLead.Id);
            if(this.myLead.IsConverted == true) { 
                this.myLead.addError( 'ERROR: The lead has already been converted, you cannot convert again' );
	            pg         = new PageReference('/apex/myConvLeadView?id=' + this.myLead.Id);
	            pg.setRedirect(true);
            }
            return pg;
        }



    // Record Owner Routines for created Account/Contact/Opp
		public List<SelectOption> getUserList() { 
			Profile p = this.gh.getProfile('up.time Sales User');
			List<User> uList = [select Id, Name from User where IsActive = true AND ProfileId  = :p.Id AND UserType = 'Standard' order by Name];
			List<SelectOption> selList = new List<SelectOption>();
			
			//if(this.getRecordOwner() <> null)
			//	selList.add(new SelectOption(String.valueOf(this.recordOwner.Id), this.getRecordOwner().Name));
			selList.add(new SelectOption('', '--None--'));
				
	        for(User u : uList) 
	            selList.add(new SelectOption(String.valueOf(u.Id), u.Name));
			return selList;
		}   
    
		public User getRecordOwner() {
	    	if(this.recordOwner == null)
	    		this.recordOwner = [select Id, Name from User where Id = :this.myLead.OwnerId];
			return this.recordOwner;
		}

	    public void setRecordOwner(User myRecordOwner) {
	        this.recordOwner = myRecordOwner;
	    }	




}

 


Hello,

 

Over the weekend, our sandbox was upgraded to Winter '12, and many of my Apex tests have failures now.

 

For instance, I have a test that tries to save a Lead without a Last Name (which should lead to an error for a required field missing).

 

My test:

 

static testMethod void testExceptionsConvertCloseNoLead() { 
  myGenHelpers gh = new myGenHelpers();
		
  Lead testLead = gh.getUptimeTestLead();
  insert testLead;
	            	
  testLead.LastName = null;
	            	
   myLeadConvertCloseExtension lcc = new myLeadConvertCloseExtension(new ApexPages.StandardController(testLead));
   lcc.save();
}

 

Last week, and still in production, this test passes successfully.  However, today, it fails.

 

The problem is in this code segment:

 

                try {
	                update this.myLead;
                } catch (DmlException e) {
                    for (Integer i = 0; i < e.getNumDml(); i++) {
				    	System.debug('myClass.save: error: ' + e.getDmlMessage(i));
                        this.myLead.addError(e.getDmlMessage(i)); 
                    }
                    return null;
                }

 

Instead the error being handled gracefully, the test just fails at the upsert.

 

Any thoughts?

Hi All, and thanks for taking the time to look at my question.

I recently ran into an error when trying to deploy - not enough coverage across the org. So I've been going through my classes one by one and increasing code coverage. However, I have a problem. Often the coverage that displays in my org's control panel doesn't reflect the values I see when testing in the sandbox.

I found this question:

http://boards.developerforce.com/t5/Apex-Code-Development/Different-code-coverage-in-Sandbox-and-Production/td-p/71962

and decided to run the tests on the prod org in the eclipse ide. I got the same values as in the sandbox, but my org still shows less!

Does anyone have any ideas?

  • September 07, 2011
  • Like
  • 0

I want to hide and display two sections based on a user input to a checkbox. In my page I have two sections called section1 and section2. I want to display only section1 when user checks the check box. And display only section2 when user unchecks check box. This works only for section1.

 

<apex:page controller="Sample" >
  <apex:form >  
      <apex:pageBlock id="trainersBlock">
          <apex:inputCheckbox id="isEmp" value="{!isChecked}" >
              <apex:actionsupport event="onclick" rerender="SampleView" />
          </apex:inputCheckbox>
          
          <apex:outputPanel id="SampleView">
              <apex:pageBlockSection rendered="{!isChecked}">
                  <apex:pageblockSectionItem >
                  <apex:outputlabel value="Section 1"/>
                  </apex:pageblockSectionItem>                           
              </apex:pageBlockSection>
              <apex:pageBlockSection rendered="{!isChecked} == false">
                  <apex:pageblockSectionItem >
                  <apex:outputlabel value="Section 2"/>  
                  </apex:pageblockSectionItem>                        
              </apex:pageBlockSection>
          </apex:outputPanel>
       </apex:pageBlock>
  </apex:form>
</apex:page>

 Controller:

public class Sample {

    public String isChecked { get; set; }
}

 

  • July 02, 2011
  • Like
  • 0

I'm using a commandButton on a Visualforce page to override the Case View.

 

<apex:commandButton action="{!clone}" value="Clone"  />

 

When clicking this, I get the following error:

 

"Return type of an Apex action method must be a PageReference. Found: core.apexpages.el.adapters.ApexObjectValueELAdapter"

 

Do I need to do a custom PageReference function in my extension class to handle this?  I thought I would be able to do this with a standard button?

https://cs3.salesforce.com/apex/uptimeCaseView?id=500Q0000003JhDe

Is there a way to mimic the "Back to" link and top quick links (to related lists) at the top of a visualforce page?

 

 

I have a Visualforce page to override our Case View page, however, having problems with the following relatedLists:

 

   <apex:relatedlist list="CaseComments" />
   <apex:relatedList list="EmailMessages" />
   <apex:relatedlist list="NotesandAttachments" />
   <apex:relatedList list="CaseHistories" />

 

All are resulting in the "is not a valid child relationship name for entity Case".  Any thoughts?

 

My code is working but it's certainly not optimized so I'm hoping for tips on how to clean this up...

 

The code is tracking students (Attend_Record__c) who attended attended class (Class__c) on a specific date (Attendance__c).   The object hierarchy would be Attendance__c is the parent to Attend_Record__c.  Class__c is a lookup object to Attendance__c.

 

When attendance is being taken for the student (Attend_Record__c) the only value entered is a Student_Id__c.  Based on that field, I resolve a variety of other fields:

  1. determine the ContactID (the actual student record)
  2. add the Class__c.Id and School (Account ID) fields
  3. determine the status of the student's contract and the type of contract (this will come either from an object that all users have access to (Student_Lookup__c) or from the contract (limited access)

I'm not sure how to implement best practices when I need to retrieve data from 3 or 4 different places.  How would you consolidate this to optimize it?

 

trigger trgAttendRecord_GetContactBasedOnStudentId on Attend_Record__c (before insert, before update) {
  // This trigger populates Attend_Record__c.Student__c based on the data entered in Attend_Record__c.Student_Id__c
  
  // if we already have the status, there is no need to run this code.  Also allows mass data loading
  if (trigger.new[0].Status__c > '') {
    if (trigger.new[0].Update_Status__c == false) return;
    if (trigger.new[0].Update_Status__c == null) return;
  }
  
  
  // step 1 - retrieve the student id from Student_Lookup__c.Student_ContactID__c
  set<string> SI = new set<string>();  
  set<Id> AttendId = new set<Id>();  
  for (Attend_Record__c arc : trigger.new) {
    if (arc.Student_Id__c == null) {
      continue ;
    }
    if (arc.Student_Id__c == '') {
      continue ;
    }
    SI.add(arc.Student_Id__c);
    AttendId.add(arc.Attendance_For__c);
  }
  
  
  // step 2 - create a map of the StudentIds and ContactIds for reference    
  map<string, string> StudentIdMap = new map<string, string>();
  for (Student_Lookup__c s:[select Student_Id__c, Student_ContactID__c from Student_Lookup__c where Student_Id__c IN :SI])  
    StudentIdMap.put(s.Student_Id__c, s.Student_ContactID__c);
  
  
  // step 3 - get parent (Attendance__c) field vaules
  string txtClass = null;
  string txtSchool = null;
  for (Attendance__c[] ac2 : [Select a.Id, a.Class__c, a.Class__r.School__c from Attendance__c a where a.Id IN :AttendId]) {
    for (Attendance__c a : ac2) {
      txtClass = a.Class__c;
      txtSchool = a.Class__r.School__c; 
    }
  }
  
  
  // step 4 - resolve the student id to return the ContactId and status
  for (Attend_Record__c arc2 : Trigger.new) {
    // reset Update_Status__c flag
    arc2.Update_Status__c=false;
    
    // get the Student's ContactId
    arc2.Student__c = StudentIdMap.get(arc2.Student_Id__c);
    
    // Check Student Role - if empty set it to Student
    if (arc2.Role__c == '') arc2.Role__c = 'Student';
    
    // set default for Program name
    arc2.Program__c = '';
    
    // get Student's Class Status
    List<Student_Lookup__c> slc = [Select s.School_ClassID__c, s.School_AccountID__c, s.Program_Name__c from Student_Lookup__c s  where s.Student_ID__c = :arc2.Student_Id__c];
    for (Student_Lookup__c sl: slc) {
      // set Program name
      arc2.Program__c = sl.Program_Name__c;
      
      // set agreement Status
      if (sl.School_ClassID__c == txtClass) {
        arc2.Status__c = 'Student';
      } else if (sl.School_AccountID__c == txtSchool) {
        arc2.Status__c = 'Guest Time';
      } else arc2.Status__c = 'Guest Location';
    }

    if (slc.isEmpty()) {
      // set agreement Status
      List<contract> c = [Select c.EndDate, c.Student__c from Contract c where c.Student_ID__c = :arc2.Student_Id__c order by c.EndDate asc];
      if (c.isEmpty()) {
        arc2.Status__c = 'No Agreement';
      } else {
        for (contract c2 : c) {
          arc2.Student__c = c2.Student__c;
        }
        arc2.Status__c = 'Expired Agreement';
      }
    }    
  }
}

 Thanks

Hello,


I've created a VF page, and when I load w/o the 'renderAs="pdf"', it loads fine.

 

When I add 'renderAs="pdf"', the browser just spins and takes ages to return.

 

Why would this be happening?

 

 

In my apex:pageMessages section, if an error message (from a Validation Rule) is displayed, it changes the quotes to their HTML entity, i.e. instead of ", it displays as &quot;

 

Is there a way to prevent this from happening?

I am trying to use the jQuery library for some visual effects for an Opportunity screen.

 

Currently, the below works fine for the view screen, where the div with id "size_details" will show/hide based on the mouse clicks for the href tag.

 

 

	<apex:includeScript value="{!URLFOR($Resource.jquery, '/js/jquery-1.4.4.min.js')}"  />
	<apex:includeScript value="{!URLFOR($Resource.jquery, '/js/jquery-ui-1.8.10.custom.min.js')}"  />
	<apex:stylesheet value="{!URLFOR($Resource.jquery, '/css/ui-lightness/jquery-ui-1.8.10.custom.css')}"  />
	<script type="text/javascript">
		jQuery.noConflict();
	     
	   jQuery(document).ready(function($) {
	        $("#pnl_details").hide();
	 
	        $('#viewSizeDetails').click(function () {
	            if ($("#size_details").is(":hidden")) {
	                $("#size_details").slideDown("slow");
	                $("#viewSizeDetails").html("Hide Scope and Size Details");
	                 return false;
	            } else {
	                $("#size_details").hide("slow");
	                $("#viewSizeDetails").html("Show Scope and Size Details");
	             return false;
	            }
	        });        

	        $('#viewGapDetails').click(function () {
	            if ($("#gap_details").is(":hidden")) {
	                $("#gap_details").slideDown("slow");
	                $("#viewGapDetails").html("Hide Gap Details");
	                 return false;
	            } else {
	                $("#gap_details").hide("slow");
	                $("#viewGapDetails").html("Show Gap Details");
	             return false;
	            }
	        });   
	        
	        
	        
	        $('#scopeSizeCheckbox').click(function () {
	            if ($("#size_details").is(":hidden")) {
	                $("#size_details").slideDown("slow");
	                $("#viewSizeDetails").html("Hide Gap Details");
	                 return false;
	            } else {
	                $("#size_details").hide("slow");
	                $("#viewSizeDetails").html("Show Gap Details");
	             return false;
	            }
	        });   
	        
	        
	    });
	</script>

 

 

 

            <apex:pageBlockSection title="Do we know the scope and size?" columns="2"  collapsible="false">
                <apex:pageBlockSectionItem labelStyleClass="oppCheckboxLabel" dataStyleClass="oppCheckbox" >
					<apex:outputLabel value="True?" />
                    <apex:outputField value="{!opportunity.Do_we_know_the_scope_and_size__c}" />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem labelStyleClass="oppInfoLabel" 
                    dataStyleClass="oppInfoBox">
                    <apex:outputLabel value="Info" for="primary4Info"/>
                    <apex:outputField id="primary4Info" 
                    value="{!opportunity.Do_we_know_the_scope_and_size_info__c}" 
                    styleClass="oppInfoTextArea" />
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>   
                        

			<p style="padding-left:35px; display:{!if(opportunity.Do_we_know_the_scope_and_size__c==True,'block','none')}"><a id="viewSizeDetails" href="#">Show Scope and Size Details</a></p>
			<!--Use a Standard Div not an apex outputpanel simplifies selection process for jQuery no need for !$Component to get the element id-->  
			<div id="size_details" style='padding-left:35px; display:none'>
	            <c:oppSizeInfoView opportunity="{!opportunity}" rendered="{!if(opportunity.Do_we_know_the_scope_and_size__c==True,True,False)}" />
			</div>
			

 

 

 

However, now I want to get the same effect (showing/hiding the div) when the input Field is changed on the Edit Screen:

 

 

            
            <apex:pageBlockSection title="Do we know the scope and size?" columns="2"  collapsible="false">
                <apex:pageBlockSectionItem id="scopeSizeCheckbox" labelStyleClass="oppCheckboxLabel" dataStyleClass="oppCheckbox" >
					<apex:outputLabel value="True?" />
                    <apex:inputField value="{!opportunity.Do_we_know_the_scope_and_size__c}" />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem labelStyleClass="oppInfoLabel" 
                    dataStyleClass="oppInfoBox">
                    <apex:outputLabel value="Info" for="primary4Info"/>
                    <apex:inputField id="primary4Info" 
                    value="{!opportunity.Do_we_know_the_scope_and_size_info__c}" 
                    styleClass="oppInfoTextArea" />
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>   


			<!--Use a Standard Div not an apex outputpanel simplifies selection process for jQuery no need for !$Component to get the element id-->  
			<div id="size_details" style="padding-left:35px; display:{!if(opportunity.Do_we_know_the_scope_and_size__c==True,'block','none')}">
	            <c:oppSizeInfo opportunity="{!opportunity}" />
			</div>
			             

 

 

The change is not detected for the inputField, because the HTML created from the page does not use that as the actual id of the checkbox field.


Has anyone integrated jquery with onChange events for input Fields?

 

 

 

Hello, I've created a trigger in order to create a case when a new product is added to an opportunity, according some rules.

But now, for a product added case is created more then once.

 

This is the trigger:

 

 

trigger NewProductAdded on OpportunityLineItem (after insert) {

//Query for Case record types
     List<RecordType> rtypes = [Select Name, Id From RecordType where sObjectType='Case' and isActive=true];
     
//Create a map between the Record Type Name and Id for easy retrieval
     Map<String,String> CampaignsRecordTypes = new Map<String,String>{};
     for(RecordType rt: rtypes)
     CampaignsRecordTypes.put(rt.Name,rt.Id);
     
//Query for Users 

    List<User> users = [Select Name, Id From User];
    
//Create a map between the User Name and Id for easy retrieval

     Map<String,String> CaseUsers = new Map<String,String>{};
     for(User  usr: Users)
     CaseUsers.put(usr.Name,usr.Id);
     
for (OpportunityLineItem oli : Trigger.new) 
 { 
     if (oli.Implementation_DirectTrack__c == 'Yes'& (oli.Approval_status__c == 'Approved by AD'))
        
    { 
       Case c = new Case ( 
       Opportunity__c = oli.OpportunityId, 
       Status = 'New', 
       Origin = 'Web', 
       Type = 'Internal Case', 
       Reason = 'Add Campaign to R-ADserver', 
       Description = 'Hello, a new product has been added. Please add campaign to R-Adserver',
       R_Adserver_Status__c = '',
       RecordTypeId=CampaignsRecordTypes.get('Traffic'),
       Account_Manager__c = oli.Account_Manager__c,
       OwnerId = CaseUsers.get('Traffic List') 
       ); 
       insert c; 
    }   
     else if (oli.Implementation_DirectTrack__c == 'No' & (oli.Approval_status__c == 'Approved by AD') )
    { 
       Case c = new Case ( 
       Opportunity__c = oli.OpportunityId, 
       Status = 'New', 
       Origin = 'Web', 
       Type = 'Internal Case', 
       Reason = 'Add Campaign to Emediate', 
       Description = 'Hello, a new product has been added. Please add campaign to Emediate',
       RecordTypeId=CampaignsRecordTypes.get('Traffic'),
              Account_Manager__c = oli.Account_Manager__c,
       OwnerId = CaseUsers.get('Traffic List')  
       ); 
       insert c; 
    } 
    else { } 
 }         

}

 

 

Any idea about how to fix it?

 

Many thanks in advance,

 

Stefano Di Leone

 

 

Is there a way to mimic the standard EmailMessage Screen, to utilize templates, contact lookups, etc?

 

I'm looking for a way to create a new interface, so users can update related Cases while sending out and email, however, don't want to lose any of the existing functionality of the EmailMessage interface.

Hi,

 

I have a class in sandbox and have it exported in a project in eclipse. When I run test for it in eclipse, it gives me 90% test coverage for it but when I run test in salesforce app front end it gives 75%. I have noticed that while running test in salesforce app it is not including the exception block as executed whereas in eclipse it does. I have put code in test method of that class to have the exception block executed.

 

to give you a brief about testmethod:

 

static testmethod void test1(){

 

try

{

.........test code for testing most part of the class

 

.......test code to generate exception so it can be caught in exception block below

 

}

 

catch(exception e)

{

....this exception block is empty in testmethod but has statements in class

}

 

} // end testmethod

 

 

Please help me out what can be possible cause of this issue and how it can be resolved.

 

Thanks!

 

  • November 10, 2010
  • Like
  • 0
I am in the process of converting a Web2Case form into a script that uses the API (version: 2.5) to add new cases. Unfortunately, having done so, it appears that emails automatically generated through the auto-response are no longer firing.  This is odd, because the debug log seems indicate that the auto-response rule is matching and firing appropriately:

Code:
Rule entry order: 1
[Case : Case Origin starts with ASSIST]
Value found: ASSIST (Support Web Site)
Criteria evaluates to true
Spooling All Immediate Actions
 [Case: 00009713 500T0000001emr9]
  Response notify: Caeli Collins, Email: caeli.collins@onstor.com
  Template: 00X00000006oqrQ

Am I reading the debug log incorrectly? The rule appears to match and spool up, but nothing is received.  With a little digging around, I found the triggerAutoResponseEmail switch which can be sent in the SOAP query, but I do not believe the old API that I am working with supports this. 

I should also note that I am working in the sandbox and that when attempting to create a case directly through the browser interface, I also do not receive the auto-response notifications.  Could this be the issue?

Thanks in advance.


Message Edited by charlesg on 09-10-2008 10:25 AM