• crop1645v2
  • NEWBIE
  • 35 Points
  • Member since 2013

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 21
    Replies
I have an Apex Controller that works but I cannot get the test class to compile. It blows with the following error.

System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Record Type ID: this ID value isn't valid for the user: : [RecordTypeId]

The user I am using is authorized to record types "CAD", "Install"  

Name      Id
CAD        012W00000004S1FIAU
Install     012W00000004S1AIAU

When I run the test scripts I pull out the user ID and query for the record type I want to use.

The Debug logs are returning the correct ID's
User: 00550000001J8elAAC
RecordTypeID: 012W00000004S1AIAU

The hardcoded record type id does not work either.

The Test Script Looks like this:

@isTest
public with sharing class createProjectFromProject_Test {
// Method for testing
     public static testmethod void testCreateProjectFromProject_Test()   
     {     
     //Start Test
     Test.startTest();     
           
     // Get User Settings       
     User UserSetting = [select name, TimeZoneSidKey,
          LocaleSidKey,
          EmailEncodingKey,
          ProfileId,                            
          LanguageLocaleKey
          from User where name = 'Administrator' LIMIT 1];
         
     // Create Test User       
     User theTestUser1 = new User (FirstName = 'Test',
                            LastName = 'User',
                            Username = 'Test.User@ki.com',
                            Email =  'Test.User@ki.com',
                            Alias = 'TestUser',
                            TimeZoneSidKey = UserSetting.TimeZoneSidKey,
                            LocaleSidKey = UserSetting.LocaleSidKey,
                            EmailEncodingKey = UserSetting.EmailEncodingKey,
                            ProfileId = UserSetting.ProfileId,
                            LanguageLocaleKey = UserSetting.LanguageLocaleKey);
                            insert theTestUser1;
                           
                           
                            Id theAdminUserID = [SELECT Id FROM  User where name = 'Administrator' LIMIT 1].id;
                           
// Create Account   
      Account theTestAccount = new Account(Name = 'Test Opp. To Project  Account', Type = 'End User', Site = 'Test Account City', MARKET_CODE__C = 'University & College Market – 1', SALES_REP__C = 'Zakowski, Ted', STATE__C = 'WI', DISTRICT__C = '125',  Region__c = '1', FIELD_SALES_REP_NUMBER__C = '12542', DISTRICT_NAME__C = 'KI-New York', DISTRICT_TYPE__C  = 'Direct',   Owner = theTestUser1);       
      insert theTestAccount;
        
      RecordType theRecordType = [SELECT Id FROM RecordType where Name = 'Install' and SobjectType = 'tenrox__c' Limit 1];
  

// Create Project     
       Tenrox__c TheOrigProject = new Tenrox__c (Name =  'Test',
      Description__c =  'Test',
      Start_Date__c = Date.Today(),
      Account__c = theTestAccount.id,
     Finish_Date__c =  date.valueOf('2039-12-31'),
     OwnerId = theAdminUserID,
     RecordTypeId = therecordtype.id);       
        insert TheOrigProject;       
       theProjectID = TheOrigProject.id;
 
       /*****************************************************************/       
       /*                   Data Setup Complete                         */       
       /*****************************************************************/                
       /*****************************************************************/       
       /*                       Test Scenario                          */       
       /*****************************************************************/
      // Test Controller        
  
      ApexPages.StandardController controller1 = new ApexPages.StandardController(TheOrigProject);
 
   createProjectFromProject controller2 = new createProjectFromProject(controller1);
   
     controller2.autorun();
   
  PageReference pageRef = Page.createProjectFromProject;
  pageRef.getParameters().put('id', String.valueOf(TheOrigProject.id));
  Test.setCurrentPage(pageRef);
  controller2.autorun();
  
  Test.stopTest();
    
   }
}
leading "zeros" are eliminationg in zip code when export to csv file.

wrote formula field: " ' "  & Zip_code__c

by using this leading 'zeros' coming but  ' special character also appearing before leading zero in csv file

I am currently working on getting test cases to work so I can start to alter the main code, however whenever I try to run my test cases they fail and I get the following error "too many SOQL queries: 101."  When I check to see where this error is occuring it points to the top of the program at "@isTest(SeeAllData=true)."  What does this mean , and how would I go about fixing the problem?
I have an inner class that has a method I want to call using a Map.  I get the following error when trying to save the VF Page.  The CommandLink line of code is causing the error.

Error Error: java.lang.UnsupportedOperationException
Error Error: null

Here is the code:
public with sharing class TestInnerClass
{
  class wA
  {
 
public  Account         a    {get;set;}
public wA(Account a){this.a = a;}
public void saveAcc(){upsert a;}
 
  }
  public Map<String,wA> mapWAcc {get;set;}

  public TestOuterClass()
  {
  mapWAcc  = new Map<String,wA>(); 
  mapWAcc.put('Test',new wA(new Account(Name='Test')));
  }
}

