• QotD
  • NEWBIE
  • 5 Points
  • Member since 2013
  • Developer

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 3
    Replies
I'm planning to put an app up for Security Review and am working on CRUD/FLS, and was wondering if there was a way to check if the current user has Send Email permissions so I can put an if statement around the send email code.
  • April 09, 2016
  • Like
  • 0
I created a Managed-Beta Package and all my test classes failed after I added the Namespace prefix. They worked before and it is all still on the same org.
Here is the error I am getting
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]
And here is one of the test classes
@isTest
public class Dog_Forms_Evaluations_Notes_Test {
    private static testmethod void behaviorMgt(){

        User u = [select id from user where profile.name like '%System Administrator%' and isactive = true limit 1 ];
         
        List<RecordType> brTypes = [SELECT Name,Id FROM RecordType WHERE sObjectType = 'Dog_Forms_Evaluations_Notes__c' AND isActive=true];    
        List<RecordType> rTypes = [SELECT Name,Id FROM RecordType WHERE sObjectType = 'Dog__c' AND isActive=true];    

        Map<String,String> bRecordTypes = new Map<String,String>{};
        Map<String,String> DogRecordTypes = new Map<String,String>{};
        for(RecordType brt: brTypes)
        {
            bRecordTypes.put(brt.Name,brt.Id);
        }  
        for(RecordType rt: rTypes)
        {
            DogRecordTypes.put(rt.Name,rt.Id);
        }  
        System.RunAs(u){
            Dog__c d = new Dog__c(
                Name = 'TestDog', 
                RecordTypeId = DogRecordTypes.get('In Training'),
                OwnerId = u.id
            );
            insert d;
            
            Dog_Forms_Evaluations_Notes__c f = new Dog_Forms_Evaluations_Notes__c(
                RecordTypeId = bRecordTypes.get('Behavior Issue Management'),
                Dog__c = d.id,
                Date__c = system.today(),
                Describe_Incident_or_Behavior_Issue__c = 'Test',
                Behavior_Management_Plan__c = 'Test',
                Check_Effectiveness_In_Number__c = 2,
                Check_Effectiveness_In__c = 'Month(s)'
            );
            insert f;     

            Dog_Forms_Evaluations_Notes__c f2 = new Dog_Forms_Evaluations_Notes__c(
                RecordTypeId = bRecordTypes.get('Behavior Issue Management'),
                Dog__c = d.id,
                Date__c = system.today(),
                Describe_Incident_or_Behavior_Issue__c = 'Test',
                Behavior_Management_Plan__c = 'Test',
                Check_Effectiveness_In_Number__c = 2,
                Check_Effectiveness_In__c = 'Week(s)'
            );
            insert f2; 
            
            Dog_Forms_Evaluations_Notes__c f3 = new Dog_Forms_Evaluations_Notes__c(
                RecordTypeId = bRecordTypes.get('Behavior Issue Management'),
                Dog__c = d.id,
                Date__c = system.today(),
                Describe_Incident_or_Behavior_Issue__c = 'Test',
                Behavior_Management_Plan__c = 'Test',
                Check_Effectiveness_In_Number__c = 2,
                Check_Effectiveness_In__c = 'Day(s)'
            );
            insert f3;   
            
            Integer getTask = [SELECT Count() FROM Task WHERE Subject LIKE 'Behavior Management Follow Up for%' AND WhatId =: d.Id];
            System.assertEquals(3,getTask);      
            
          // error code test && bulk test      
          // 
          List<Dog_Forms_Evaluations_Notes__c> dogErrors = new List<Dog_Forms_Evaluations_Notes__c>();
            for (Integer i=0;i<200;i++) {
    
                Dog_Forms_Evaluations_Notes__c f4 = new Dog_Forms_Evaluations_Notes__c(
                RecordTypeId = bRecordTypes.get('Behavior Issue Management'),
                Dog__c = d.id,
                Date__c = system.today(),
                Describe_Incident_or_Behavior_Issue__c = 'Test',
                Behavior_Management_Plan__c = 'Test',
                Check_Effectiveness_In_Number__c = 2,
                Check_Effectiveness_In__c = 'Wrong'
            );
                dogErrors.add(f4);
    
            }      
            try{
                insert dogErrors;
            }catch(Exception e) {
                System.Assert(e.getMessage().contains('Picklist value for field Check Effectiveness In'));
            }
            
              
    	}
    }
}

 
  • April 07, 2016
  • Like
  • 0
