• dkorba2k5
  • NEWBIE
  • 179 Points
  • Member since 2005

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

I know how to write a trigger for Lead Conversion, but what about a trigger to change the lead owner to the current user when Lead Status field is altered to a specific value?

 

The basic goal here is I have a workflow that creates tasks for the Lead Owner when the status of a lead is altered to "qualified".  However, the Lead Owner is not always the Current User who performed the status change.  So I need to alter the Lead Owner to the Current User prior to the status change so that the task is created for the Current User/New Lead Owner.  

 

Any guidance would be greatly appreciated, and thank you in advance.

  • January 27, 2010
  • Like
  • 0

On the task there is a WhatId and a WhoId. Sometimes the WhatId is filled in and others have the WhoId filled in. In which situations is one used over the other?

 

Thanks 

  • October 29, 2009
  • Like
  • 0

Hi All,

 

I have been trying to follow the example on how to do this - http://wiki.developerforce.com/index.php/VisualForceEmailTemplates_sample

 

I have a custom object with Contacts as a related list. I wish to be able to list the Contacts within the email template much like the sample above.

 

I receive the error  "Error: Invalid Field Contacts for SObject customobject__c" using the below:

 

<apex:repeat var="cx" value="{!relatedTo.Contacts}">
        {!cx.FirstName}
        {!cx.LastName}
</apex:repeat>

 

I am assuming the sample is applicable to custom objects. Any suggestions appreciated.

 

 

Is there any way to find out what records have been submitted for @future class processing to make sure that the same record is not being submitted again?

OK .. here's an interesting one.  I have a datatable that has a bunch of columns where we want to have scrollbars.  However, we need the first column to stay static, i.e. as I scroll horizontally it will always be there.  But if I scroll vertically, it needs to scroll with the rest of the rows.  Any ideas how to do this?

Strange problem with TabPanel tabs.  Renders fine on load.  After clicking on a tab, now the tabs have been spaced out.  Any idea why the styling would've changed just from simply selecting a tab?

Ok this is a strange two-part question/issue.

 

We have analytic snapshots that run once/week based on a report.  There are two issues we've just noticed with these.

 

1. For some reason, a couple of the date fields that are pulled from the report are storing an incorrect date.  The snapshot is due to run on a user in the PST timezone but the create and last modified dates from the report are storing an incorrect date in some cases.  If it's a record owned by a user in a different timezone, the snapshot is storing their date, not the person the context of the report is run as.

 

2. But more importantly, we have an apex controller class that pulls from the snapshot table a list of the snapshot dates.  These dates are showing up in each users local time zone settings when we need it to be consistent for all users.  So if the snapshot is run on 04-17-2010, then when we present the list of snapshots to all users they should see 04-17-2010.  not 04-18-2010 in some cases.


Here is the code that we're using to find the snapshot dates.  The goal is to create a selectlist for a VisualForce page to let the user choose which snapshot they want to run some analytics against.

 

 

	public List<SelectOption> getSnapShotDates() {
        List<SelectOption> optionList = new List<SelectOption>();
		Set <DateTime> snapdates = new Set <DateTime>();

// go get the most recent snapshot
		Analytics_Pipeline_Snapshots__c[] aps = 
			([SELECT Pipeline_Date__c 
			FROM Analytics_Pipeline_Snapshots__c 
			ORDER BY Pipeline_Date__c DESC LIMIT 1]);
// loop thru and create other snapshot dates one week before each one (up to 2 maximum)
		if (aps.size() > 0) {
			for (Integer i=0; i < 2; i++) {
				Datetime tempdate = datetime.newInstance(aps[0].pipeline_date__c.addDays(7 * -i).year(), 
														aps[0].pipeline_date__c.addDays(7 * -i).month(),
														aps[0].pipeline_date__c.addDays(7 * -i).day());
	            optionList.add(
	            	new SelectOption(String.valueof(tempdate.format('yyyy-MM-dd')),
	            					String.valueof(tempdate.format('yyyy-MM-dd'))));
			}
		}

        return optionList;
	}

 

 

 

 

 

 

 