<apex:page controller="TestOuterClass">
<apex:form >
    <apex:repeat value="{!mapWAcc}" var="idMap">
    <apex:repeat value="{!mapWAcc[idMap]}" var="wAcc">
        <apex:inputField value="{!wAcc.a.Name}"/>
        <apex:commandLink value="Save" action="{!wAcc.saveAcc}"/>
    </apex:repeat>
    </apex:repeat>
</apex:form>
</apex:page>

Thanks
  • February 24, 2014
  • Like
  • 0
I have seen some discussion on these problems and some solutions too, however i cannot find on the addresses my issue.
I am trying to do the following
<ol>
<li>Item 1</li>
<apex:outputPanel rendered="IF Statement">
     <li>Optional item a</li>
</apex:outputPanel>
<li>Item 2</li>
</ol>

This renders on the PDF as:
     Item 1
     Optional item a
     Item 2
Whereas in html:
     1. Item 1 
     2. Optional item a
     3. Item 2

I know there is incomplete support for the pdf rendering engine but does anyone know of a workaround for this?
  • February 24, 2014
  • Like
  • 0
Here's a screenshot of what i see in developer console, it's missing executable logs and I don't see the execution logs like in this link http://www.salesforce.com/us/developer/docs/apex_workbook/Content/apex1_2.htmUser-added image
I have written an application with bespoke VF pages. I have used standard <apex:inputfield> tags throughout, but I do not want users to be able to click on fields which SF automatically makes into a link - this would take users to the standard SF page, which is something I do not want.

Anyone know how to disable this behaviour?
Is returning null in catch block is best practice..

String strOpportunityRecord;
        Opportunity sourceOpportunityRecord = new Opportunity();
        try {
            strOpportunityRecord =  'SELECT ' + Queriablefields +'Name From Opportunity where id =: sourceOpportunityId';
            if (strOpportunityRecord != null) {
                sourceOpportunityRecord = Database.query(strOpportunityRecord) ;
            }
           return sourceOpportunityRecord;
        }
        catch(QueryException ex) {
            system.debug(ex);
            return null;
        }
    }
Hi folks, hope you can help.

I recently company policy change means that we're not allowed to have any 8 digit account numbers stored on cases received via Email-to-Case.

Is there any way to get Salesforce to alert the Salesforce admin of any instances or even possibly remove the 8 digit account numbers from the case entirely or blank out the first 5 digits perhaps?

Any help on this would be greatly appreciated.

Many thanks,
Dave
I have a custom list button that operates on a custom object.  The expected/intended behavior is that when the user checks the box next to a related list item and then clicks the custom button, my custom VF page will load and I will have access to the list of records that were selected by the user.  The was working find before the spring 14 update (but I have tried to roll back the page and controller extension to earlier versions, still having the same issue).

What is happening now is if I select the custom button without selecting any records my VF page loads fine.  If I select records from the related list before I click the custom button the page redirects, but never fully loads.  There is no new entry in developer console log and I am left with w blank screen
   I have also tried the example from the documentation here: 
http://www.salesforce.com/us/developer/docs/pages/Content/pages_quick_start_massupdate.htm?SearchType=Stem&Highlight=getSelected (http://www.salesforce.com/us/developer/docs/pages/Content/pages_quick_start_massupdate.htm?SearchType=Stem&Highlight=getSelected)

  And i get the same blank page result when I select records before clicking the custom button.

Any ideas?

  • February 15, 2014
  • Like
  • 0
Hello,
I am trying to write a trigger for Accounts so that when an Account Owner is changed, the owner of the custom object (in this case "Pricings" or Pricing__c) is changed. I was successfully able to do this for contacts and opportunities, but something about this code and the custom object are not meshing. I know it has to do with that SOQL query, but I'm at my wits end trying to fix it. Can someone please advise?
Thank you,

trigger reassignRelatedPricings on Account (after update) {
      Set<Id> accountIds = new Set<Id>(); //set for holding the Ids of all Accounts that have been assigned to new Owners
      Map<Id, String> oldOwnerIds = new Map<Id, String>(); //map for holding the old account ownerId
      Map<Id, String> newOwnerIds = new Map<Id, String>(); //map for holding the new account ownerId
      Pricing__c[] PricingUpdates = new Pricing__c[0]; //Pricing sObject to hold OwnerId updates
     
      for (Account a : Trigger.new) { //for all records
         if (a.OwnerId != Trigger.oldMap.get(a.Id).OwnerId) {
            oldOwnerIds.put(a.Id, Trigger.oldMap.get(a.Id).OwnerId); //put the old OwnerId value in a map
            newOwnerIds.put(a.Id, a.OwnerId); //put the new OwnerId value in a map
            accountIds.add(a.Id); //add the Account Id to the set
         }
      }
      if (!accountIds.isEmpty()) { //if the accountIds Set is not empty
         for(Account acct : [Select id,Account__c, Account_Owner__c from Pricing__c where Account__c in:accIds]) { //SOQL to get Pricing for updated Accounts
            String newOwnerId = newOwnerIds.get(act.id); //get the new OwnerId value for the account
            String oldOwnerId = oldOwnerIds.get(act.id); //get the old OwnerId value for the account
            for (Pricing__c p : act.Pricing__cs) { //for all pricings
               if (p.Account_owner__c == oldOwnerId) { //if the pricing is assigned to the old account Owner
                  Pricing__c updatedPricing = new Pricing__c(Id = p.Id, Account_owner__c = newOwnerId); //create a new Contact sObject
                  PricingUpdates.add(updatedPricing__c); //add the pricing to our List of updates
               }
            }
         }
         update PricingUpdates; //update the Pricings
   }
}
I have an Apex Controller that works but I cannot get the test class to compile. It blows with the following error.

