• Nathan Crosby
  • NEWBIE
  • 75 Points
  • Member since 2008

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

I just deployed code last week without a problem.  When I run all tests in the sandbox, I get 85% coverage and no errors.  However, when I try  to deploy anything from my sandbox, I get the following error on 3 of my test classes:

 

System.DMLException: Insert Failed. First Exception on row 0; first error; Duplicate_Username, Duplicate Username, <br> Another user has already selected the username <br> Please selectd another: [Username]

 

Each test class does create a user object and even though I have deployed these before without problem, I modified so they hae a differeint email address.... However I still cannot deploy.

 

I don't believe I have made any changes to the live org but I cannot deploy... any ideas? thanks!!!

 

Fred

Hi all,

 

I created my site in the Developer Edition.  All worked fine. 

Then, I activated the customer portal because I wanted to try case management.

After that, a new tab was automatically created (Home) on top of my toolbar, this tab, always go to the customer registration page.

I want to delete this tab, rename the tab or deactivate the customer portal to get my normal salesforce site.

I see how can I activate the portal, but not how to deactivate.

Can anyboby provide some help?
Thanks and regards,

Isidoro!

Hey all, 

 

We're in the middle of doing our best to roll out a production site. Each site page has a number of elements that gather display or gather data, including static resources and Apex forms.

 

Of course, many of our data fields are acted upon by Javascript that validate certain things prior to submit, or that perform operations not handled by Apex, prior to submit.

 

We're hitting a big challenge, which is that each element is assigned an ID, but that IDs are NOT static; they seem to depend upon the order that the element falls within the page. For instance, our form has the following name, now:

 

 

<form id="j_id0:CT_App_Template:j_id10" ..../>

 

 but had a different id (13) earlier, and still a different id prior to that.  These changing IDs make for very confusing and bug-prone development, especially because there are quite a few elements on each page, and the number of elements changes as we add or subtract visual elements (referred to as static resources).

 

This is causing us to push static resources to other servers, for instance, hosting on internal sites that we can refer to directly, rather than dealing with the issue of changing IDs.

 

Has anyone run into & found a solution to this aggravating issue, and/or is there a way to catch and dynamically assign the ID, or tell a resource to always use the SAME id,  on a consistent basis?

 

Thanks for your support!

--Dave 

 

I have a trigger that calls a class which establishes record sharing for an object based on the record owner and their role. Essentially I am sharing the record with the owner's role. The org has entirely too many roles that will quickly exceed the number of predefined sharing rules that can be established so this trigger/class solution is necessary across a number of private objects to ensure members of the same role share the same access to records anyone in the same role owns.

My challenge comes in establishing the data set needed to create the sharing in the custom object's sharing object (in this case Team__Share). Specifically, because I am sharing with a Role I need to first grab the record owner, determine their role, and then query the Group object to get the Group Id to pass back into the Team__Share object to set the UserOrGroupId (using the Role Id to set UserOrGroupId causes an error as it is looking for either a User Id or Group Id).

Here is my code for both the trigger and the class with the SOQL that is generating the governor limit execution error commented. This works like a charm if it is just one record being updated/inserted, but obviously fails once testing with larger sets of data.
Code:
trigger TeamSharingTrigger on Team__c (after insert, after update) {
 
 List<ID> ownerId = new List<ID>();
 
 for (Team__c teamNew1: Trigger.New){
  ownerId.add(teamNew1.OwnerId);
 }
 
 Map<ID,User> u = new Map<ID,User>([Select Id, UserRoleId From User where Id in :ownerId]);
 
 ID roleId;
 for (Team__c teamNew2: Trigger.New){
  roleId = u.get(teamNew2.OwnerId).UserRoleId;
  if(roleid != null){
   TeamSharingClass.manualShareAll(teamNew2.Id,roleId);
  }
 }
 
}





public class TeamSharingClass {
 
 public static boolean manualShareAll(Id recordId, Id userOrGroupId){

   /*Since this is a Role and not a User that I am trying to share with I 
     need to grab the Id of the Group for that role.
     This is the SOQL that causes the governor limits (executed for each call)*/
      ID groupID = [Select g.Id From Group g where g.RelatedId=:userOrGroupId and g.Type='Role'].Id;
      
      Team__Share teamShr = new Team__Share();
   teamShr.ParentId = recordId;
   teamShr.UserOrGroupId = groupID;
   teamShr.AccessLevel = 'Edit';
   teamShr.RowCause = Schema.Team__Share.RowCause.Manual;
   Database.SaveResult sr = Database.insert(teamShr,false);
         
      // Process the save results.
      if(sr.isSuccess()){
         // Indicates success
         return true;
      }
      else {
         // Get first save result error.
         Database.Error err = sr.getErrors()[0];
         
         // These sharing records are not required and thus an insert exception is acceptable. 
         if(err.getStatusCode() == StatusCode.FIELD_INTEGRITY_EXCEPTION  &&  
                  err.getMessage().contains('AccessLevel')){
            // Indicates success.
            return true;
         }
         else{
            // Indicates failure.
            return false;
         }
       }
   }
   
}

 