I'm trying to add pagination to a page that uses a Standard controller and an extension. When I try to use something like:
Page: <apex:outputText value="{!PageNumber} of {! CEILING(ResultSize / PageSize) }"/>
I get the error Error: Unknown property 'Client_Tracker__cStandardController.PageNumber'
I guess it doesn't work because I need to tell it to check the extension and not the Standard Controller but I'm not sure how. 

Controller Code: 
public class Client_PublicAccessTestsLists_Controller {
    private List< Forms_Evaluations__c > publicAccessTests;
    private Client_Tracker__c clientTracker; 
    
    public Client_PublicAccessTestsLists_Controller(ApexPages.StandardController controller) {
        this.clientTracker= (Client_Tracker__c)controller.getRecord();
    }
    
    public List<Forms_Evaluations__c> getpublicAccessTests()
    {
        RecordType rt = [SELECT Id FROM RecordType WHERE DeveloperName = 'Public_Access_Test' AND sobjecttype = 'Forms_Evaluations__c' LIMIT 1];
        publicAccessTests = [SELECT id, Name, Status__c, Date__c, Client_Tracker__c FROM Forms_Evaluations__c WHERE Client_Tracker__r.id = :clientTracker.id AND RecordTypeId = :rt.id ORDER BY Date__c DESC];
        return publicAccessTests;
    }
}

Visualforce Page:
<apex:page standardController="Client_Tracker__c" extensions="Client_PublicAccessTestsLists_Controller">
<apex:form >
 <apex:pageMessages />

<apex:pageblock id="CustomList" title="Public Access Tests List">
   <apex:pageBlockTable value="{!publicAccessTests}" var="pat" rendered="{!NOT(ISNULL(publicAccessTests))}">
        <apex:column headerValue="Action" width="60px">
            <apex:outputLink value="{! URLFOR($Action.Forms_Evaluations__c.Edit, pat.Id, [retURL=pat.Client_Tracker__c]) }" target="_top"
            style="color:#015ba7;">
                Edit
            </apex:outputLink>
            <span style="color:grey;">|</span>&nbsp;
            <apex:outputLink value="{! URLFOR($Action.Forms_Evaluations__c.Delete, pat.Id, [retURL=pat.Client_Tracker__c]) }"
            style="color:#015ba7;">Del
            </apex:outputLink>
        </apex:column>
        <apex:column value="{!pat.Name}"/>
        <apex:column value="{!pat.Status__c}"/>
        <apex:column value="{!pat.Date__c}"/>
   </apex:pageBlockTable>
   <apex:outputLabel value="No records to display" rendered="{!(ISNULL(publicAccessTests))}" styleClass="noRowsHeader"></apex:outputLabel>
    <!-- Pagination -->
    <table style="width: 100%"><tr>
    
        <td>
            <!-- doesn't work -->
            <apex:outputText value="{!PageNumber} of {! CEILING(ResultSize / PageSize) }"/>
        </td>            
    
        <td align="center">   
        </td>
                
        <td align="right">
        </td>
    
    </tr></table> 
</apex:pageblock>

</apex:form>
</apex:page>

I've been doing every search I can think of to find the answer but at this point my brain is fried.
Thanks for any help
  • February 08, 2016
  • Like
  • 0