System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Record Type ID: this ID value isn't valid for the user: : [RecordTypeId]

The user I am using is authorized to record types "CAD", "Install"  

Name      Id
CAD        012W00000004S1FIAU
Install     012W00000004S1AIAU

When I run the test scripts I pull out the user ID and query for the record type I want to use.

The Debug logs are returning the correct ID's
User: 00550000001J8elAAC
RecordTypeID: 012W00000004S1AIAU

The hardcoded record type id does not work either.

The Test Script Looks like this:

@isTest
public with sharing class createProjectFromProject_Test {
// Method for testing
     public static testmethod void testCreateProjectFromProject_Test()   
     {     
     //Start Test
     Test.startTest();     
           
     // Get User Settings       
     User UserSetting = [select name, TimeZoneSidKey,
          LocaleSidKey,
          EmailEncodingKey,
          ProfileId,                            
          LanguageLocaleKey
          from User where name = 'Administrator' LIMIT 1];
         
     // Create Test User       
     User theTestUser1 = new User (FirstName = 'Test',
                            LastName = 'User',
                            Username = 'Test.User@ki.com',
                            Email =  'Test.User@ki.com',
                            Alias = 'TestUser',
                            TimeZoneSidKey = UserSetting.TimeZoneSidKey,
                            LocaleSidKey = UserSetting.LocaleSidKey,
                            EmailEncodingKey = UserSetting.EmailEncodingKey,
                            ProfileId = UserSetting.ProfileId,
                            LanguageLocaleKey = UserSetting.LanguageLocaleKey);
                            insert theTestUser1;
                           
                           
                            Id theAdminUserID = [SELECT Id FROM  User where name = 'Administrator' LIMIT 1].id;
                           
// Create Account   
      Account theTestAccount = new Account(Name = 'Test Opp. To Project  Account', Type = 'End User', Site = 'Test Account City', MARKET_CODE__C = 'University & College Market – 1', SALES_REP__C = 'Zakowski, Ted', STATE__C = 'WI', DISTRICT__C = '125',  Region__c = '1', FIELD_SALES_REP_NUMBER__C = '12542', DISTRICT_NAME__C = 'KI-New York', DISTRICT_TYPE__C  = 'Direct',   Owner = theTestUser1);       
      insert theTestAccount;
        
      RecordType theRecordType = [SELECT Id FROM RecordType where Name = 'Install' and SobjectType = 'tenrox__c' Limit 1];
  

// Create Project     
       Tenrox__c TheOrigProject = new Tenrox__c (Name =  'Test',
      Description__c =  'Test',
      Start_Date__c = Date.Today(),
      Account__c = theTestAccount.id,
     Finish_Date__c =  date.valueOf('2039-12-31'),
     OwnerId = theAdminUserID,
     RecordTypeId = therecordtype.id);       
        insert TheOrigProject;       
       theProjectID = TheOrigProject.id;
 
       /*****************************************************************/       
       /*                   Data Setup Complete                         */       
       /*****************************************************************/                
       /*****************************************************************/       
       /*                       Test Scenario                          */       
       /*****************************************************************/
      // Test Controller        
  
      ApexPages.StandardController controller1 = new ApexPages.StandardController(TheOrigProject);
 
   createProjectFromProject controller2 = new createProjectFromProject(controller1);
   
     controller2.autorun();
   
  PageReference pageRef = Page.createProjectFromProject;
  pageRef.getParameters().put('id', String.valueOf(TheOrigProject.id));
  Test.setCurrentPage(pageRef);
  controller2.autorun();
  
  Test.stopTest();
    
   }
}
I am trying to control when a user is allowed to enter something into an input field on a visual force page. Something like this:

{!IF(some-condition,<apex:inputField value="{!budget.Jan_Season__c}" />,<apex:outputField value="{!budget.Jan_Season__c}" />)}

When I try to use this, it complains about EL Expression Unbalanced.

Any suggestions would be greatly appreciated.
My Controller :

public class clsmap{
public String s{public get;public set;}
public clsmap()
{
Map<String,String> strmap=new Map<String,String>{'a'=>'apple','c'=>'cat'};
strmap.put('p','pen');
strmap.get('b');
System.debug(strmap.get('a'));
for(String s:strmap.keyset()){
if(s=='b'){
s+='cil';
system.debug(s);
}
}
}
}
My Page:
<apex:page controller="clsmap">
<apex:form >
Values:
<br/>
    <apex:outputtext value="{!s}"/><br/>
</apex:form>
</apex:page>

here i want to display a value of a string s.can any one help me pls?

Thanks