• bryan.gilbert
  • NEWBIE
  • 50 Points
  • Member since 2010

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 1
    Questions
  • 16
    Replies

I'm trying to Upload the trigger below into our production environment and receiving the errors below. Test Coverage for the trigger is 85%. Not sure why I would get the errors below:

 

 

 

trigger ExpenseReportUpdate on Expense__c (before insert) {

Expense__c exp = Trigger.new[0];

date trx_d = exp.date__c;
Integer trx_m = trx_d.month();
Integer trx_y = trx_d.year();
String exname = exp.Employee_First_Name__c + ' ' + exp.Employee_Last_Name__c;
String exname_id;
String expR_id;
date trx_st = trx_d.toStartOfMonth();
date stdate = trx_st.addmonths(1);

    try {
        exname_id = [SELECT id
                    FROM User
                    WHERE name = :exname].id;
        }
        
    catch (QueryException e) {
        exname_id = [SELECT id
                    FROM User
                    WHERE name = 'Force Admin'].id;
        }
          
    try { 
    
        expR_id = [SELECT id
            FROM Expense_Report__c
            WHERE CALENDAR_MONTH(Statement_Date__c) = :trx_m
            AND CALENDAR_YEAR(Statement_Date__c)= :trx_y
            AND Employee__c = :exname_id].id; 
            
        exp.Expense_Report__c = expR_id;
       
        }
                    
    catch (QueryException e) {
            Expense_Report__c newER = new Expense_Report__c(Employee__c = exname_id, Statement_Date__c = stdate);
            insert newER;
            
            exp.Expense_Report__c = newER.id;       
    }
    
}

 

 

ERRORS I GET:

MyProfilePageController.testSave()            Failure Message: "System.QueryException: List has no rows for assignment to SObject", Failure Stack Trace: "Class.MyProfilePageController.testSave: line 78, column 35 External entry point"

"not even referencing this?"

ExpenseReportUpdateTest  Coverage of selected Apex Trigger is 0%, at least 1% test coverage is required

"coverage is 89%?"

Deploy Error Average test coverage across all Apex Classes and Triggers is 66%, at least 75% test coverage is required

"not sure why this is happening"

It seems like something obvious but it took me hours to find a way to set a DateTime field to the time when a record is created.   I am building a simple Change Managment system as my first real project in Salesforce. As the administrator I want a method for my users to request changes and log defects and I need to let them know when changes are deployed.

So I created a single custom object with a "Date Opened" field.

 

When the record is created I want this field to get the current time and then never to change again.

 

Solution (partial) create a trigger and use this code. Replace Change_Request__c with the name of your object.  Replace the Date_Opened__c field name too.

 

This trigger only fires when the record is inserted, or created.

 

Triggers operate in batch so it may process a set of records. That is why the assignment is in a for loop.

 

System.now() returns the local date time.

 

This is only a partial solution because the page layout of my custom object is not read only. Users can edit the date!.  I have set the field level permission to read-only but that didn't help. When, and if, I figure this out then I'll post back.

 

 

trigger SetOpenDate on Change_Request__c (before insert) {
    for (Change_Request__c chg : Trigger.new) {
        // Iterate over each sObject  
        chg.Date_Opened__c = System.now();
    }
}
I'm having an issue with Spring '07 Lightning Application Events. It seems that handlers of an application event are being notified multiple times for a single firing of the event. This can be replicated on various browsers. 

How to reproduce the error:
1) Create the below components and put them in a new lightning page for an object of your choice. 
2) Assign that page to a profile, app or org
3) Navigate to that object's list view and then drill down to the newly created page
4) Press the button. The console should show this:
Test2 receiving event
Test1 receiving event

5) Navigate back to the list view and drill down on another record
6) Press the button. The console should show this:
Test2 receiving event
Test1 receiving event
Test2 receiving event
Test1 receiving event

7) If you repeat steps 5 and 6, you will get an additional two lines in the console for each time you repeat the process. I.e., one firing of the event is causing the handlers to be notified multiple times. 

