• Dekor
  • NEWBIE
  • 45 Points
  • Member since 2011
  • Service Desk Manager

  • Chatter
    Feed
  • 1
    Best Answers
  • 3
    Likes Received
  • 0
    Likes Given
  • 16
    Questions
  • 27
    Replies
As someone who often has to import new assets into our system via the DataLoader tool I've decided I'll try and automate the process a bit as the GUI is long winded for importing multiple files a day.

So I've been reading the documentation and I've created my config files/batch file.  Finally got it working but there is a couple of limitations I'm hoping to work around.

Here is my process-conf.xml file
 
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
    <bean id="AssetUpsertProcess"
          class="com.salesforce.dataloader.process.ProcessRunner"
          singleton="false">
        <description>Asset Upsert job gets the inventory asset record updates from a CSV file and uploads them to salesforce using 'upsert'.</description>
        <property name="name" value="AssetUpsertProcess"/>
        <property name="configOverrideMap">
            <map>
                <entry key="sfdc.endpoint" value="https://login.salesforce.com"/> 
                <entry key="sfdc.username" value=""/>
                <entry key="sfdc.password" value=""/>
                <entry key="sfdc.timeoutSecs" value="600"/>
                <entry key="sfdc.loadBatchSize" value="200"/>
                <entry key="sfdc.externalIdField" value="Oracle_Id__c"/>
                <entry key="sfdc.entity" value="Asset"/>
                <entry key="process.operation" value="upsert"/>
                <entry key="process.mappingFile" value="C:\Salesforce Imports\Mapping\1.3.sdl"/>
                <entry key="dataAccess.name" value="C:\Salesforce Imports\Inventory Imports\Ready to import\import.csv"/>
                <entry key="dataAccess.type" value="csvRead"/>
                <entry key="process.initialLastRunDate" value="2006-12-01T00:00:00.000-0800"/>
                <entry key="process.outputError" value="C:\Salesforce Imports\errors\error.csv"/>
                <entry key="process.outputSuccess" value="C:\Salesforce Imports\errors\success.csv"/>
		<entry key="process.useEuropeanDates" value="true"/>
            </map>
        </property>
    </bean>
</beans>

My queries relate to three settings, dataAccess.name, process.outputError and process.outputSuccess.

Now for the dataAccess.name file you have to specify a file name.  Is there a way you can specify a folder name and it imports all .csv files in the folder?  This would enable me to import multiple files at once rather than having to save each file in the specified folder with the same file name after each run.

In regards to the output error/success, I'd like it to timestamp the results files rather than constantly overwriting the current file.  The GUI does this so I assume there is a way to do it via command line.  I like to keep an audit of all imports and having these log files is crucial to that. 
 
  • October 27, 2016
  • Like
  • 0
Hello,

We've hit an issue where our support agents are forgetting to tick the "Public" option on case comments when they can be viewed by our customers in the portal. 

I'm looking into a way around this, we don't want to automatically mark all comments as public and rely on the support staff to untick it when it is a private comment.

So I'm thinking the best way would be a new VF page for adding case comments, which has a custom javascript "Accept" button that prompts the user on whether it should be public or private.  If public is selected it creates the comment and marks it as public or if private is selected create the comment with public set to false.

My questions are:

1.  What javascript code would be required on the custom accept button to perform this?
2.  Can I hijack the "new case comment" from the related list on the case layout page to direct to the custom VF page or will I need to create a custom related list that points at case comments to enable me to place my own "new case comment" button?

Cheers in advance!
  • July 26, 2016
  • Like
  • 0
Ok, been directed here by support so hoping someone can help.

Basically noticed that our case milestones were violating outside our set business hours.  After a lot of head scratching the only conclusion was that our timezone on the business hours in use by the entitlement processes were set to GMT.  I have changed this to BST (British Summer Time) to prevent more out of hours violations.

I have asked support if having it set to BST would mean that come Autumn salesforce will automatically revert back an hour in line with daylight savings.  They have said this does not occur and you have to manually change the timezone each time daylight savings occurs.

Can anyone confirm if this is true?  Seems like something so basic that I can't believe its not in the system. 
  • April 21, 2016
  • Like
  • 3
At present when I want to view all open cases against an account in salesforce I go to the account in question, then from the cases related list I click "view all" then order by status column.  This is a bit cumbersome and I'm hoping I can develop something to simplify this.  I was thinking of creating a custom button on the account detail page called "Open cases" that will take me to a list of cases. 

Imagine this would be best done with a visual force page and the button would link to this page/automatically provide the account ID for filtering.  

Has anyone created anything similar to this and have any tips I could look at?  Would I need to create a custom controller for this task?
  • March 16, 2016
  • Like
  • 0
I currently have a couple of triggers in our system that automatically set up an entitlement against accounts.  These triggers fire based on the field "type" against the account.  I'm trying to create a test class for these triggers as they currently have zero code coverage.

