• kwu
  • NEWBIE
  • 75 Points
  • Member since 2010

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

Hello -

 

I'm trying to use a custom controller to display a picklist of a custom object. The below code works when I place it in anonymous, but fails when I upload the class. Maybe I need a test class?

 

public with sharing class ebsController{

    public List<SelectOption> getDatacenter()
    {  
           List<SelectOption> options = new List<SelectOption>();        
           Schema.DescribeFieldResult fieldResult = Pod_UPS__c.Datacenters__c.getDescribe();
           List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();    
           
           options.add(new SelectOption('','--Select Data Center --'));
        
           for( Schema.PicklistEntry f : ple)
           {
              options.add(new SelectOption(f.getLabel(), f.getValue()));
              System.debug(logginglevel.INFO,f.getLabel() + ',' + f.getValue());
           }
               
           return options;
    }
}

 

 

Thanks, Daniel

Hi,

 

I have been reading about rules around at least 75% of code must be tested successfully before it can be moved to production.  My problem is I am imagining the process and I am sure by experimenting I will figure it out; however, when dealing with a production environment I do not like the idea of experiementing.

 

QUESTIONS:

  1. When I move the class and the test class to production is it automically active code or do I have to activate it?
  2. Do I have to keep the Test Class code in production all the time with the associate class?
  3. If I have a class that has temporary variables in the class code just for testing so that I can get 100% code coverage then move it to production will I be able to comment those variables out in the test class and controller class after I move it to production? 

If the answer is no than I may need some help on how to test a class that I need to know the new record id.  The code below is a portion of the controller and the second code snippet is a portion of the test class that tests the controller.

 

CONTROLLER CLASS:

// This class clones an opportunity and all related partner records
public class OppCloneWithPartnerRecsController {
 
    //added an instance varaible for the standard controller
    private ApexPages.StandardController controller {get; set;}
     // add the instance for the variables being passed by id on the url
    private Opportunity opp {get;set;}
    
    // set the id of the record that is created -- ONLY USED BY THE TEST CLASS
    public ID newRecordId {get;set;}    
    // set the force error  
    public boolean forceError { get;set; }
    //-------------------------------------------- ONLY USED BY THE TEST CLASS

 
    // initialize the controller
    public OppCloneWithPartnerRecsController(ApexPages.StandardController controller) { 
        //initialize the stanrdard controller
        this.controller = controller;
        // load the current record
        opp = (Opportunity)controller.getRecord();       
    }
 

 

TEST CLASS:

...

        Test.startTest();

//        ext.forceError = false;

        
        // call the oppCloneWithPartners method
        PageReference ref = ext.oppCloneWithPartners();
        // create the matching page reference
        PageReference redir = new PageReference('/'+ext.newRecordId); 
 
        // make sure the user is sent to the correct url
        System.assertEquals(ref.getUrl(),redir.getUrl());
 
        // check that the new Opp was created successfully
       Opportunity newOpp = [select id from Opportunity where id = :ext.newRecordId];
        System.assertNotEquals(newOpp, null);
        // check that the line item was created
        List<Partner> newItems = [Select p.Id From Partner p where p.OpportunityId = :newOpp.id];
        System.assertEquals(newItems.size(),2);
 
        // Switch back to runtime context
        Test.stopTest(); 
    } 

...

 

 

Hi,

I would like to test WebService (I have a got a developer account and an application under development) 
I have successfully generated the entreprise wsdl - The generated wsdl shows the following endpoint

<soap:address location="https://www.salesforce.com/services/Soap/c/18.0"/>

 

This is the error I get when I attempt to login using the above location:

 

 

com.sforce.soap.enterprise.LoginFault: INVALID_LOGIN: Invalid username, password, security token; or user locked out

 

 

  I guess the reason is that this is the production URL? What would be endpoint for development?


Thanks
--
jaguarg

Hi folks, my team is hiring for a Sr. Innovation Developer. You can read the job description here:

 

Senior Innovation Developer

 

This position is located in San Francisco at the Salesforce.com HQ!

 

Thanks!

 

  • February 13, 2013
  • Like
  • 0