Incidentally, I don't have this problem in the community edition. It's only in the base lightning experience version that it crops up. Can anyone replicate this? Thanks. 

Component #1
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<aura:handler event="c:pvStateControlEvt" action="{!c.receiveEvent}"  phase="default" />
    <aura:registerEvent name="stateControlEvent" type="c:pvStateControlEvt"/>

I send and receive events
            <lightning:button label="sendEvent" aura:id="testButton" onclick="{!c.fireEvent}"/>

</aura:component>

Component #1 controller
({
fireEvent : function(component, event, helper) {
       var theEvent = $A.get("e.c:pvStateControlEvt");
        theEvent.fire();

},
receiveEvent : function(component, event, helper) {
        console.log("Test1 receiving event");
    }
})


Component #2
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<aura:handler event="c:pvStateControlEvt" action="{!c.receiveEvent}"  phase="default" />
    I receive events
</aura:component>

Component #2 controller
({
receiveEvent : function(component, event, helper) {
        console.log("Test2 receiving event");
    }
})

Event pvStateControlEvt
 
<aura:event type="APPLICATION" description="My event" >
        <aura:attribute name="myAttribute" type="String"/>
</aura:event>

 

I'm having issue in escaping a single quote in VisualForce page.

In my output label, I used

{!IF($Profile.Name=="Customer Portal User","My Open Service Requests","Company\'s Open Service Requests")}

 

The output on my VF page is Company\'s Open Service Requests. Its not escaping the single quote. 

 

I also tried "Company\'\'s Open Service Requests".

 

Thanks in advance for the help.

  • October 04, 2012
  • Like
  • 0

Hi all,

 

I'm using the following case statement to within a VF page to adjust some language.  Within one of the options is an apostrophe and I'm having difficulty escaping it.

 

Here's what I have:

{!case(MyOBJ__c.MyField__c,
'Any time',' at any time.',
'Based on Employer policy',' based on your employer\'s policy.',
'MERGE ERROR')}

 Doing this results in "based on your employer\'s policy" being displayed on the page.

 

Using \\'s results in a nasty looking Error: EL Expression Unbalanced: ...

 

And for grins, using \\\'s results in "based on your employer\\'s policy"

We are receiving an error while deploying to production:
MyProfilePageController.testSave System.QueryException: List has no rows for assignment to SObject
Class.MyProfilePageController.testSave: line 78, column 35

MyProfilePageController class is automatically generated, I mean we didn't write code for this.

 

 

/**
 * An apex class that keeps updates of a portal user in sync with its corresponding contact.
   Guest users are never able to access this page.
 */
public class MyProfilePageController {

    private User user;
    private boolean isEdit = false;
    
    public User getUser() {
        return user;
    }

    public MyProfilePageController() {
        user = [SELECT id, email, username, usertype, communitynickname, timezonesidkey, languagelocalekey, firstname, lastname, phone, title,
                street, city, country, postalcode, state, localesidkey, mobilephone, extension, fax, contact.email
                FROM User
                WHERE id = :UserInfo.getUserId()];
        // guest users should never be able to access this page
        if (user.usertype == 'GUEST') {
            throw new NoAccessException();
        }
    }
    
    public Boolean getIsEdit() {
        return isEdit;
    }
    
    public void edit() {
        isEdit=true;
    }    
    
    public void save() {
        if (user.contact != null) {              
            setContactFields(user.contact);
        }
        
        try {
            update user;
            if (user.contact != null) { 
                update user.contact;
            }
            isEdit=false;
        } catch(DmlException e) {
            ApexPages.addMessages(e);
        }
    }
    
    public PageReference changePassword() {
        return Page.ChangePassword;
    }
    
    public void cancel() {
        isEdit=false;
        user = [SELECT id, email, username, communitynickname, timezonesidkey, languagelocalekey, firstname, lastname, phone, title,
                street, city, country, postalcode, state, localesidkey, mobilephone, extension, fax, contact.email
                FROM User
                WHERE id = :UserInfo.getUserId()];
    }
    