I can't figure out this error. It only happens on the 3 triggers I have created on Opportunities that send emails. It always points to the "Messaging.sendEmail(emails);" line. These triggers worked before, and then I installed the NPSP 3.0 and this error started appearing. NPSP says it has nothing to do with them, which is fine, I just know that's the only thing we changed. We need to keep NPSP 3.0 because we were having different errors with 2.0.

Here is the full error

Upsert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ClientCare_TeamTrainingFundingReceived: execution of AfterInsert

caused by: System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Task: bad field names on insert/update call: ActivityOriginType: [ActivityOriginType]

Trigger.ClientCare_TeamTrainingFundingReceived: line 148, column 1: []

 
  • October 22, 2015
  • Like
  • 0

Hi,

I am trying to get the ID of a lookup field so I can populate a field on a new record. Basically I need the ID of Birth_Record__c.Dame__c instead of the value so I don't get the Malformed ID error. The line that's causing the error is in bold red. Thank you!  

 

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/25.0/apex.js")}

var pupIn = "{!Birth_Record__c.dog_Name2__c}";
if (pupIn != "") {
alert("A dog record has already been created for this birth record. Please click the link next to Puppy Name to view that record.")
}else{
var dog = new sforce.SObject("Dog__c");

dog.Name = "{!Birth_Record__c.Name}";
dog.sex__c = "{!Birth_Record__c.Gender__c}";
alert("{!Birth_Record__c.Dame__c}");
dog.Dame__c = "{!Birth_Record__c.Dame__c}";

var by = "{!YEAR( DATEVALUE(Birth_Record__c.Birth__c) )}";
var bm = "{!MONTH( DATEVALUE(Birth_Record__c.Birth__c) )}";
if (bm.length == 1){
bm = "0"+bm;
}


var bd = "{!DAY( DATEVALUE(Birth_Record__c.Birth__c) )}";
if (bd.length == 1){
bd = "0"+bd;
}

var b = by+"-"+bm+"-"+bd;
dog.birthdate__c = b;

var result = sforce.connection.create([dog]);

if(result[0].getBoolean("success")){
var nextPg = result[0].id;

var newRecords = [];
var c = new sforce.SObject("Birth_Record__c");
c.id ="{!Birth_Record__c.Id}";
c.dog_Name2__c = result[0].id;
newRecords.push(c);
result = sforce.connection.update(newRecords);

window.location = "/" + nextPg;
}else{
alert('Could not create record '+result);
}
}

  • September 23, 2013
  • Like
  • 0