I know there are ways to download contact details etc... to excel but is there anyway to download ALL SalesForce data in one large spreadsheet? Or do you have to download certain areas seperately?

Any help would be appreciated.

A

Which for loop here is more efficient, is there even a difference when it comes to avoiding governor limits?

 

 

Task[] tasks = new Task[]{};
for(Integer i=0;i<tasks.size();i++) {
//some code
}

 

 

OR

 

 

Task[] tasks = new Task[]{};
for(Task activity: tasks) {
//some code
}

 

 

 

 

Hi guys,

 

I have a simple issue with deployment. I have a trigger and a test class for it. While i'm trying to deploy only my trigger  deployment process  runs all test.

And some of these test are failed. Is it possible to deploy only my trigger with running only my test for it ?

 

 

Thanks for your responses!

hi i have requirement here like we will be sending some links in the emails to the guest users  .so when a user clicks on the link a page opens with some populated data.i am using java script to populate the data. i made the page render as pdf. then the page is loading as pdf but the data is not populating.when i take off the render as pdf the page is loading with populated data.

 

So i want to create a button on the page so that when user clicks on that button the page with populated data should convert as pdf.

 

 

can anybody how can i achieve this.,

 

cheers 

I just deployed code last week without a problem.  When I run all tests in the sandbox, I get 85% coverage and no errors.  However, when I try  to deploy anything from my sandbox, I get the following error on 3 of my test classes:

 

System.DMLException: Insert Failed. First Exception on row 0; first error; Duplicate_Username, Duplicate Username, <br> Another user has already selected the username <br> Please selectd another: [Username]

 

Each test class does create a user object and even though I have deployed these before without problem, I modified so they hae a differeint email address.... However I still cannot deploy.

 

I don't believe I have made any changes to the live org but I cannot deploy... any ideas? thanks!!!

 

Fred

Hi all,

 

I created my site in the Developer Edition.  All worked fine. 

Then, I activated the customer portal because I wanted to try case management.

After that, a new tab was automatically created (Home) on top of my toolbar, this tab, always go to the customer registration page.

I want to delete this tab, rename the tab or deactivate the customer portal to get my normal salesforce site.

I see how can I activate the portal, but not how to deactivate.

Can anyboby provide some help?
Thanks and regards,

Isidoro!

Hey all, 

 

We're in the middle of doing our best to roll out a production site. Each site page has a number of elements that gather display or gather data, including static resources and Apex forms.

 

Of course, many of our data fields are acted upon by Javascript that validate certain things prior to submit, or that perform operations not handled by Apex, prior to submit.

 

We're hitting a big challenge, which is that each element is assigned an ID, but that IDs are NOT static; they seem to depend upon the order that the element falls within the page. For instance, our form has the following name, now:

 

 

<form id="j_id0:CT_App_Template:j_id10" ..../>

 

 but had a different id (13) earlier, and still a different id prior to that.  These changing IDs make for very confusing and bug-prone development, especially because there are quite a few elements on each page, and the number of elements changes as we add or subtract visual elements (referred to as static resources).

 

This is causing us to push static resources to other servers, for instance, hosting on internal sites that we can refer to directly, rather than dealing with the issue of changing IDs.

 

Has anyone run into & found a solution to this aggravating issue, and/or is there a way to catch and dynamically assign the ID, or tell a resource to always use the SAME id,  on a consistent basis?

 

Thanks for your support!

--Dave 

 

Hi all:

 

I have a customer for whom it would seem to make sense to move their existing, mostly static, web site to Sites. The site has about 50 pages that for the sake of argument are purely static HTML/CSS, maybe a little Javascript. It has maybe 8-10 pages that will draw on significant dynamic content. He'd like to be able to edit the static content himself to the extent possible. He is willing and tech-savvy.

 

Two questions:

 

1) What's the best way to handle the static HTML pages in Visual Force? Upload and manage as static resources?

2) Any way to let my customer use a tool like Adobe Contribute to edit his static content directly, or can that only be done via the web UI and/or the Force.com IDE?

 

Thanks in advance for all feedback.

 

-- SGL

  • July 20, 2009
  • Like
  • 0

Hey everyone,

 