    private void setContactFields(Contact c) {
        c.title = user.title;
        c.firstname = user.firstname;
        c.lastname = user.lastname;
        c.email = user.email;
        c.phone = user.phone;
        c.mobilephone = user.mobilephone;
        c.fax = user.fax;
        c.mailingstreet = user.street;
        c.mailingcity = user.city;
        c.mailingstate = user.state;
        c.mailingpostalcode = user.postalcode;
        c.mailingcountry = user.country;
    }

    static testMethod void testSave() {         
        // Modify the test to query for a portal user that exists in your org
        User existingPortalUser = [SELECT id, profileId, userRoleId FROM User WHERE UserRoleId <> null AND UserType='CustomerSuccess' LIMIT 1];
        System.assert(existingPortalUser != null, 'This test depends on an existing test portal user to run');
        
        String randFax = Math.rint(Math.random() * 1000) + '5551234';
        
        System.runAs(existingPortalUser) {
            MyProfilePageController controller = new MyProfilePageController();
            System.assertEquals(existingPortalUser.Id, controller.getUser().Id, 'Did not successfully load the current user');
            System.assert(controller.isEdit == false, 'isEdit should default to false');
            controller.edit();
            System.assert(controller.isEdit == true);
            
            controller.cancel();
            System.assert(controller.isEdit == false);
            
            controller.getUser().Fax = randFax;
            controller.save();
            System.assert(controller.isEdit == false);
        }
        
        // verify that the user and contact were updated
        existingPortalUser = [Select id, fax, Contact.Fax from User where id =: existingPortalUser.Id];
        System.assert(existingPortalUser.fax == randFax);
        //System.assert(existingPortalUser.Contact.fax == randFax);
    }
}

 

 

The line highlighted in red is the error line.

 

Please help me.

 

I get the following errors when tring to deploy my first website from sandbox to production

MyProfilePageController.testSave()Class7835Failure Message: "System.QueryException: List has no rows for assignment to SObject", Failure Stack Trace: "Class.MyProfilePageController.testSave: line 78, column 35 External entry point"
Deploy Error


Average test coverage across all Apex Classes and Triggers is 46%, at least 75% test coverage is required

 

 

However, MyProfilePageController is not my code and is not included in the change set anyway!  So what on earth is this all about?

    

 

 

 

    

I'm trying to Upload the trigger below into our production environment and receiving the errors below. Test Coverage for the trigger is 85%. Not sure why I would get the errors below:

 

 

 

trigger ExpenseReportUpdate on Expense__c (before insert) {

Expense__c exp = Trigger.new[0];

date trx_d = exp.date__c;
Integer trx_m = trx_d.month();
Integer trx_y = trx_d.year();
String exname = exp.Employee_First_Name__c + ' ' + exp.Employee_Last_Name__c;
String exname_id;
String expR_id;
date trx_st = trx_d.toStartOfMonth();
date stdate = trx_st.addmonths(1);

    try {
        exname_id = [SELECT id
                    FROM User
                    WHERE name = :exname].id;
        }
        
    catch (QueryException e) {
        exname_id = [SELECT id
                    FROM User
                    WHERE name = 'Force Admin'].id;
        }
          
    try { 
    
        expR_id = [SELECT id
            FROM Expense_Report__c
            WHERE CALENDAR_MONTH(Statement_Date__c) = :trx_m
            AND CALENDAR_YEAR(Statement_Date__c)= :trx_y
            AND Employee__c = :exname_id].id; 
            
        exp.Expense_Report__c = expR_id;
       
        }
                    
    catch (QueryException e) {
            Expense_Report__c newER = new Expense_Report__c(Employee__c = exname_id, Statement_Date__c = stdate);
            insert newER;
            
            exp.Expense_Report__c = newER.id;       
    }
    
}

 

 