Here is the test class I have created but its failing on line 15 with List has no rows for assignment to SObject message:
@isTest
private class CreateEntitlement{
static testMethod void CreateEntitlement(){
	
     // CORRECT - Create the required test data needed for the test scenario.
     // In this case, I need to create an account with type set to customer
     // So I create that Account in my test method itself. 
     Account testAccount = new Account(name='Test Company Name');
     insert testAccount;
	   
     testAccount.type='Customer';
     update testAccount;

     // Verify that the entitlment was created in the database.
     Entitlement NewEntitlement = [SELECT AccountId FROM Entitlement WHERE Name = 'testAccount'];
     System.assertEquals(testAccount.ID, NewEntitlement.AccountId);

  
}
}



Here is the Apex Trigger that I'm trying to cover with this test. 
 
trigger CreateEntitlement on Account (after insert,before update) {

Map<Id, Entitlement> mapOfAccountIdToEntitlement = new Map<Id, Entitlement>();

for( Entitlement et : [ Select AccountId From Entitlement Where AccountId in: trigger.new] ) {
mapOfAccountIdToEntitlement.put( et.AccountId , et );
}


List<Entitlement> createentitlement = new List <Entitlement> {};

for (Account acc : trigger.new) {

// then in you code where you have &&(entitlement.accountid != account.id))  check frommap instead like
Boolean alreadyhasEntitlement = mapOfAccountIdToEntitlement.containsKey(acc.Id) ;
if( (acc.type == 'customer') && ( !alreadyhasEntitlement)  ) 
{
createentitlement.add(new Entitlement (
Name = acc.name, /* Give a standard name*/
AccountId = acc.Id, /* Link the Entitlement to the account */
SlaProcessId = '55220000000L9ZOAA0', /* Link it to a defined entitlement process */
StartDate = system.Today(),
Type = 'Phone Support',
BusinessHoursId = '01m200000009dGQAAY'
    
));
}
}
try {
insert createentitlement ;
}
catch (Exception Ex)
{
system.debug(Ex);
}
}

 
  • November 27, 2015
  • Like
  • 0
I have two triggers in our production org that complete case milestones based on case status/isclosed.

The first trigger completes the "closed" milestone when the case.isclosed = true.  This is working correctly.

However my second trigger which completes the "responded" milestone when case.status = "New" or "Assigned" is firing regardless of status. 

Here is the trigger, I'm sure its something simple but I can't spot it. 
 