I created a Managed-Beta Package and all my test classes failed after I added the Namespace prefix. They worked before and it is all still on the same org.
Here is the error I am getting
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]
And here is one of the test classes
@isTest
public class Dog_Forms_Evaluations_Notes_Test {
    private static testmethod void behaviorMgt(){

        User u = [select id from user where profile.name like '%System Administrator%' and isactive = true limit 1 ];
         
        List<RecordType> brTypes = [SELECT Name,Id FROM RecordType WHERE sObjectType = 'Dog_Forms_Evaluations_Notes__c' AND isActive=true];    
        List<RecordType> rTypes = [SELECT Name,Id FROM RecordType WHERE sObjectType = 'Dog__c' AND isActive=true];    

        Map<String,String> bRecordTypes = new Map<String,String>{};
        Map<String,String> DogRecordTypes = new Map<String,String>{};
        for(RecordType brt: brTypes)
        {
            bRecordTypes.put(brt.Name,brt.Id);
        }  
        for(RecordType rt: rTypes)
        {
            DogRecordTypes.put(rt.Name,rt.Id);
        }  
        System.RunAs(u){
            Dog__c d = new Dog__c(
                Name = 'TestDog', 
                RecordTypeId = DogRecordTypes.get('In Training'),
                OwnerId = u.id
            );
            insert d;
            
            Dog_Forms_Evaluations_Notes__c f = new Dog_Forms_Evaluations_Notes__c(
                RecordTypeId = bRecordTypes.get('Behavior Issue Management'),
                Dog__c = d.id,
                Date__c = system.today(),
                Describe_Incident_or_Behavior_Issue__c = 'Test',
                Behavior_Management_Plan__c = 'Test',
                Check_Effectiveness_In_Number__c = 2,
                Check_Effectiveness_In__c = 'Month(s)'
            );
            insert f;     

            Dog_Forms_Evaluations_Notes__c f2 = new Dog_Forms_Evaluations_Notes__c(
                RecordTypeId = bRecordTypes.get('Behavior Issue Management'),
                Dog__c = d.id,
                Date__c = system.today(),
                Describe_Incident_or_Behavior_Issue__c = 'Test',
                Behavior_Management_Plan__c = 'Test',
                Check_Effectiveness_In_Number__c = 2,
                Check_Effectiveness_In__c = 'Week(s)'
            );
            insert f2; 
            
            Dog_Forms_Evaluations_Notes__c f3 = new Dog_Forms_Evaluations_Notes__c(
                RecordTypeId = bRecordTypes.get('Behavior Issue Management'),
                Dog__c = d.id,
                Date__c = system.today(),
                Describe_Incident_or_Behavior_Issue__c = 'Test',
                Behavior_Management_Plan__c = 'Test',
                Check_Effectiveness_In_Number__c = 2,
                Check_Effectiveness_In__c = 'Day(s)'
            );
            insert f3;   
            
            Integer getTask = [SELECT Count() FROM Task WHERE Subject LIKE 'Behavior Management Follow Up for%' AND WhatId =: d.Id];
            System.assertEquals(3,getTask);      
            
          // error code test && bulk test      
          // 
          List<Dog_Forms_Evaluations_Notes__c> dogErrors = new List<Dog_Forms_Evaluations_Notes__c>();
            for (Integer i=0;i<200;i++) {
    
                Dog_Forms_Evaluations_Notes__c f4 = new Dog_Forms_Evaluations_Notes__c(
                RecordTypeId = bRecordTypes.get('Behavior Issue Management'),
                Dog__c = d.id,
                Date__c = system.today(),
                Describe_Incident_or_Behavior_Issue__c = 'Test',
                Behavior_Management_Plan__c = 'Test',
                Check_Effectiveness_In_Number__c = 2,
                Check_Effectiveness_In__c = 'Wrong'
            );
                dogErrors.add(f4);
    
            }      
            try{
                insert dogErrors;
            }catch(Exception e) {
                System.Assert(e.getMessage().contains('Picklist value for field Check Effectiveness In'));
            }
            
              
    	}
    }
}

 
  • April 07, 2016
  • Like
  • 0
I'm trying to add pagination to a page that uses a Standard controller and an extension. When I try to use something like:
Page: <apex:outputText value="{!PageNumber} of {! CEILING(ResultSize / PageSize) }"/>
I get the error Error: Unknown property 'Client_Tracker__cStandardController.PageNumber'
I guess it doesn't work because I need to tell it to check the extension and not the Standard Controller but I'm not sure how. 

Controller Code: 
public class Client_PublicAccessTestsLists_Controller {
    private List< Forms_Evaluations__c > publicAccessTests;
    private Client_Tracker__c clientTracker; 
    
    public Client_PublicAccessTestsLists_Controller(ApexPages.StandardController controller) {
        this.clientTracker= (Client_Tracker__c)controller.getRecord();
    }
    
    public List<Forms_Evaluations__c> getpublicAccessTests()
    {
        RecordType rt = [SELECT Id FROM RecordType WHERE DeveloperName = 'Public_Access_Test' AND sobjecttype = 'Forms_Evaluations__c' LIMIT 1];
        publicAccessTests = [SELECT id, Name, Status__c, Date__c, Client_Tracker__c FROM Forms_Evaluations__c WHERE Client_Tracker__r.id = :clientTracker.id AND RecordTypeId = :rt.id ORDER BY Date__c DESC];
        return publicAccessTests;
    }
}