ERRORS I GET:

MyProfilePageController.testSave()            Failure Message: "System.QueryException: List has no rows for assignment to SObject", Failure Stack Trace: "Class.MyProfilePageController.testSave: line 78, column 35 External entry point"

"not even referencing this?"

ExpenseReportUpdateTest  Coverage of selected Apex Trigger is 0%, at least 1% test coverage is required

"coverage is 89%?"

Deploy Error Average test coverage across all Apex Classes and Triggers is 66%, at least 75% test coverage is required

"not sure why this is happening"

It seems like something obvious but it took me hours to find a way to set a DateTime field to the time when a record is created.   I am building a simple Change Managment system as my first real project in Salesforce. As the administrator I want a method for my users to request changes and log defects and I need to let them know when changes are deployed.

So I created a single custom object with a "Date Opened" field.

 

When the record is created I want this field to get the current time and then never to change again.

 

Solution (partial) create a trigger and use this code. Replace Change_Request__c with the name of your object.  Replace the Date_Opened__c field name too.

 

This trigger only fires when the record is inserted, or created.

 

Triggers operate in batch so it may process a set of records. That is why the assignment is in a for loop.

 

System.now() returns the local date time.

 

This is only a partial solution because the page layout of my custom object is not read only. Users can edit the date!.  I have set the field level permission to read-only but that didn't help. When, and if, I figure this out then I'll post back.

 

 

trigger SetOpenDate on Change_Request__c (before insert) {
    for (Change_Request__c chg : Trigger.new) {
        // Iterate over each sObject  
        chg.Date_Opened__c = System.now();
    }
}

With Winter '11, if you create a Site, a new Salesforce-provided class gets deployed to your org: MyProfilePageController.cls

 

There is test code in this class that fails if you don't have a portal user installed. This prevents you from doing anything in that org that requires running all tests.

 

Here is the error:

 

System.QueryException: List has no rows for assignment to SObject

Class.MyProfilePageController.testSave: line 78, column 35 External entry point

 

and the line in question:

 

 

User existingPortalUser = [SELECT id, profileId, userRoleId FROM User WHERE UserRoleId <> null AND UserType='CustomerSuccess' LIMIT 1];

 

This failure prevents doing any save from Eclipse. You can't deploy new code, edit object metadata files, etc. Complete showstopper.

 