trigger completeRespondMilestone on Case (after update) {

    // Cannot be a portal user
    if (UserInfo.getUserType() == 'Standard'){
        DateTime completionDate = System.now();
            List updateCases = new List();
            for (Case c : Trigger.new){
                if (((c.Status != 'New')||(c.Status != 'Assigned'))&&((c.SlaStartDate 

 
  • June 23, 2015
  • Like
  • 0
So I uninstalled a package we no longer used earlier today which I assume has brought down our average test coverage.

I'm now trying to deploy an updated version of an existing class and its failing obviously due to low code coverage.  So sort this I have written a test class in our sandbox which runs fine and works with one of the existing classes in my production org.  However if I try to deploy the change set from my sandbox to production it is failing again due to code coverage.

How on earth am I meant to boost the test coverage if I cannot deploy new test classes????
  • June 22, 2015
  • Like
  • 0
So I have created a Apex class called "MilestoneUtils" to use with some triggers I am using for entitlements.  I have also created a test class to ensure code coverage.  I grabbed the test class from the "MilestoneUtils" in the salesforce documentation but separated it into its own class as current salesforce version doesn't allow test class within your main class. 

When I try to run the test it fails with these two errors:

Class testCompleteMilestoneCase
Method Name testCompleteMilestoneCase
Pass/Fail Fail
Error Message System.QueryException: List has no rows for assignment to SObject
Stack Trace Class.testCompleteMilestoneCase.testCompleteMilestoneCase: line 6, column 1


and

Class testCompleteMilestoneCase
Method Name testCompleteMilestoneViaCase
Pass/Fail Fail
Error Message System.QueryException: List has no rows for assignment to SObject
Stack Trace Class.testCompleteMilestoneCase.testCompleteMilestoneViaCase: line 36, column 1


I can't understand why the list would not have any rows as surely the query returns the first record in the entilement/contact table and there is at least one contact/one entitlement in my sandbox. 

Here it the test class itself:
 
@isTest
    private class testCompleteMilestoneCase{
  
  static testMethod void testCompleteMilestoneCase(){
    
    Contact oContact = [select id from Contact limit 1];
    String contactId;
    if (oContact != null)
      contactId = oContact.Id;
    
    Entitlement entl = [select id from Entitlement limit 1];
    String entlId;
    if (entl != null)
      entlId = entl.Id;
    
    List<Case> cases = new List<Case>{};
    if (entlId != null){
      Case c = new Case(Subject = 'Test Case with Entitlement ', EntitlementId = entlId, ContactId = contactId);
      cases.add(c);
    }
    
    // Insert the Account records that cause the trigger to execute.
    if (cases.isEmpty()==false){
      insert cases;
      List<Id> caseIds = new List<Id>();
      for (Case cL : cases){
        caseIds.add(cL.Id);
      }
      milestoneUtils.completeMilestone(caseIds, 'First Response', System.now());
        }
    }
  
    static testMethod void testCompleteMilestoneViaCase(){
      
        // Perform data preparation
        Entitlement entl = [select id from Entitlement limit 1];
        String entlId;
        if (entl != null)
            entlId = entl.Id;
        List<Case> cases = new List<Case>{};
        for(Integer i = 0; i < 1; i++){
            Case c = new Case(Subject = 'Test Case ' + i);
            cases.add(c);
            if (entlId != null){
                c = new Case(Subject = 'Test Case with Entitlement ' + i, EntitlementId = entlId);
                cases.add(c);
            }
        }
        
        // Insert the Account records that cause the trigger to execute.
        insert cases;

        List<CaseComment> ccs = new List<CaseComment>{};
        for(Case c : cases){
            CaseComment cc = new CaseComment(CommentBody='TestPublic', IsPublished=true, ParentId=c.Id);
            ccs.add(cc);
            cc = new CaseComment(CommentBody='TestPrivate', IsPublished=false, ParentId=c.Id);
            ccs.add(cc);
        }
        if (ccs.isEmpty()==false)
            insert ccs;
    
    // Now create emailmessage objects for them.
    
        List<EmailMessage> emails = new List<EmailMessage>();
        for(Case c : cases){
            emails.add(new EmailMessage(parentId = c.id));
        }
        if(emails.isEmpty()==false)
            database.insert(emails);
        
        for(Case c : cases){
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            String[] toAddr = new String[] {'mramsey@salesforce.com'};
            mail.setToAddresses(toAddr);
            mail.setSaveAsActivity(false);
            mail.setTargetObjectId(c.ContactId);
            mail.setWhatId(c.Id);
            mail.setHtmlBody('TestHTMLBody');
            mail.setPlainTextBody('TestTextBody');
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        }
    
    for(Case c : cases){
      c.Status = 'Closed';
    }
    update cases;
    
        // Query the database for the newly inserted records.
        List<Case> insertedCases = [SELECT Subject,
                                           Description,
                                          (SELECT IsPublished, CommentBody From CaseComments),
                                          (SELECT TextBody, Subject, Incoming From EmailMessages)
                                           FROM Case
                                           WHERE Id IN :cases];
    }
}

Here it the main class:
 
public class milestoneUtils {
    
    public static void completeMilestone(List<Id> caseIds, String milestoneName, DateTime complDate) {
      
    List<CaseMilestone> cmsToUpdate = [select Id, completionDate
                       from CaseMilestone cm
                       where caseId in :caseIds and cm.MilestoneType.Name=:milestoneName and completionDate = null limit 1];
    if (cmsToUpdate.isEmpty() == false){
      for (CaseMilestone cm : cmsToUpdate){
        cm.completionDate = complDate;
      }
      update cmsToUpdate;
    } // end if
  }
  }


 
  • June 15, 2015
  • Like
  • 0
During setting up of entitlements I've created an Apex trigger that automatically assigns an entitlement to new/updated accounts where type = customer.  This is working, however I've discovered that everytime an account is updated, another entitlement is automatically created.

So I need to modify my trigger to first check there isn't an existing entitlement set up.  Below is the trigger and I've added:

(entitlement.accountid != account.id)

However this doesn't seem to do the task.  Any ideas on how I can modify my trigger to not create the entitlement when there is already an existing entitlement in the entitlement table matching the account ID on the account I'm updating. 
 
trigger CreateEntitlement on Account (after insert,before update) {

List<Entitlement> createentitlement = new List <Entitlement> {};

for (Account acc : trigger.new) {

if ((acc.type == 'customer')&&(entitlement.accountid != account.id)) /* If the Account type is set to customer and no entitlement already exists*/

{
createentitlement.add(new Entitlement (
Name = acc.name, /* Give a standard name*/
AccountId = acc.Id, /* Link the Entitlement to the account */
SlaProcessId = '55220000000L9IJAA0', /* Link it to a defined entitlement process */
StartDate = system.Today(),
Type = 'Phone Support',
BusinessHoursId = '01m200000009dGQAAY'
    
));
}
}
try {
insert createentitlement ;
}
catch (Exception Ex)
{
system.debug(Ex);
}
}

 
  • June 15, 2015
  • Like
  • 0
So after discovering that I needed to develop apex classes/triggers to mark my "completed" milestone as complete when a case is closed I've noticed an issue.  Basically if a previously closed case is reopened the "completed" milestone needs to be marked as active again as the SLA is technically live again. 

Can't think of a way to code a trigger to do this.  So basically it needs to clear the completed date/time field when cased close was previously true but now isn't.

Here is my apex class:
 
public class milestoneUtils {
    
    public static void completeMilestone(List<Id> caseIds, String milestoneName, DateTime complDate) {
      
    List<CaseMilestone> cmsToUpdate = [select Id, completionDate
                       from CaseMilestone cm
                       where caseId in :caseIds and cm.MilestoneType.Name=:milestoneName and completionDate = null limit 1];
    if (cmsToUpdate.isEmpty() == false){
      for (CaseMilestone cm : cmsToUpdate){
        cm.completionDate = complDate;
      }
      update cmsToUpdate;
    } // end if
  }
  }

Here is the trigger that marks the "closed" milestone as complete once case closed is true:
 
trigger completeResolutionTimeMilestone on Case (after update) {

    // Cannot be a portal user
    if (UserInfo.getUserType() == 'Standard'){
        DateTime completionDate = System.now();
            List<Id> updateCases = new List<Id>();
            for (Case c : Trigger.new){
                if (((c.isClosed == true))&&((c.SlaStartDate <= completionDate)&&(c.SlaExitDate == null)))
            updateCases.add(c.Id);
        }
    if (updateCases.isEmpty() == false)
        milestoneUtils.completeMilestone(updateCases, 'Closed Milestone', completionDate);
    }
}

Any thoughts on the best way to achieve this?
 
  • June 15, 2015
  • Like
  • 0
We are interested in finding a developer to further advance our existing salesforce community page.  We are interested in adding the ability to do the following:
  • Present salesforce reports/dashboards to certain customers whilst logged into our portal
  • Ability for clients to view assets against their accounts
  • Ability for clients to self manage contacts and their information against their accounts
  • Decision tree based contact support options
  • Chat integration
Please email dean.cachia@uniware.co.uk to discuss further. 
 
  • May 13, 2015
  • Like
  • 0
So I'm trying to deploy an apex class to my production system however it is failing due to code coverage.

I've had a look at the failing tests and can see that "ChatterAnswersAuthProviderRegTest" is failing with the below message.

System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [ProfileId]: [ProfileId]

From what I understand this test class was brought in with the spring release.  Just trying to understand why its not working on my system, any thoughts?

Here is original bug link:

https://success.salesforce.com/issues_view?id=a1p300000008XHfAAM
  • April 10, 2015
  • Like
  • 0
I'm trying to create a field that displays to my operators how much time is remaining before a case escalates.  My plan was to have a field that calculates how many business hours have passed since the date/time the case was created and then subtract this figure from the escalation hours. 

So for example, a priority 1 case in our system has a escalate time if not closed of 0.5 (30 minutes) so subtract from that the time open calculated by my business hours field.

Here is an example of the formula I'm after but the problem is this is designed to calculate between two fields, I want to calculate between a field and the current date/time.  I thought replacing "YourEnd/RecentDateFieldHere" with NOW () would do it but the formula doesn't seem to work.  Any ideas?

 
ROUND( "NumberOfBusinessHoursWithinaDay" *( (5*FLOOR(( DATEVALUE( "YourEnd/RecentDateFieldHere" ) -DATE(1996,01,01))/7) +MIN(5, MOD(DATEVALUE( "YourEnd/RecentDateFieldHere" )-DATE(1996,01,01), 7) +MIN(1, 24/ "NumberOfBusinessHoursWithinaDay" *(MOD( "YourEnd/RecentDateFieldHere" -DATETIMEVALUE('1996-01-01 13:00:00'), 1)))))
-
(5*FLOOR((DATEVALUE( "YourStart/OldDateFieldHere" )-DATE(1996,01,01))/7) +MIN(5, MOD(DATEVALUE( "YourStart/OldDateFieldHere" )-DATE(1996,01,01), 7) +MIN(1, 24/ "NumberOfBusinessHoursWithinaDay" *(MOD( "YourStart/OldDateFieldHere" -DATETIMEVALUE('1996-01-01 13:00:00'), 1)))))), 0) / "NumberOfBusinessHoursWithinaDay"


 
  • April 09, 2015
  • Like
  • 0

Good Morning,

 

I have been using dataloader for quite some time now to update our salesforce system with new assets each time we perform a new install.  Since the spring update a problem seems to have been introduced in regards to the dataloader and updating lookup/reference fields.

 

We custom field as an external ID called "Asset tag" which is unique for every asset.  On my assets I have a reference field called "parent asset" which contains an asset tag for the asset that this asset is fitted to.  Up until recently I had a column in my template for importing for "parent asset" and I could just enter the external ID value into this and it worked fine.

 

However now when I try to import and specify a valid "Asset Tag" in this parent ID field I get this error:

 

Parent ID: id value of incorrect type:

 

Has anyone else seen this and been able to find a work around?  I don't want to have to specify the salesforce ID for asset as this will involve a lot more extra work, hence the use of external ID in the first place.

 

Kind Regards

 

Dean

  • February 20, 2012
  • Like
  • 0

Hello,

 

I have created a trigger that runs a class to update the account on an asset when an inactive tick box is ticked.

 

Here is my class:

 

public with sharing class Inactive_asset_class {

   public static void Inactive_asset(Asset[] cont){

      ASSET a = [select asset.AccountId FROM ASSET where Inactive__c=true ];
      a.Accountid = '0012000000oX453';
      update a.account;
   }
}

 

Here is my trigger:

 

trigger inactive_asset on Asset (after update){
    Inactive_asset_class.Inactive_asset(Trigger.new);

}

 

Here is my test:

@isTest
private class InactiveTriggerTest {

    static testMethod void myUnitTest() {
       
       //create a test asset
       
       Asset test_asset = new Asset(id='02i2000000KU6mR',accountid='0012000000foauZ',name='0012000000foauZ',Asset_Tag__c = '18668',Inactive__c=false);
       
       test_asset.Inactive__c=true;
       UPDATE (test_asset);
       

  
      }
}

 

 

Unfortunately the trigger is failing to deploy with this failure, any ideas?  I just can't suss this out!

 

Run Failures:
  InactiveTriggerTest.myUnitTest System.DmlException: Update failed. First exception on row 0 with id 02i2000000KU6mRAAT; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, inactive_asset: execution of AfterUpdate

caused by: System.NullPointerException: Attempt to de-reference a null object

Class.Inactive_asset_class.Inactive_asset: line 7, column 14
Trigger.inactive_asset: line 2, column 5: []

 

  • November 11, 2011
  • Like
  • 0

I have created this VF page:

 

<apex:page controller="casebyasset" >
  <apex:pageBlock >
        <apex:pageBlockTable value="{!casesbyasset}" var="c">  
        <apex:column value="{!c.AssetId}"/>
        <apex:column value="{!c.asset.product2id}"/>   
         
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>

 

Which is using this Apex class:

 

public with sharing class casebyasset {
    public List<Case> getCasesbyasset() {
        return [SELECT assetid, asset.Product2Id FROM Case
                WHERE assetid !=null and CreatedDate = this_month limit 200];
    }
}

 

 

The issue I am having is that I want to use count function in this class grouped by assetid.  The aim is so that my VF page will display a list of assets, their product name, number of cases logged this month.

 

Have to excuse me as quite new to this and just struggling to get my head round this function.  Appreciate any feedback.

  • May 25, 2011
  • Like
  • 0
Ok, been directed here by support so hoping someone can help.

Basically noticed that our case milestones were violating outside our set business hours.  After a lot of head scratching the only conclusion was that our timezone on the business hours in use by the entitlement processes were set to GMT.  I have changed this to BST (British Summer Time) to prevent more out of hours violations.

I have asked support if having it set to BST would mean that come Autumn salesforce will automatically revert back an hour in line with daylight savings.  They have said this does not occur and you have to manually change the timezone each time daylight savings occurs.

Can anyone confirm if this is true?  Seems like something so basic that I can't believe its not in the system. 
  • April 21, 2016
  • Like
  • 3
As someone who often has to import new assets into our system via the DataLoader tool I've decided I'll try and automate the process a bit as the GUI is long winded for importing multiple files a day.

So I've been reading the documentation and I've created my config files/batch file.  Finally got it working but there is a couple of limitations I'm hoping to work around.

Here is my process-conf.xml file
 
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
    <bean id="AssetUpsertProcess"
          class="com.salesforce.dataloader.process.ProcessRunner"
          singleton="false">
        <description>Asset Upsert job gets the inventory asset record updates from a CSV file and uploads them to salesforce using 'upsert'.</description>
        <property name="name" value="AssetUpsertProcess"/>
        <property name="configOverrideMap">
            <map>
                <entry key="sfdc.endpoint" value="https://login.salesforce.com"/> 
                <entry key="sfdc.username" value=""/>
                <entry key="sfdc.password" value=""/>
                <entry key="sfdc.timeoutSecs" value="600"/>
                <entry key="sfdc.loadBatchSize" value="200"/>
                <entry key="sfdc.externalIdField" value="Oracle_Id__c"/>
                <entry key="sfdc.entity" value="Asset"/>
                <entry key="process.operation" value="upsert"/>
                <entry key="process.mappingFile" value="C:\Salesforce Imports\Mapping\1.3.sdl"/>
                <entry key="dataAccess.name" value="C:\Salesforce Imports\Inventory Imports\Ready to import\import.csv"/>
                <entry key="dataAccess.type" value="csvRead"/>
                <entry key="process.initialLastRunDate" value="2006-12-01T00:00:00.000-0800"/>
                <entry key="process.outputError" value="C:\Salesforce Imports\errors\error.csv"/>
                <entry key="process.outputSuccess" value="C:\Salesforce Imports\errors\success.csv"/>
		<entry key="process.useEuropeanDates" value="true"/>
            </map>
        </property>
    </bean>
</beans>

My queries relate to three settings, dataAccess.name, process.outputError and process.outputSuccess.

Now for the dataAccess.name file you have to specify a file name.  Is there a way you can specify a folder name and it imports all .csv files in the folder?  This would enable me to import multiple files at once rather than having to save each file in the specified folder with the same file name after each run.

In regards to the output error/success, I'd like it to timestamp the results files rather than constantly overwriting the current file.  The GUI does this so I assume there is a way to do it via command line.  I like to keep an audit of all imports and having these log files is crucial to that. 
 
  • October 27, 2016
  • Like
  • 0
At present when I want to view all open cases against an account in salesforce I go to the account in question, then from the cases related list I click "view all" then order by status column.  This is a bit cumbersome and I'm hoping I can develop something to simplify this.  I was thinking of creating a custom button on the account detail page called "Open cases" that will take me to a list of cases. 

Imagine this would be best done with a visual force page and the button would link to this page/automatically provide the account ID for filtering.  

Has anyone created anything similar to this and have any tips I could look at?  Would I need to create a custom controller for this task?
  • March 16, 2016
  • Like
  • 0
I have two triggers in our production org that complete case milestones based on case status/isclosed.

The first trigger completes the "closed" milestone when the case.isclosed = true.  This is working correctly.

However my second trigger which completes the "responded" milestone when case.status = "New" or "Assigned" is firing regardless of status. 

Here is the trigger, I'm sure its something simple but I can't spot it. 
 
trigger completeRespondMilestone on Case (after update) {

    // Cannot be a portal user
    if (UserInfo.getUserType() == 'Standard'){
        DateTime completionDate = System.now();
            List updateCases = new List();
            for (Case c : Trigger.new){
                if (((c.Status != 'New')||(c.Status != 'Assigned'))&&((c.SlaStartDate 

 
  • June 23, 2015
  • Like
  • 0
So I uninstalled a package we no longer used earlier today which I assume has brought down our average test coverage.

I'm now trying to deploy an updated version of an existing class and its failing obviously due to low code coverage.  So sort this I have written a test class in our sandbox which runs fine and works with one of the existing classes in my production org.  However if I try to deploy the change set from my sandbox to production it is failing again due to code coverage.

How on earth am I meant to boost the test coverage if I cannot deploy new test classes????
  • June 22, 2015
  • Like
  • 0
So I have created a Apex class called "MilestoneUtils" to use with some triggers I am using for entitlements.  I have also created a test class to ensure code coverage.  I grabbed the test class from the "MilestoneUtils" in the salesforce documentation but separated it into its own class as current salesforce version doesn't allow test class within your main class. 

When I try to run the test it fails with these two errors:

Class testCompleteMilestoneCase
Method Name testCompleteMilestoneCase
Pass/Fail Fail
Error Message System.QueryException: List has no rows for assignment to SObject
Stack Trace Class.testCompleteMilestoneCase.testCompleteMilestoneCase: line 6, column 1


and

Class testCompleteMilestoneCase
Method Name testCompleteMilestoneViaCase
Pass/Fail Fail
Error Message System.QueryException: List has no rows for assignment to SObject
Stack Trace Class.testCompleteMilestoneCase.testCompleteMilestoneViaCase: line 36, column 1


I can't understand why the list would not have any rows as surely the query returns the first record in the entilement/contact table and there is at least one contact/one entitlement in my sandbox. 

Here it the test class itself:
 
@isTest
    private class testCompleteMilestoneCase{
  
  static testMethod void testCompleteMilestoneCase(){
    
    Contact oContact = [select id from Contact limit 1];
    String contactId;
    if (oContact != null)
      contactId = oContact.Id;
    
    Entitlement entl = [select id from Entitlement limit 1];
    String entlId;
    if (entl != null)
      entlId = entl.Id;
    
    List<Case> cases = new List<Case>{};
    if (entlId != null){
      Case c = new Case(Subject = 'Test Case with Entitlement ', EntitlementId = entlId, ContactId = contactId);
      cases.add(c);
    }
    
    // Insert the Account records that cause the trigger to execute.
    if (cases.isEmpty()==false){
      insert cases;
      List<Id> caseIds = new List<Id>();
      for (Case cL : cases){
        caseIds.add(cL.Id);
      }
      milestoneUtils.completeMilestone(caseIds, 'First Response', System.now());
        }
    }
  
    static testMethod void testCompleteMilestoneViaCase(){
      
        // Perform data preparation
        Entitlement entl = [select id from Entitlement limit 1];
        String entlId;
        if (entl != null)
            entlId = entl.Id;
        List<Case> cases = new List<Case>{};
        for(Integer i = 0; i < 1; i++){
            Case c = new Case(Subject = 'Test Case ' + i);
            cases.add(c);
            if (entlId != null){
                c = new Case(Subject = 'Test Case with Entitlement ' + i, EntitlementId = entlId);
                cases.add(c);
            }
        }
        
        // Insert the Account records that cause the trigger to execute.
        insert cases;

        List<CaseComment> ccs = new List<CaseComment>{};
        for(Case c : cases){
            CaseComment cc = new CaseComment(CommentBody='TestPublic', IsPublished=true, ParentId=c.Id);
            ccs.add(cc);
            cc = new CaseComment(CommentBody='TestPrivate', IsPublished=false, ParentId=c.Id);
            ccs.add(cc);
        }
        if (ccs.isEmpty()==false)
            insert ccs;
    
    // Now create emailmessage objects for them.
    
        List<EmailMessage> emails = new List<EmailMessage>();
        for(Case c : cases){
            emails.add(new EmailMessage(parentId = c.id));
        }
        if(emails.isEmpty()==false)
            database.insert(emails);
        
        for(Case c : cases){
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            String[] toAddr = new String[] {'mramsey@salesforce.com'};
            mail.setToAddresses(toAddr);
            mail.setSaveAsActivity(false);
            mail.setTargetObjectId(c.ContactId);
            mail.setWhatId(c.Id);
            mail.setHtmlBody('TestHTMLBody');
            mail.setPlainTextBody('TestTextBody');
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        }
    
    for(Case c : cases){
      c.Status = 'Closed';
    }
    update cases;
    
        // Query the database for the newly inserted records.
        List<Case> insertedCases = [SELECT Subject,
                                           Description,
                                          (SELECT IsPublished, CommentBody From CaseComments),
                                          (SELECT TextBody, Subject, Incoming From EmailMessages)
                                           FROM Case
                                           WHERE Id IN :cases];
    }
}

Here it the main class:
 
public class milestoneUtils {
    
    public static void completeMilestone(List<Id> caseIds, String milestoneName, DateTime complDate) {
      
    List<CaseMilestone> cmsToUpdate = [select Id, completionDate
                       from CaseMilestone cm
                       where caseId in :caseIds and cm.MilestoneType.Name=:milestoneName and completionDate = null limit 1];
    if (cmsToUpdate.isEmpty() == false){
      for (CaseMilestone cm : cmsToUpdate){
        cm.completionDate = complDate;
      }
      update cmsToUpdate;
    } // end if
  }
  }


 
  • June 15, 2015
  • Like
  • 0
During setting up of entitlements I've created an Apex trigger that automatically assigns an entitlement to new/updated accounts where type = customer.  This is working, however I've discovered that everytime an account is updated, another entitlement is automatically created.

So I need to modify my trigger to first check there isn't an existing entitlement set up.  Below is the trigger and I've added:

(entitlement.accountid != account.id)

However this doesn't seem to do the task.  Any ideas on how I can modify my trigger to not create the entitlement when there is already an existing entitlement in the entitlement table matching the account ID on the account I'm updating. 
 
trigger CreateEntitlement on Account (after insert,before update) {

List<Entitlement> createentitlement = new List <Entitlement> {};

for (Account acc : trigger.new) {

if ((acc.type == 'customer')&&(entitlement.accountid != account.id)) /* If the Account type is set to customer and no entitlement already exists*/

{
createentitlement.add(new Entitlement (
Name = acc.name, /* Give a standard name*/
AccountId = acc.Id, /* Link the Entitlement to the account */
SlaProcessId = '55220000000L9IJAA0', /* Link it to a defined entitlement process */
StartDate = system.Today(),
Type = 'Phone Support',
BusinessHoursId = '01m200000009dGQAAY'
    
));
}
}
try {
insert createentitlement ;
}
catch (Exception Ex)
{
system.debug(Ex);
}
}

 
  • June 15, 2015
  • Like
  • 0
So after discovering that I needed to develop apex classes/triggers to mark my "completed" milestone as complete when a case is closed I've noticed an issue.  Basically if a previously closed case is reopened the "completed" milestone needs to be marked as active again as the SLA is technically live again. 

Can't think of a way to code a trigger to do this.  So basically it needs to clear the completed date/time field when cased close was previously true but now isn't.

Here is my apex class:
 
public class milestoneUtils {
    
    public static void completeMilestone(List<Id> caseIds, String milestoneName, DateTime complDate) {
      
    List<CaseMilestone> cmsToUpdate = [select Id, completionDate
                       from CaseMilestone cm
                       where caseId in :caseIds and cm.MilestoneType.Name=:milestoneName and completionDate = null limit 1];
    if (cmsToUpdate.isEmpty() == false){
      for (CaseMilestone cm : cmsToUpdate){
        cm.completionDate = complDate;
      }
      update cmsToUpdate;
    } // end if
  }
  }

Here is the trigger that marks the "closed" milestone as complete once case closed is true:
 
trigger completeResolutionTimeMilestone on Case (after update) {

    // Cannot be a portal user
    if (UserInfo.getUserType() == 'Standard'){
        DateTime completionDate = System.now();
            List<Id> updateCases = new List<Id>();
            for (Case c : Trigger.new){
                if (((c.isClosed == true))&&((c.SlaStartDate <= completionDate)&&(c.SlaExitDate == null)))
            updateCases.add(c.Id);
        }
    if (updateCases.isEmpty() == false)
        milestoneUtils.completeMilestone(updateCases, 'Closed Milestone', completionDate);
    }
}

Any thoughts on the best way to achieve this?
 
  • June 15, 2015
  • Like
  • 0
So I'm trying to deploy an apex class to my production system however it is failing due to code coverage.

I've had a look at the failing tests and can see that "ChatterAnswersAuthProviderRegTest" is failing with the below message.

System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [ProfileId]: [ProfileId]

From what I understand this test class was brought in with the spring release.  Just trying to understand why its not working on my system, any thoughts?

Here is original bug link:

https://success.salesforce.com/issues_view?id=a1p300000008XHfAAM
  • April 10, 2015
  • Like
  • 0
I'm trying to create a field that displays to my operators how much time is remaining before a case escalates.  My plan was to have a field that calculates how many business hours have passed since the date/time the case was created and then subtract this figure from the escalation hours. 

So for example, a priority 1 case in our system has a escalate time if not closed of 0.5 (30 minutes) so subtract from that the time open calculated by my business hours field.

Here is an example of the formula I'm after but the problem is this is designed to calculate between two fields, I want to calculate between a field and the current date/time.  I thought replacing "YourEnd/RecentDateFieldHere" with NOW () would do it but the formula doesn't seem to work.  Any ideas?

 
ROUND( "NumberOfBusinessHoursWithinaDay" *( (5*FLOOR(( DATEVALUE( "YourEnd/RecentDateFieldHere" ) -DATE(1996,01,01))/7) +MIN(5, MOD(DATEVALUE( "YourEnd/RecentDateFieldHere" )-DATE(1996,01,01), 7) +MIN(1, 24/ "NumberOfBusinessHoursWithinaDay" *(MOD( "YourEnd/RecentDateFieldHere" -DATETIMEVALUE('1996-01-01 13:00:00'), 1)))))
-
(5*FLOOR((DATEVALUE( "YourStart/OldDateFieldHere" )-DATE(1996,01,01))/7) +MIN(5, MOD(DATEVALUE( "YourStart/OldDateFieldHere" )-DATE(1996,01,01), 7) +MIN(1, 24/ "NumberOfBusinessHoursWithinaDay" *(MOD( "YourStart/OldDateFieldHere" -DATETIMEVALUE('1996-01-01 13:00:00'), 1)))))), 0) / "NumberOfBusinessHoursWithinaDay"


 
  • April 09, 2015
  • Like
  • 0

Good Morning,

 

I have been using dataloader for quite some time now to update our salesforce system with new assets each time we perform a new install.  Since the spring update a problem seems to have been introduced in regards to the dataloader and updating lookup/reference fields.

 

We custom field as an external ID called "Asset tag" which is unique for every asset.  On my assets I have a reference field called "parent asset" which contains an asset tag for the asset that this asset is fitted to.  Up until recently I had a column in my template for importing for "parent asset" and I could just enter the external ID value into this and it worked fine.

 

However now when I try to import and specify a valid "Asset Tag" in this parent ID field I get this error:

 

Parent ID: id value of incorrect type:

 

Has anyone else seen this and been able to find a work around?  I don't want to have to specify the salesforce ID for asset as this will involve a lot more extra work, hence the use of external ID in the first place.

 

Kind Regards

 

Dean

  • February 20, 2012
  • Like
  • 0

I have two objects  'Building ' and 'Lease' .Lease is a child of building

 

 

I have an excel sheet with all information regrad to building and lease.

 

 

What i did is I inserted the information pertaining to 'Building' which is the Master object.All the records were inserted successfully ,Happy tilll here

 

Next when I tried to insert records for the child object 'Lease'    .I got error for all inserted records.

 

The error is like this 'Building: id value of incorrect type: XZ006'

 

 

Can anybody help me out of this cave