Has anyone managed to have a VF Page with an active component (i.e. like a news area) that has the information pulled from data in SFDC and then has it scrolling vertically like a news ticker?  If so, any easy samples to share?  I can get the static content but trying to figure out how to get it to scroll on it's own.
when logging in as a customer portal user to check what we have set-up with VF/Apex, I need to have the Apex queries execute based on the portal user, not as my profile.  But it seems that the userinfo.getuserid() function is still acting with my id.  Is there anyway to get around this?  To have it use the context of the user I'm logged in as in the portal instead of my id?
In an attempt to make our application bulletproof I'm trying to figure out how to catch the error when a VF page is loaded and has a bad ID value (either missing or incorrect value for that standard controller).  We're able to catch all other scenario's but haven't been able to figure out how to process that error.
Will VF pages work with the offline edition?  Or will it default back to the standard page layouts?

We've overriden several pages with VF pages.  All works fine and when you click on the "Log a Call" button to create an activity it works fine.  But on Leads, the Log a Call button has an incorrect Return URL.  It doesn't have the lead records id included in it.  Any ideas?

 

A sample of the wrong URL looks like this:

 

https://cs1.salesforce.com/00T/e?title=Call&who_id=00Q00000004zANx&followup=1&tsk5=Call&retURL=%2Fapex%2Fleads

 

Notice the retURL is incomplete.  Here's a sample from a different overriden page object that is correct:

 

https://cs1.salesforce.com/00T/e?title=Call&what_id=a0200000000UqXV&followup=1&tsk5=Call&retURL=%2Fapex%2FQuote_Layout%3Fid%3Da0200000000UqXV%26sfdc.override%3D1

When we override the standard contact page with our own visualforce page, the customer portal functionality seems broken.  First off, a contact that is already set-up as a customer portal user shows the "Enable Customer Portal User" button when it shouldn't.  Second, the buttons for "Login as Portal User", "View Customer Portal User" and "Disable Customer Portal User" do not show up at all.

 

We're just using the standard <apex: detail> tag to render the page with some additions only in terms of related lists.

 

Any ideas?

Had the following functions in Apex added to our Leads page layout that worked great prior to the Summer '09 upgrade.  Now the performance on these is incredibly slow.  Any ideas?

 

 

public Lead[] getRelatedLeads() {return this.relatedleads;}

public void loadRelatedLeads() { String querystring; querystring = 'SELECT id,Website,Title,State,Country,CreatedDate,CreatedById,'; querystring += 'Status,Sales_Region__c,Sales_Area__c,Phone,OwnerId,Owner.Name,Name,'; querystring += 'LastModifiedDate,LastModifiedById,LastActivityDate,IsUnreadByOwner,'; querystring += 'Email,Company,Campaign_Source__c '; querystring += 'FROM Lead WHERE id != \''+pageid+'\' AND IsConverted = FALSE AND (Company LIKE \''+String.escapeSingleQuotes(entry.company)+'\' OR SLXSpam__Scoring_Email_Domain__c =\'' + entry.SLXSpam__Scoring_Email_Domain__c + '\') '; querystring += 'ORDER BY CreatedDate DESC LIMIT 10'; relatedleads = Database.query(querystring); } public Contact[] getConvertedLeads() {return this.convertedleads;} public void loadConvertedLeads() { String querystring; querystring = 'SELECT id,Title,CreatedDate,CreatedById,'; querystring += 'Phone,OwnerId,Owner.Name,Name,'; querystring += 'LastModifiedDate,LastModifiedById,LastActivityDate,'; querystring += 'Email,Account.Name,accountid '; querystring += 'FROM Contact WHERE id != \''+pageid+'\' AND Account.Name LIKE \'%'+String.escapeSingleQuotes(entry.company)+'%\''; querystring += 'ORDER BY CreatedDate DESC LIMIT 10'; convertedleads = Database.query(querystring); }

 

 

 

Thought I'd pass this little set of snipets on.  Have had clients asking us how to implement a Next and Prev button on some objects.  The concept being that if I'm looking at say an invoice I want to just easily go to the next one or previous one while still in that object instead of having to go back to the list view.  So we built the following.  The movement from one record to another is based on an invoice number field but you could modify to do it based on other fields as appropriate and you could also add a limiting factor to only records based on the owner that's running this.

 

 