Can anyone:

 * confirm this (we think reproducing will require that you create a new Site, perhaps the first Site in the org, after Winter 11)

 * think of a work-around (tried enabling self-service portal, but it doesn't create the required user type)

 

Anyone from Salesforce confirm that this is a bug and not something we're doing wrong?

 

Thanks!

 

Here is the entire class:

 

/**
 * An apex class that keeps updates of a portal user in sync with its corresponding contact.
   Guest users are never able to access this page.
 */
public class MyProfilePageController {

    private User user;
    private boolean isEdit = false;
    
    public User getUser() {
        return user;
    }

    public MyProfilePageController() {
        user = [SELECT id, email, username, usertype, communitynickname, timezonesidkey, languagelocalekey, firstname, lastname, phone, title,
                street, city, country, postalcode, state, localesidkey, mobilephone, extension, fax, contact.email
                FROM User
                WHERE id = :UserInfo.getUserId()];
        // guest users should never be able to access this page
        if (user.usertype == 'GUEST') {
            throw new NoAccessException();
        }
    }
    
    public Boolean getIsEdit() {
        return isEdit;
    }
    
    public void edit() {
        isEdit=true;
    }    
    
    public void save() {
        if (user.contact != null) {              
            setContactFields(user.contact);
        }
        
        try {
            update user;
            if (user.contact != null) { 
                update user.contact;
            }
            isEdit=false;
        } catch(DmlException e) {
            ApexPages.addMessages(e);
        }
    }
    
    public PageReference changePassword() {
        return Page.ChangePassword;
    }
    
    public void cancel() {
        isEdit=false;
        user = [SELECT id, email, username, communitynickname, timezonesidkey, languagelocalekey, firstname, lastname, phone, title,
                street, city, country, postalcode, state, localesidkey, mobilephone, extension, fax, contact.email
                FROM User
                WHERE id = :UserInfo.getUserId()];
    }
    
    private void setContactFields(Contact c) {
        c.title = user.title;
        c.firstname = user.firstname;
        c.lastname = user.lastname;
        c.email = user.email;
        c.phone = user.phone;
        c.mobilephone = user.mobilephone;
        c.fax = user.fax;
        c.mailingstreet = user.street;
        c.mailingcity = user.city;
        c.mailingstate = user.state;
        c.mailingpostalcode = user.postalcode;
        c.mailingcountry = user.country;
    }

    static testMethod void testSave() {         
        // Modify the test to query for a portal user that exists in your org
        User existingPortalUser = [SELECT id, profileId, userRoleId FROM User WHERE UserRoleId <> null AND UserType='CustomerSuccess' LIMIT 1];
        System.assert(existingPortalUser != null, 'This test depends on an existing test portal user to run');
        
        String randFax = Math.rint(Math.random() * 1000) + '5551234';
        
        System.runAs(existingPortalUser) {
            MyProfilePageController controller = new MyProfilePageController();
            System.assertEquals(existingPortalUser.Id, controller.getUser().Id, 'Did not successfully load the current user');
            System.assert(controller.isEdit == false, 'isEdit should default to false');
            controller.edit();
            System.assert(controller.isEdit == true);
            
            controller.cancel();
            System.assert(controller.isEdit == false);
            
            controller.getUser().Fax = randFax;
            controller.save();
            System.assert(controller.isEdit == false);
        }
        
        // verify that the user and contact were updated
        existingPortalUser = [Select id, fax, Contact.Fax from User where id =: existingPortalUser.Id];
        System.assert(existingPortalUser.fax == randFax);
        System.assert(existingPortalUser.Contact.fax == randFax);
    }

}

 

 

 

  • October 15, 2010
  • Like
  • 0

Currently, I have the default Case pages overridden. I have users that fall into a few different categories that all need to be able to create or manage cases.

 

1. Internal users in role abc.

2. Internal users in role xyz.

3. 3rd party contractors. 

4. Customer Portal users. 

 

And the list keeps growing, and growing.

 

Currently, the way I deal with this is to use one page as the overriding page, and within the page have code like this:

 

<apex:include pageName="pageNameabc" rendered="{!$user.ProfileId == 'abc123'}">

 

<apex:include pageName="pageNamexyz" rendered="{!$user.ProfileId == 'xyz123'}">

 I am not a fan of this implementation. Hard coding Id's is not ideal, but I've not found a better way to achieve what I need.

 
Message Edited by ehartye on 11-24-2009 08:49 AM

Hello,

 

I have a custom VF page and controller. The controller is declared as 

 

 

public with sharing class MyCustomController {

The user accessing this page is a Partner user and does not have "Edit" Permissions on Leads but is still able to assign leads to other users.

 

I also tried assigning leads to a user who does not have "Read" permission on leads and that also surprising worked.

 

As per my understanding if I declare the class with the "with sharing" keyword, it should take into account the user permission.

 

Can someone explain why the "with sharing" is not having any effect.

 

Thanks,

Rohit

 

 

Hi All,
 
 
We are currently facing an issue regarding SMS integration. 
 
We need to send the SMS automatically when a case is saved/edited. For this we have an apex class which consists  of  HTTPS callouts to access the SMS gateway of Value first 
and a trigger which invokes this apex class when ever a case is saved/edited.
 
Now, when ever the trigger is fired i'm getting this exception     "System.CalloutException: Callout from triggers are currently not supported"
 
I think it can be possible by S-Control  but the process should automatic.  
 
And this is very urgent for our project 
 
Pls suggest any solution /workaround  for the same.
 

 
Any help is appreciable.
 
 
Thanks  
Jagan.
  • January 28, 2009
  • Like
  • 0
Hi everyone.  

   Is there a Apex class method to get current Salesforce.com instance or URL at runtime?

I want to generate hyperlinks like https://na4.salesforce.com/{accountId} in code.  But I don't want to hard code 'na4'.

Every time I deploy the same code back to Sandbox, I must fix the instance manually.

Thanks in advance.


  • August 04, 2008
  • Like
  • 0
I am trying to made tabbedCases (like the example tabbedAccounts).  Here is the code:

Code:
<apex:page standardController="Case" showHeader="true" tabStyle="case" >
    <style> 
    .activeTab {background-color: #B7A752; color:white; background-image:none} 
    .inactiveTab { background-color: lightgrey; color:black; background-image:none} 
    </style>
   <apex:tabPanel switchType="client" selectedTab="name2" id="theTabPanel"  tabClass="activeTab" inactiveTabClass="inactiveTab">
      <apex:tab label="Detail" name="CaseDetails" id="tabdetails">
         <apex:detail relatedList="true" title="true"/>
      </apex:tab>
      <apex:tab label="Open Activities" name="OpenActivities" id="tabOpenAct">
         <apex:relatedList subject="{!case}" list="OpenActivities" />
      </apex:tab>
         <apex:tab label="Activity History" name="ActivityHistory" id="tabActHis">
      <apex:relatedList subject="{!case}" list="ActivityHistories" />
      </apex:tab>
         <apex:tab label="Case Comments" name="CaseComments" id="tabCaseComments">
      <apex:relatedList subject="{!case}" list="CaseComments" />
      </apex:tab>
   </apex:tabPanel>
</apex:page>

 
I get the error: 'CaseComments' is not a valid child relationship name for entity Case.  This looks to be the correct name according to the WSDL.

Any thoughts?


Message Edited by billgreenhaw on 07-14-2008 02:18 PM
I'm having an issue with Spring '07 Lightning Application Events. It seems that handlers of an application event are being notified multiple times for a single firing of the event. This can be replicated on various browsers. 

How to reproduce the error:
1) Create the below components and put them in a new lightning page for an object of your choice. 
2) Assign that page to a profile, app or org
3) Navigate to that object's list view and then drill down to the newly created page
4) Press the button. The console should show this:
Test2 receiving event
Test1 receiving event