Hi all,

 

I created a custom object called Lead Contact.  It is located on the Lead Object.  When we have multiple Leads from the same company, we add the extra Leads to the Lead Contact object.  Once the Parent Lead is converted, all Lead Contacts need to be converted to Contacts and assigned to the Parent Account.

 

We also have a custom object called Locations that will be moved over upon conversion of the Lead.

 

The trigger works great in the Sandbox, but I cannot get over 65% coverage in production.  Any suggestions?

 

Trigger:

 

trigger LeadContactConvertAcc on Account (after insert, after update) {

    Account a = [select Id, Lead_Convert_Id__c from Account where Id = :Trigger.new[0].Id limit 1];

    if(a.Lead_Convert_ID__c != NULL) {
      
    Lead l = [select Id from Lead where Id = :a.Lead_Convert_Id__c Limit 1];
        
            for (Lead_Contact__c lc : [Select id, Converted_Account_ID_del__c, First_Name__c,
                   Last_Name__c,Title__c,Email__c,Secondary_Email__c,Phone__c,Fax__c,
                   Mobile__c,Mailing_Street__c,Mailing_City__c,Mailing_State__c,
                   Mailing_Zip__c,Mailing_Country__c 
                   FROM Lead_Contact__c 
                   WHERE Parent_Lead_ID_del__c = :a.Lead_Convert_Id__c]) 
                   
                   {
                           
                   Contact newContact = new Contact (
                     AccountId = a.Id,
                     FirstName = lc.First_Name__c,
                     LastName = lc.Last_Name__c,
                     Title = lc.Title__c,
                     Email = lc.Email__c,
                     Secondary_Email__c = lc.Secondary_Email__c,
                     Phone = lc.Phone__c,
                     Fax = lc.Fax__c,
                     MobilePhone = lc.Mobile__c,
                     MailingStreet = lc.Mailing_Street__c,
                     MailingCity = lc.Mailing_City__c,
                     MailingState = lc.Mailing_State__c,
                     MailingPostalCode = lc.Mailing_Zip__c,
                     MailingCountry = lc.Mailing_Country__c);
                     
                   insert newContact;  
                   
                   lc.Parent_Name_del__c = null;
                   
                   update lc;
     
                   }   
                   
            for (Location__c ln : [select Id, Lead__c, Account__c 
                from Location__c 
                WHERE Lead__c = :a.Lead_Convert_Id__c]) {
                
                ln.Account__c = a.Id;
                
                update ln;
                
     }        
   }
  }

  Class:

 

 