I've been dabbling in apex code for a while. I've always used system.assert to check my code and view the apex error in my triggers. Once I confirmed I've gotten the right output/input I comment out the system.assert.

 

I've been seeing a lot of board messages suggesting using system.debug. I've looked at the dev. manual and I'm a bit confused. How and when do I use system.debug? Why use system.debug over system.assert?

 

Any real life examples including the system.debug and the output of system.debug would be appreciated as well.

 

Thanks!

Every once in a while I get the following error from my trigger:

 

 Apex script unhandled trigger exception by user/organization: 00530000000fJTi/00D300000000beQ

Contact_Area_of_Interest: execution of BeforeUpdate

caused by: System.Exception: Too many SOQL queries: 21

Trigger.Contact_Area_of_Interest: line 18, column 9

 

 Can anyone see where my problem is in the code below.

 

Thanks.

 

 

trigger Lead_Area_of_Interest on Lead(before insert, before update, after insert, after update) { String aoiValue = ''; // Set up list to hold unique IDs of all new or updated leads Set<Id> leadIds = New Set<Id>(); // Set up list to hold unique area of interests Set<String> interests = new Set<String>(); // Iterate through array of new or updated records for (Lead a : trigger.new){ //if (a.area_of_interest_landing__c != null && a.area_of_interest_landing__c != '') leadIds.add(a.id); } // Map the area of interest field values to ID Map<ID, Lead> aoi = new Map<Id, Lead>( [select area_of_interest__c, area_of_interest_landing__c from Lead where ID in : leadIds]); if (Trigger.isBefore) { if (Trigger.isDelete) { // In a before delete trigger, the trigger accesses the records that will be // deleted with the Trigger.old list. for (Lead a : Trigger.old) { if (a.firstname == 'delete') { a.addError('You cannot delete this record!'); } } } else { // In before insert or before update triggers, the trigger accesses the new records // with the Trigger.new list. for (Lead a : Trigger.new) { if (a.firstname == 'bad') a.firstname.addError('Bad name'); if (a.area_of_interest_landing__c != null && a.area_of_interest_landing__c != '') { if (a.area_of_interest__c != null && a.area_of_interest__c != '') { // if here then we have to merge both area of interest fields // Add all values from both fields into Set array which ensures uniqueness for (Lead aoiLanding : trigger.new) { String[] result1 = a.area_of_interest_landing__c.split(';'); for (String x : result1) { interests.add(x); } String[] result2 = a.area_of_interest__c.split(';'); for (String y : result2) { interests.add(y); } } // Populate variable to be used in update Integer i = 0; for (String s : interests) { if (i == 0) aoiValue = s; else aoiValue = aoiValue + ';' + s; i++; } try { a.area_of_interest__c = aoiValue; } catch (DmlException de) { for (Integer e = 0; E < de.getNumDml(); e++) { //NC a.area_of_interest__c.addError(de.getDmlMessage(e)); //NC } } } else { // area_of_interest__c is null and no record in aoi map so just copy values a.area_of_interest__c = a.area_of_interest_landing__c; } } else { // no exising values so just copy landing field values if not null TEST5 if (a.area_of_interest_landing__c != null && a.area_of_interest_landing__c != '') { // try { a.area_of_interest__c = aoi.get(a.id).area_of_interest_landing__c; //NC // } // catch (DmlException de) { // for (Integer e = 0; E < de.getNumDml(); e++) { //NC // a.area_of_interest__c.addError(de.getDmlMessage(e)); //NC // } // } } } } if (Trigger.isInsert) { // area_of_interest__c is null and no record in aoi map so just copy values for (Lead a : Trigger.new) { if (a.area_of_interest_landing__c != null && a.area_of_interest_landing__c != '') { // try { a.area_of_interest__c = a.area_of_interest_landing__c; // } // catch (DmlException de) { // for (Integer e = 0; E < de.getNumDml(); e++) { //NC // a.area_of_interest__c.addError(de.getDmlMessage(e)); //NC // } // } } } // If the trigger is not a before trigger, it must be an after trigger. } else { /* if (Trigger.isInsert) { List<Contact> contacts = new Contact[0]; for (Lead a : Trigger.new) { if(a.lastname == 'makeContact') { contacts.add(new Contact (firstname = a.firstname, lastname = a.lastname, accountId = a.id)); } } insert contacts; } */ } }}}

 

 

 

I am trying to input the below code on Custom Formula, but getting Error.
CASE( Status ,
"Open - Not Contacted","Open - Not Contacted",
"Working - Contacted","Working - Contacted",
"Open- In Approval","Open- In Approval",
"Channel Deal Approved (Converted)", "Channel Deal Approved (Converted)",
"Closed - Converted","Closed - Converted",
"Closed - Not Converted","Closed - Not Converted",
"Closed - Not Converted","Closed - Not Converted",
"Ready to Convert","Ready to Convert",
null)
Can any one help on the same?
We have a custom required text field called "Locale" for leads.  In addition to being required, I want to validate that it is set to either "US" or "CA" during edit/create.  Any ideas?  Pseudo code looks like this:

if the locale equals US or CA
    allow update/insert
otherwise
    display error message

I have a trigger that calls a class which establishes record sharing for an object based on the record owner and their role. Essentially I am sharing the record with the owner's role. The org has entirely too many roles that will quickly exceed the number of predefined sharing rules that can be established so this trigger/class solution is necessary across a number of private objects to ensure members of the same role share the same access to records anyone in the same role owns.

My challenge comes in establishing the data set needed to create the sharing in the custom object's sharing object (in this case Team__Share). Specifically, because I am sharing with a Role I need to first grab the record owner, determine their role, and then query the Group object to get the Group Id to pass back into the Team__Share object to set the UserOrGroupId (using the Role Id to set UserOrGroupId causes an error as it is looking for either a User Id or Group Id).

Here is my code for both the trigger and the class with the SOQL that is generating the governor limit execution error commented. This works like a charm if it is just one record being updated/inserted, but obviously fails once testing with larger sets of data.
Code:
trigger TeamSharingTrigger on Team__c (after insert, after update) {
 
 List<ID> ownerId = new List<ID>();
 
 for (Team__c teamNew1: Trigger.New){
  ownerId.add(teamNew1.OwnerId);
 }
 
 Map<ID,User> u = new Map<ID,User>([Select Id, UserRoleId From User where Id in :ownerId]);
 
 ID roleId;
 for (Team__c teamNew2: Trigger.New){
  roleId = u.get(teamNew2.OwnerId).UserRoleId;
  if(roleid != null){
   TeamSharingClass.manualShareAll(teamNew2.Id,roleId);
  }
 }
 
}





public class TeamSharingClass {
 
 public static boolean manualShareAll(Id recordId, Id userOrGroupId){

   /*Since this is a Role and not a User that I am trying to share with I 
     need to grab the Id of the Group for that role.
     This is the SOQL that causes the governor limits (executed for each call)*/
      ID groupID = [Select g.Id From Group g where g.RelatedId=:userOrGroupId and g.Type='Role'].Id;
      
      Team__Share teamShr = new Team__Share();
   teamShr.ParentId = recordId;
   teamShr.UserOrGroupId = groupID;
   teamShr.AccessLevel = 'Edit';
   teamShr.RowCause = Schema.Team__Share.RowCause.Manual;
   Database.SaveResult sr = Database.insert(teamShr,false);
         
      // Process the save results.
      if(sr.isSuccess()){
         // Indicates success
         return true;
      }
      else {
         // Get first save result error.
         Database.Error err = sr.getErrors()[0];
         
         // These sharing records are not required and thus an insert exception is acceptable. 
         if(err.getStatusCode() == StatusCode.FIELD_INTEGRITY_EXCEPTION  &&  
                  err.getMessage().contains('AccessLevel')){
            // Indicates success.
            return true;
         }
         else{
            // Indicates failure.
            return false;
         }
       }
   }
   
}

 



I created a formula field that is to display a value from a picklist field from another object based on a look up of a user. I wrote this formula, but it is not displaying the correct value from the picklist. Can anyone recommend how to fix it?
 
Thanks in advance,
Julie
 
CASE(Sales_Rep__r.Team__c , "Advertising Operations", "Business Services",
"Communities", "Communities-Central", "Communities-East", "Communities-North Coastal", "Communities-North Inland", "Communities-South", "Consumer Marketing",
"Database Marketing", "Enlace", "Executive", "Lifestyles & Entertainment",
"Majors & Nationals", "Majors-Digital Media", "Marketplace", "Marketplace-Automotive",
"Marketplace-Digital Media", "Marketplace-Real Estate", "Marketplace-Recruitment", "Niche", "Online Customer Service", "TLN", "Training", "U-T Direct Marketing" )
  • November 19, 2008
  • Like
  • 0
Hi I am new to all this formula stuff and would like some help please.  I have been asked to create a date calculation based on:
 
The date requested (date field) + no of days contracted (text field) and from this I need to
get the = End Date (date field).  So if I request a start date of 10/10/2008 and I have a contract which is 50 days, I want it to tell me the end date of my request?
 
When I try it the formula comes up with expected a date and got text?
 
Thank you in advance.
  • October 27, 2008
  • Like
  • 0