5) Navigate back to the list view and drill down on another record
6) Press the button. The console should show this:
Test2 receiving event
Test1 receiving event
Test2 receiving event
Test1 receiving event

7) If you repeat steps 5 and 6, you will get an additional two lines in the console for each time you repeat the process. I.e., one firing of the event is causing the handlers to be notified multiple times. 

Incidentally, I don't have this problem in the community edition. It's only in the base lightning experience version that it crops up. Can anyone replicate this? Thanks. 

Component #1
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<aura:handler event="c:pvStateControlEvt" action="{!c.receiveEvent}"  phase="default" />
    <aura:registerEvent name="stateControlEvent" type="c:pvStateControlEvt"/>

I send and receive events
            <lightning:button label="sendEvent" aura:id="testButton" onclick="{!c.fireEvent}"/>

</aura:component>

Component #1 controller
({
fireEvent : function(component, event, helper) {
       var theEvent = $A.get("e.c:pvStateControlEvt");
        theEvent.fire();

},
receiveEvent : function(component, event, helper) {
        console.log("Test1 receiving event");
    }
})


Component #2
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<aura:handler event="c:pvStateControlEvt" action="{!c.receiveEvent}"  phase="default" />
    I receive events
</aura:component>

Component #2 controller
({
receiveEvent : function(component, event, helper) {
        console.log("Test2 receiving event");
    }
})

Event pvStateControlEvt
 
<aura:event type="APPLICATION" description="My event" >
        <aura:attribute name="myAttribute" type="String"/>
</aura:event>