public class LeadContactConvert {

static testMethod void LeadContactConvert() {

Id a1Id;
Id l1Id;
Id lnId;
Id lcId;
Id c1Id;
Id c2Id;

    // CREATE LEAD
    Lead l1 = new Lead();
    
        l1.Lastname='leaddata';
        l1.Company='nav';
        l1.Leadsource='Calling Campaign';
        l1.IsConverted = false;
        l1.IsUnreadByOwner = true;
        l1.Status = 'qualified';
        
        Database.insert(l1);
        l1Id = l1.id;
       

    //CREATE LEAD CONTACT
    Lead_Contact__c lc = new Lead_Contact__c ();
      
        lc.First_Name__c = 'test';
        lc.Last_Name__c = 'test';
        lc.Title__c = 'test';
        lc.Email__c = 'test@test.com';
        lc.secondary_Email__c = 'test2@aol.com';
        lc.Phone__c = '1111111111';
        lc.fax__c = '2222222222';
        lc.Mobile__c = '3333333333';
        lc.Mailing_Street__c = '123 Main St';
        lc.Mailing_City__c = 'Phoenix';
        lc.Mailing_State__c = 'AZ';
        lc.Mailing_Zip__c = '85083';
        lc.Mailing_Country__c = 'USA';
        lc.Parent_Name_del__c = l1.Id;
       
       
       Database.insert(lc);         
       lcId = lc.id;
   
    //CREATE LOCATION
    Location__c  ln = New Location__c ();
      
      ln.Street__c = '123 test';
      ln.City__c = 'Test';
      ln.State__c = 'az';
      ln.zip__c = '11111';
      ln.Entrances_Required__c = 'test';
      ln.Location__c = 1;
      ln.Proposed_Demarc__c = 'test';
      ln.Account__c = NULL;
      ln.Lead__c = l1.Id;
          
      Database.insert(ln);
      lnId = ln.id;
       
    //CREATE ACCOUNT   
    Account a1 = new Account();
        a1.name = 'AName';
        a1.type = 'Prospect';
        a1.Lead_Convert_ID__c = l1.Id;
        
        Database.insert(a1);
        a1Id = a1.Id;
    
     //CREATE CONTACT 1
     Contact c1 = new Contact ();
      
       c1.LastName = l1.Lastname;
       c1.Email = 'test@aol.com';
       c1.Phone = '9999999999';
       c1.AccountId = a1.id;
       
       Database.insert(c1);            
       c1Id = c1.id; 
    
    
    //CREATE CONTACT 2
    Contact c2 = new Contact ();
      
        c2.FirstName = lc.First_Name__c;
        c2.LastName = lc.Last_Name__c;
        c2.Title = lc.Title__c;
        c2.Email = lc.Email__c;
        c2.Secondary_Email__c = lc.Secondary_Email__c;
        c2.Phone = lc.Phone__c;
        c2.Fax = lc.Fax__c;
        c2.MobilePhone = lc.Mobile__c;
        c2.MailingStreet = lc.Mailing_Street__c;
        c2.MailingCity = lc.Mailing_City__c;
        c2.MailingState = lc.Mailing_State__c;
        c2.MailingPostalCode = lc.Mailing_Zip__c;
        c2.MailingCountry = lc.Mailing_Country__c;
        c2.AccountId = lc.Converted_Account_ID_del__c;
       
       Database.insert(c2);            
       c2Id = c2.id;     
     
               
// Account a = [select Id, Lead_Convert_Id__c from Account where Lead_Convert_Id__c = :l1.Id limit 1];
      
//      Lead_Contact__c lc1 = [Select id, Converted_Account_ID_del__c, First_Name__c,
//                   Last_Name__c,Title__c,Email__c,Secondary_Email__c,Phone__c,Fax__c,
//                   Mobile__c,Mailing_Street__c,Mailing_City__c,Mailing_State__c,
//                   Mailing_Zip__c,Mailing_Country__c 
//                   FROM Lead_Contact__c 
//                   WHERE Parent_Name_del__c = :a.Lead_Convert_Id__c]; 
      
      Contact newContact = new Contact (
      AccountId = a1.Id,
      FirstName = lc.First_Name__c,
      LastName = lc.Last_Name__c,
      Title = lc.Title__c,
      Email = lc.Email__c,
      Phone = lc.Phone__c,
      Fax = lc.Fax__c,
      MobilePhone = lc.Mobile__c,
      MailingStreet = lc.Mailing_Street__c,
      MailingCity = lc.Mailing_City__c,
      MailingState = lc.Mailing_State__c,
      MailingPostalCode = lc.Mailing_Zip__c,
      MailingCountry = lc.Mailing_Country__c);
       
      insert newContact; 
        
      lc.Parent_Name_del__c = null;
       
        update lc; 
        
      ln.Account__c = a1.Id;
      
        update ln;  
        
     }
   
}

 

 

Thank you in advance for any assistance.

 

Levi

 

Hi,

I have 2 fields:

Annual Date : mm/dd format field

Last Quoted by Year :  yyyy format field

How can I map these fields in Salesforce given that we dont have these formats defined?

Thanks,

Vimal

Hi,

 

Don't understand dashboards at all and can't find documantation that allows me to do what I need.

 

I have my own custom object, that is built on a visualforce page from data retrieve from different objects choosen by the user on the inputfields on my visualforce screen.

I want to add a dashboard, preferebly to the same visualForce screen (if possible) or on a new screen.

The dashboard should show records that represent data from specific months and years choose by the user.

and the objects should be displayed by the different month and the amount hold in each sum.