VisualForce page component code


<apex:pageBlockButtons >
<apex:commandButton value="Prev" action="{!prev}" rerender="page" immediate="true" />
<apex:commandButton value="Next" action="{!next}" rerender="page" immediate="true" />
</apex:pageBlockButtons>

 

 

 

Apex controller code (this assumes you're adding to an existing controller extension class and you must initialize Allids in your init class by calling getListofIds() and we also have a generic utility that scans a list to see if it contains a field called Utils.SetContains)


Id oppid;
String invoiceno;
List <Id> Allids = new List <Id>();

 

public List<Id> getListofIds()
{
Billing__c[] billingids;
List <Id> ids = new List <Id>();

billingids = ([SELECT Id FROM Billing__c WHERE Invoice_Number__c < :invoiceno ORDER BY Invoice_Number__c DESC LIMIT 1]);
for (Billing__c b : billingids) {ids.add(b.id);}
ids.add(entry.id);
billingids = ([SELECT Id FROM Billing__c WHERE Invoice_Number__c > :invoiceno ORDER BY Invoice_Number__c LIMIT 1]);
for (Billing__c b : billingids) {ids.add(b.id);}
return ids;
}

public PageReference next()
{
Id nextid;
Integer idlocation = Utils.SetContains(System.currentPageReference().getParameters().get('id'), Allids);
if (idlocation != -1) {if (idlocation < Allids.size() - 1) {nextid = Allids[idlocation + 1];} else {nextid = AllIds[AllIds.size() - 1];}}
else {nextid = System.currentPageReference().getParameters().get('id');}
PageReference pageRef = new PageReference('/'+nextid);
pageRef.setRedirect(true);
return pageRef;
}

public PageReference prev()
{
Id previd;
Integer idlocation = Utils.SetContains(System.currentPageReference().getParameters().get('id'), Allids);
if (idlocation != -1) {if (idlocation != 0) {previd = Allids[idlocation - 1];} else {previd = AllIds[0];}}
else {previd = System.currentPageReference().getParameters().get('id');}
PageReference pageRef = new PageReference('/'+previd);
pageRef.setRedirect(true);
return pageRef;
}

 

Message Edited by dkorba2k5 on 04-27-2009 12:50 PM

Getting stuck on trying to figure out where to go with this.  With the example of Dynamic Picklists which works great.  What if I had 3 picklists (A,B, and C).  If after selecting a value on A, I find that there's only one value option for B, then I want that to be automatically selected for the user and then have C re-rendered now based on the value of B being selected.

 

I've managed to get this working fine with this one exception.  If there's more than 1 value, then we want the user to select, but to auto-select if there's only 1.  Any examples would be awesome.  Thanks.

Had a VF page and controller that was working fine until Spring '09 was installed.  It appears that any values in any public variables are maintained fine when rendered as HTML output and we get a single debug log.  However, if we renderAs="pdf", we end up with multiple log entries and the controller values are lost between the two separate logs resulting in a bunch of null value errors.  What's changed in Spring '09 and how do we accomodate for this?  An simple pseudo-code example would be:

 

public Account myAcct; public Account getAccount() { myAcct = ([SELECT name FROM Account where somecriteria]) System.debug('myAcct Name='+myAcct.name); } public getAcctName() { System.debug('myAcct Name='+myAcct.name); return myAcct.name;}

 


 

This is a simple example but the first debug statement works fine.  The second one returns a null error/value when rendering as PDF.  However, rendering as HTML doesn't have a problem.

 

Before I go too far down this path can someone answer if this is able to be done using Dynamic SOQL.

I know I can dynamically create the SELECT string using this.  But can I bind to a set in order to reproduce the equivalent of this:
assume I've already populated a list of id's.

SELECT id FROM Account WHERE Id in :idset

How can I create that as a query string that allows the injection of the set of id's into it.
Wondering if someone can post a simple example of the following.  I've got two picklists that I'm populating dynamically.  I was able to get this to work within the pageBlockSection tags.  However, I need this to work in terms of a spreadsheet-like/grid-entry.  So I need to see how to do it using a dataTable tag instead.  So it would look something like:

Row 1  Quantity -- Picklist 1 -- Picklist 2
Row 2  Quantity -- Picklist 1 -- Picklist 2

Where Picklist 2 re-renders based on Picklist 1 for each row independently

Thanks in advance
With the 10000 record limit on SOQL queries, is that per SOQL call in an Apex class or is it the sum of all calls in that class?  So if I had 5 queries, the total of those 5 must not exceed 10k?

Also, if all I'm doing is an SOQL count() .. how can I count all the records if it exceeds 10k?  Example please.  Thanks.
With VF whenever a text formula field has a <br> in it, it's being rendered as &lt;br&gt;.  How can we support this?  These are long text fields and need to have line breaks in it.
OK ... I must be missing something.  I have the following VF page and it works great except that I can't seem to figure out how to get the <apex:detail> section to rerender after saving records into the database.  Only the pageblock is rerendering.  So I need basically a full page rerender after saving.  Thanks

Code:
<apex:page StandardController="Timesheet__c" extensions="TimeSheetDetails" tabStyle="Timesheet__c" sidebar="true" standardStylesheets="true" showHeader="true" id="page">
<style>
.dim_a {width:300px; font-family: Verdana; font-size: 10px; font-weight: normal;}
.tabletext {font-family: Verdana; font-size: 10px; font-weight: normal;}
</style>
  <apex:detail relatedList="False"/>
  <apex:form >
        <apex:pageBlock title="Timesheet Details Edit">
        <apex:pageBlockButtons >
            <apex:commandButton value="Save"  action="{!save}" rerender="rows status="outStatus"/>
            <apex:commandButton value="Add"   action="{!add}" rerender="rows" status="outStatus"/>
            <apex:commandButton value="Reset" action="{!reset}" rerender="rows" status="outStatus" immediate="true" />
            <br>&nbsp
            <apex:actionStatus startText="(.................working.................)" stopText="" id="outStatus" onstop="Reset"/>
        </apex:pageBlockButtons>
            <apex:pageBlockTable border="1" cellpadding="2" value="{!entries}" var="a" id="rows" styleClass="tabletext"> 
                <apex:column width="20px"><apex:inputField value="{!a.Del__c}" required="false" styleClass="tabletext"/> <apex:facet name="header">Remove</apex:facet> </apex:column>
                <apex:column width="270px"><apex:inputField value="{!a.Description__c}" required="false" styleClass="dim_a"/> <apex:facet name="header">Description</apex:facet> </apex:column>
                <apex:column width="30px"><apex:inputField value="{!a.Start_Date__c}" required="true" styleClass="tabletext"/> <apex:facet name="header">Start Date</apex:facet> </apex:column>
                <apex:column width="30px"><apex:inputField value="{!a.End_Date__c}" required="true" styleClass="tabletext"/> <apex:facet name="header">End Date</apex:facet> </apex:column>
                <apex:column width="10px"><apex:inputField value="{!a.Quantity__c}" required="true" styleClass="tabletext"/> <apex:facet name="header">Billable Hrs</apex:facet> </apex:column>
                <apex:column width="10px"><apex:inputField value="{!a.Non_Billable_Qty__c}" required="false" styleClass="tabletext"/> <apex:facet name="header">Non-Billable Hrs</apex:facet> </apex:column>
   </apex:pageBlockTable>
        </apex:pageblock>
    </apex:form>
</apex:page>

 

Relatively new to VF and not clear on how to do this.  Now that I have my page built, when someone clicks on the record id for my custom object I want the VF page brought up and not the standard Salesforce page.  How/where do I specify this change?

Is there any way to find out what records have been submitted for @future class processing to make sure that the same record is not being submitted again?

Ok this is a strange two-part question/issue.

 

We have analytic snapshots that run once/week based on a report.  There are two issues we've just noticed with these.

 

1. For some reason, a couple of the date fields that are pulled from the report are storing an incorrect date.  The snapshot is due to run on a user in the PST timezone but the create and last modified dates from the report are storing an incorrect date in some cases.  If it's a record owned by a user in a different timezone, the snapshot is storing their date, not the person the context of the report is run as.

 

2. But more importantly, we have an apex controller class that pulls from the snapshot table a list of the snapshot dates.  These dates are showing up in each users local time zone settings when we need it to be consistent for all users.  So if the snapshot is run on 04-17-2010, then when we present the list of snapshots to all users they should see 04-17-2010.  not 04-18-2010 in some cases.


Here is the code that we're using to find the snapshot dates.  The goal is to create a selectlist for a VisualForce page to let the user choose which snapshot they want to run some analytics against.

 

 

	public List<SelectOption> getSnapShotDates() {
        List<SelectOption> optionList = new List<SelectOption>();
		Set <DateTime> snapdates = new Set <DateTime>();

// go get the most recent snapshot
		Analytics_Pipeline_Snapshots__c[] aps = 
			([SELECT Pipeline_Date__c 
			FROM Analytics_Pipeline_Snapshots__c 
			ORDER BY Pipeline_Date__c DESC LIMIT 1]);
// loop thru and create other snapshot dates one week before each one (up to 2 maximum)
		if (aps.size() > 0) {
			for (Integer i=0; i < 2; i++) {
				Datetime tempdate = datetime.newInstance(aps[0].pipeline_date__c.addDays(7 * -i).year(), 
														aps[0].pipeline_date__c.addDays(7 * -i).month(),
														aps[0].pipeline_date__c.addDays(7 * -i).day());
	            optionList.add(
	            	new SelectOption(String.valueof(tempdate.format('yyyy-MM-dd')),
	            					String.valueof(tempdate.format('yyyy-MM-dd'))));
			}
		}

        return optionList;
	}

 

 

 

 

 

 

 

I know how to write a trigger for Lead Conversion, but what about a trigger to change the lead owner to the current user when Lead Status field is altered to a specific value?

 

The basic goal here is I have a workflow that creates tasks for the Lead Owner when the status of a lead is altered to "qualified".  However, the Lead Owner is not always the Current User who performed the status change.  So I need to alter the Lead Owner to the Current User prior to the status change so that the task is created for the Current User/New Lead Owner.  

 

Any guidance would be greatly appreciated, and thank you in advance.

  • January 27, 2010
  • Like
  • 0

I am writing a test class for a trigger that has multiple for loops in it and When I run the test the lines that are not covered are the for loops.

 

Here is part of the trigger:

trigger AutoCreateIncident on Account (after update) { List<Case> c = new List<Case>(); for (Integer i = 0; i < Trigger.new.size(); i++) { Account newCase = Trigger.new[i]; Account OldCase = Trigger.old[i]; if(newCase.Operational_Status__c == 'Operational' && oldCase.Operational_Status__c == 'IT GO'){ if(newCase.Account_Services_Rep__c == 'Ade Adeyemi' || oldCase.Account_Services_Rep__c == 'Ade Adeyemi'){ for(Integer j = 0; j < 24; j++){ c.add(new Case(Type = 'Health Check', Reason__c = 'Health Check', AccountId = newCase.Id, OwnerId = '005700000016ePl', Priority = 'High', Due_date__c = System.today() + (j*30) + 1)); } } else if(newCase.Account_Services_Rep__c == 'Chris Nelson' || oldCase.Account_Services_Rep__c == 'Chris Nelson'){ for(Integer k = 0; k < 24; k++){ c.add(new Case(Type = 'Health Check', Reason__c = 'Health Check', AccountId = newCase.Id, OwnerId = '005700000016eQ4', Priority = 'High', Due_date__c = System.today() + (k*30) + 1)); } } else if(newCase.Account_Services_Rep__c == 'Deborah Kerr' || oldCase.Account_Services_Rep__c == 'Deborah Kerr' ){ for(Integer l = 0; l < 24; l++){ c.add(new Case(Type = 'Health Check', Reason__c = 'Health Check', AccountId = newCase.Id, OwnerId = '005700000016ePr', Priority = 'High', Due_date__c = System.today() + (l*30) + 1)); } } else if(newCase.Account_Services_Rep__c == 'Elyssa Kim' || oldCase.Account_Services_Rep__c == 'Elyssa Kim'){ for(Integer m = 0; m < 24; m++){ c.add(new Case(Type = 'Health Check', Reason__c = 'Health Check', AccountId = newCase.Id, OwnerId = '00570000001IbB3', Priority = 'High', Due_date__c = System.today() + (m*30) + 1)); } } } } insert c; }

I understand this is not the most efficent or best way to code this trigger, but this is how i have chosen to code it for now. The lines of code that I am not sure how to test are the for loop lines and the "c.add(new Case(" lines. any suggestions on how to tackle this one?

 

I also have another one that has a few Field.addErrors in it and I am not sure how to test those lines of code either 

 

Thanks

  • November 24, 2009
  • Like
  • 0

On the task there is a WhatId and a WhoId. Sometimes the WhatId is filled in and others have the WhoId filled in. In which situations is one used over the other?

 

Thanks 

  • October 29, 2009
  • Like
  • 0
when logging in as a customer portal user to check what we have set-up with VF/Apex, I need to have the Apex queries execute based on the portal user, not as my profile.  But it seems that the userinfo.getuserid() function is still acting with my id.  Is there anyway to get around this?  To have it use the context of the user I'm logged in as in the portal instead of my id?
In an attempt to make our application bulletproof I'm trying to figure out how to catch the error when a VF page is loaded and has a bad ID value (either missing or incorrect value for that standard controller).  We're able to catch all other scenario's but haven't been able to figure out how to process that error.

We've overriden several pages with VF pages.  All works fine and when you click on the "Log a Call" button to create an activity it works fine.  But on Leads, the Log a Call button has an incorrect Return URL.  It doesn't have the lead records id included in it.  Any ideas?

 

A sample of the wrong URL looks like this:

 

https://cs1.salesforce.com/00T/e?title=Call&who_id=00Q00000004zANx&followup=1&tsk5=Call&retURL=%2Fapex%2Fleads

 

Notice the retURL is incomplete.  Here's a sample from a different overriden page object that is correct:

 

https://cs1.salesforce.com/00T/e?title=Call&what_id=a0200000000UqXV&followup=1&tsk5=Call&retURL=%2Fapex%2FQuote_Layout%3Fid%3Da0200000000UqXV%26sfdc.override%3D1

I'm trying to put a Visualforce page in the sidebar. I know you can do this by adding a homepage html component containing an iframe that points to your Visualforce page, but this seems to cause a "Redirect Loop" error in Firefox.

 

"Redirection limit for this URL exceeded.  Unable to load the requested page.  This may be caused by cookies that are blocked."

 

It works ok in IE though.

 

Does anyone know any other or best practice ways to include Visualforce content in the sidebar?

 

Thanks,

 

 

Tom

Hi All,

 

I have been trying to follow the example on how to do this - http://wiki.developerforce.com/index.php/VisualForceEmailTemplates_sample

 

I have a custom object with Contacts as a related list. I wish to be able to list the Contacts within the email template much like the sample above.

 

I receive the error  "Error: Invalid Field Contacts for SObject customobject__c" using the below:

 

<apex:repeat var="cx" value="{!relatedTo.Contacts}">
        {!cx.FirstName}
        {!cx.LastName}
</apex:repeat>

 

I am assuming the sample is applicable to custom objects. Any suggestions appreciated.

 

 

Had a VF page and controller that was working fine until Spring '09 was installed.  It appears that any values in any public variables are maintained fine when rendered as HTML output and we get a single debug log.  However, if we renderAs="pdf", we end up with multiple log entries and the controller values are lost between the two separate logs resulting in a bunch of null value errors.  What's changed in Spring '09 and how do we accomodate for this?  An simple pseudo-code example would be:

 

public Account myAcct; public Account getAccount() { myAcct = ([SELECT name FROM Account where somecriteria]) System.debug('myAcct Name='+myAcct.name); } public getAcctName() { System.debug('myAcct Name='+myAcct.name); return myAcct.name;}

 


 

This is a simple example but the first debug statement works fine.  The second one returns a null error/value when rendering as PDF.  However, rendering as HTML doesn't have a problem.