Visualforce Page:
<apex:page standardController="Client_Tracker__c" extensions="Client_PublicAccessTestsLists_Controller">
<apex:form >
 <apex:pageMessages />

<apex:pageblock id="CustomList" title="Public Access Tests List">
   <apex:pageBlockTable value="{!publicAccessTests}" var="pat" rendered="{!NOT(ISNULL(publicAccessTests))}">
        <apex:column headerValue="Action" width="60px">
            <apex:outputLink value="{! URLFOR($Action.Forms_Evaluations__c.Edit, pat.Id, [retURL=pat.Client_Tracker__c]) }" target="_top"
            style="color:#015ba7;">
                Edit
            </apex:outputLink>
            <span style="color:grey;">|</span>&nbsp;
            <apex:outputLink value="{! URLFOR($Action.Forms_Evaluations__c.Delete, pat.Id, [retURL=pat.Client_Tracker__c]) }"
            style="color:#015ba7;">Del
            </apex:outputLink>
        </apex:column>
        <apex:column value="{!pat.Name}"/>
        <apex:column value="{!pat.Status__c}"/>
        <apex:column value="{!pat.Date__c}"/>
   </apex:pageBlockTable>
   <apex:outputLabel value="No records to display" rendered="{!(ISNULL(publicAccessTests))}" styleClass="noRowsHeader"></apex:outputLabel>
    <!-- Pagination -->
    <table style="width: 100%"><tr>
    
        <td>
            <!-- doesn't work -->
            <apex:outputText value="{!PageNumber} of {! CEILING(ResultSize / PageSize) }"/>
        </td>            
    
        <td align="center">   
        </td>
                
        <td align="right">
        </td>
    
    </tr></table> 
</apex:pageblock>

</apex:form>
</apex:page>

I've been doing every search I can think of to find the answer but at this point my brain is fried.
Thanks for any help
  • February 08, 2016
  • Like
  • 0

Hi,

I am trying to get the ID of a lookup field so I can populate a field on a new record. Basically I need the ID of Birth_Record__c.Dame__c instead of the value so I don't get the Malformed ID error. The line that's causing the error is in bold red. Thank you!  

 

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/25.0/apex.js")}

var pupIn = "{!Birth_Record__c.dog_Name2__c}";
if (pupIn != "") {
alert("A dog record has already been created for this birth record. Please click the link next to Puppy Name to view that record.")
}else{
var dog = new sforce.SObject("Dog__c");

dog.Name = "{!Birth_Record__c.Name}";
dog.sex__c = "{!Birth_Record__c.Gender__c}";
alert("{!Birth_Record__c.Dame__c}");
dog.Dame__c = "{!Birth_Record__c.Dame__c}";

var by = "{!YEAR( DATEVALUE(Birth_Record__c.Birth__c) )}";
var bm = "{!MONTH( DATEVALUE(Birth_Record__c.Birth__c) )}";
if (bm.length == 1){
bm = "0"+bm;
}


var bd = "{!DAY( DATEVALUE(Birth_Record__c.Birth__c) )}";
if (bd.length == 1){
bd = "0"+bd;
}

var b = by+"-"+bm+"-"+bd;
dog.birthdate__c = b;

var result = sforce.connection.create([dog]);

if(result[0].getBoolean("success")){
var nextPg = result[0].id;

var newRecords = [];
var c = new sforce.SObject("Birth_Record__c");
c.id ="{!Birth_Record__c.Id}";
c.dog_Name2__c = result[0].id;
newRecords.push(c);
result = sforce.connection.update(newRecords);

window.location = "/" + nextPg;
}else{
alert('Could not create record '+result);
}
}

  • September 23, 2013
  • Like
  • 0