(Meaning I need a pie dashboard with the each month in a different color and the sum of that month taking the apropriate portion of the pie).

 

The best answer I can hope for is just a refernce to a guide that deals with how to build a dashboard of the type I'm trying to build, because I've found very little documentation and it is mostly about building the regular dashboards.

(The other option is just some directions that would help me deal with my problems)

 

Now for the problems:

1. How if at all can I add a dashbord to my visualforce page, should I build it regularly and then somehow refernce it in the VF page attributes or for what I need should the dashboard be created with VF from the start? if sow, how?

2. I understand that for a dashboard I first need to get a report but when trying to build a custom report it does not give me all the custom objects that I own as options for that report? how can I make my custom object the type of object that will show on my rerports.

3. for the sobject it does show for reporting it only allows the report to be on specific fields like Creation Date, name, status (a custom field) but not on the fields that I wany.

4. It only allows the user to choose specific date types for the records presented (for example the user can choose to present only records that were created between this date to another, but since all of my objects were created now, by the user, it doesn't help, I need it to show records between the date field in my object (the object that holds data from different object will hold the information on when the original data was created and that is the date I want the user to have a choice which to present and which not.

 

Thanks,

Guy

 

 

 

 

Hi...

 

I want to render my map display using Pitney Bowes MapExtreme Java and not GoogleMaps API.

MapExtreme has the functionality of creating Web Apps through a wizard which finally crates a JSP page.

I want this functionality to be used in my Salesforce.com pages. Please help me. I have really got stuck..

 

Thanks,

aslam

 

  • May 12, 2010
  • Like
  • 0

Hello -

 

I'm trying to use a custom controller to display a picklist of a custom object. The below code works when I place it in anonymous, but fails when I upload the class. Maybe I need a test class?

 

public with sharing class ebsController{

    public List<SelectOption> getDatacenter()
    {  
           List<SelectOption> options = new List<SelectOption>();        
           Schema.DescribeFieldResult fieldResult = Pod_UPS__c.Datacenters__c.getDescribe();
           List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();    
           
           options.add(new SelectOption('','--Select Data Center --'));
        
           for( Schema.PicklistEntry f : ple)
           {
              options.add(new SelectOption(f.getLabel(), f.getValue()));
              System.debug(logginglevel.INFO,f.getLabel() + ',' + f.getValue());
           }
               
           return options;
    }
}

 

 

Thanks, Daniel

Hi,

 

I have been reading about rules around at least 75% of code must be tested successfully before it can be moved to production.  My problem is I am imagining the process and I am sure by experimenting I will figure it out; however, when dealing with a production environment I do not like the idea of experiementing.

 

QUESTIONS:

  1. When I move the class and the test class to production is it automically active code or do I have to activate it?
  2. Do I have to keep the Test Class code in production all the time with the associate class?
  3. If I have a class that has temporary variables in the class code just for testing so that I can get 100% code coverage then move it to production will I be able to comment those variables out in the test class and controller class after I move it to production? 

If the answer is no than I may need some help on how to test a class that I need to know the new record id.  The code below is a portion of the controller and the second code snippet is a portion of the test class that tests the controller.

 

CONTROLLER CLASS:

// This class clones an opportunity and all related partner records
public class OppCloneWithPartnerRecsController {
 
    //added an instance varaible for the standard controller
    private ApexPages.StandardController controller {get; set;}
     // add the instance for the variables being passed by id on the url
    private Opportunity opp {get;set;}
    
    // set the id of the record that is created -- ONLY USED BY THE TEST CLASS
    public ID newRecordId {get;set;}    
    // set the force error  
    public boolean forceError { get;set; }
    //-------------------------------------------- ONLY USED BY THE TEST CLASS

 
    // initialize the controller
    public OppCloneWithPartnerRecsController(ApexPages.StandardController controller) { 
        //initialize the stanrdard controller
        this.controller = controller;
        // load the current record
        opp = (Opportunity)controller.getRecord();       
    }
 

 

TEST CLASS:

...

        Test.startTest();

//        ext.forceError = false;

        
        // call the oppCloneWithPartners method
        PageReference ref = ext.oppCloneWithPartners();
        // create the matching page reference
        PageReference redir = new PageReference('/'+ext.newRecordId); 
 
        // make sure the user is sent to the correct url
        System.assertEquals(ref.getUrl(),redir.getUrl());
 
        // check that the new Opp was created successfully
       Opportunity newOpp = [select id from Opportunity where id = :ext.newRecordId];
        System.assertNotEquals(newOpp, null);
        // check that the line item was created
        List<Partner> newItems = [Select p.Id From Partner p where p.OpportunityId = :newOpp.id];
        System.assertEquals(newItems.size(),2);
 
        // Switch back to runtime context
        Test.stopTest(); 
    } 

...

 

 

Salesforce has some great articles at developer.force.com and the Force.com community has chipped in with some excellent content but there is still something missing.  There’s a beginning book for Salesforce users (Salesforce.com for Dummies) and an advanced Force.com development book (Development with the Force.com Platform) but there is no comprehensive guide for analysts and developers just coming on to the platform. This is the niche that Wes and I want to fill with our new book:

The Salesforce Handbook
A newcomer’s guide to building applications on Salesforce.com and the Force.com Platform

We are targeting this book for business owners, analysts and developers  just getting started. Just think of all the new Vmforce Java developers that will be investigating the Force.com platform in the coming months! So if your boss walks into your office and says, “Let’s look at this Salesforce.com thing and see if we can build something”. We want this to be a reference that you can pick up and essentially find out everything you need to know about Salesforce from a high level with links to other articles, sample code, blogs, Salesforce docs, etc. that interest you.

SF doesn't allow ISCHANGED($RecordType.Name).    I need a way t to write a workflow rule to make field updates if someone changes the case record type.

 

 

We are loading external data via a nightly job from SQL Server using DBAmp.

 

Some of the fields we populate need to be picklists so that users can easily select filter criteria in reports.

 

Is there a way that I can change the pick list values automatically when new values get added in the source system?

 

 

  • March 10, 2010
  • Like
  • 0
Just out of curiosity, is it possible to dynamical create an object at a certain time? For example, I need to create an opportunity based on information from a contract 90 days before the contracts expiration date. It has to be done automatically without imput from anyone on that 90 day mark. Can anyone suggest a way to get that done or throw any ideas out?
  • March 10, 2010
  • Like
  • 0

I want get the WebTab URL from Apex Controller. I got a  describeTabs Link Example But i iam getting Error SysLog:

 

19:04:27 ERROR - Compile error: Invalid type: DescribeTabSetResult

 

In Eclipse IDE: Invalid type: DescribeTabSetResult  

 

Code:

private void describeTabSet (){  try {    DescribeTabSetResult[] dtsrs = binding.describeTabs();    System.out.println("There are " + new Integer(dtsrs.length).toString() +                        " tabsets defined.");    for (int i=0;i<dtsrs.length;i++) {      System.out.println("Tabset " + new Integer(i + 1).toString() + ":");      DescribeTabSetResult dtsr = dtsrs[i];      String tabSetLabel = dtsr.getLabel();      String logoUrl = dtsr.getLogoUrl();      boolean isSelected = dtsr.isSelected();      DescribeTab[] tabs = dtsr.getTabs();      System.out.println("Label is " + tabSetLabel + " logo url is " + logoUrl + ",                 there are " + new Integer(tabs.length) + " tabs defined in this set.                 This tab is selected: " + isSelected);      for (int j=0;j<tabs.length;j++) {        DescribeTab tab = tabs[j];        String tabLabel = tab.getLabel();        String objectName = tab.getSobjectName();        String tabUrl = tab.getUrl();        System.out.println("\tTab " + new Integer(j + 1) + ": \n\t\tLabel = " +            tabLabel + "\n\t\tObject details on tab: " + objectName + "\n\t\t" +           "Url to tab: " + tabUrl);      }    }  } catch (Exception ex) {    System.out.println("\nFailed to describe tabs, error message was: \n" +                        ex.getMessage());  } 

}

 

Thanks in advance for your valuable suggestion.