• Ossie
  • NEWBIE
  • 135 Points
  • Member since 2011

  • Chatter
    Feed
  • 3
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 57
    Questions
  • 86
    Replies
Hi All,

I need help please with my Test Class.
I have 60% code coverage. See below. Any help would be great. Thanks! 
 
trigger ManageUserCase on Case (before update){
    set<String> usrIds = new set<String>();    
    
    for(Case cs :Trigger.New){
        if(Trigger.isInsert || (Trigger.isUpdate && (cs.OwnerId != Trigger.OldMap.get(cs.Id).OwnerId))){
            usrIds.add(cs.OwnerId);
        }
    }
      
    if(usrIds.size() > 0){
        map<string,User> userMap = new map<string,user>();        
        for(User u : [select Id, Back_Up__c, Back_Up__r.Name, User_Out__c from User Where Id IN: usrIds 
                      and User_Out__c = true]){
            userMap.put(u.Id,u);
        }        
        
        for(Case cs : Trigger.new){
            if(userMap.containsKey(cs.OwnerId)){
                string otherUsername = userMap.get(cs.OwnerId).Back_Up__r.Name;
                if(otherUsername == null)
                    otherUsername = 'Someone else';
                    cs.addError('Please assign Case to '+otherUsername);
            }
        }
    }
}

Test Class:
 
@isTest

private class TestManageUserCase {

public static testMethod void TestManageUserCase(){

//Insert user
        List<User> Userlist = new List<user>();
        Profile pf = [Select id from Profile where  name = 'System Administrator' LIMIT 1];
        
        for(integer i=0;i<=8;i++)
        {
         user usr = new User();
         usr.firstName = 'test12' + i;
         usr.LastName = 'test22'+ i;
         usr.Alias = '122'+ i;
         usr.Email = 'xy@demo.com' + i;
         usr.UserName='testuser2@testclass.com'+ i;
         usr.ProfileId = pf.id;
         usr.CommunityNickname = usr.firstname+'_'+usr.lastName;
         usr.EmailEncodingKey ='ISO-8859-1';
         usr.LanguageLocaleKey = 'en_US';
         usr.TimeZoneSidKey ='America/New_York';
         usr.LocaleSidKey = 'en_US';
         usr.User_Out__c = False;
         Userlist.add(usr);
        }
        
        insert Userlist;

Case cs = new Case(ownerid = userlist[0].id, status='Open', Back_Up__c=userlist[0].id);
insert cs;

Case cs1 = [select id, ownerid, back_up__c from case where id=: cs.id];
cs1.ownerid=userlist[1].id;

update cs1;

}
}

 
  • May 18, 2015
  • Like
  • 0
Hi All,

Need some help please.

I have created a trigger which should update the OwnerId on Case object using UserId from field Back_Up__c On Case object.

But i cant get this to work.  Yet i get no error messages. Any help would be most appreciated. 

trigger CaseOutofOffice on Case (after update) {

    If (Trigger.isAfter){
        List<Case> Cases = new List<Case>();
            for (Case c : cases) {
                If (c.Status != 'Closed' && (c.Back_Up__c!=null || c.Back_Up__c!='')){
                    c.OwnerId = c.Back_Up__c;
                    c.IsBackUp__c = True;                   
}
    Update c;
}}}
  • May 13, 2015
  • Like
  • 0
Hi,

I have written the following trigger which isn't working. When I change the Case Owner i get error message "Case Owner: owner cannot be blank". 
The Back_Up__c field is a lookup field and so exists in the User Object and so when you a user creates / updates a Case the Back_Up__c field is automatically populated via another Apex class.   

When my trigger is executed it seems that Salesforce has not populated field Back_Up__c and hence the erro rmessage above is displayed.  Is this correct?  How do i get around this? Please help?

trigger CaseAssignmentOutofOffice on Case (before update) {
       
   For (Case c : Trigger.New) {
        Case NewCase = Trigger.newMap.get(c.id);
        Case OldCase = Trigger.oldMap.get(c.id);
        
        If (OldCase.OwnerId != NewCase.OwnerId && c.Status != 'Closed'){
        c.OwnerId = c.Back_Up__c;
        c.IsBackUp__c = True;     
        }
}
}
  • May 13, 2015
  • Like
  • 0
Hi All,

I have written a basic trigger and currently have code coverage of 66%.

Not sure how to cover lines 8 and 9. Could anyone help me please??

trigger CaseAssignmentOutofOffice on Case (before update) {
    
    For (Case c : Trigger.new) {
        Case NewCase = Trigger.newMap.get(c.id);
        Case OldCase = Trigger.oldMap.get(c.id);

        If (OldCase.OwnerId != NewCase.OwnerId && c.Status != 'Closed' && NewCase.Back_Up__c != Null){
        c.OwnerId = NewCase.Back_Up__c;
        c.IsBackUp__c = True;
    }
}
  • May 12, 2015
  • Like
  • 0
Hi,

How can i access large volumes of data without the need to batch upload this info to Salesforce?
For example i want to look up a Marketing Code for an Item we sell and so rather uploadng 1million+ item records with there marketing code in SF.com i would like to search an external source and retrieve the info.  Is this only possible through Web services etc? 
  • March 04, 2015
  • Like
  • 0
Hello,

I would like to store the 'Date' and 'Role' everytime a Case is assigned to a User that belongs in particulaur 'Role'.

For example: We have 2 teams using Case object in Salesforce 1) Customer Services and 2) Shipping

Sometimes Customer Services need help from Shipping Users in order to Close/Resolve a Case.  In this case CS would assign the Case to a Shipping User (sometimes the Shipping Queue) and add a Comment asking for help. Shipping would review the Case, enter any comments and then re-assign the Case back to CS.  I therefore, would like to store the 'Date' of when the Case was assigned to the Shipping User or Shipping Queue and capture/store the 'Role' of the person who assigned the Case to the Shipping User or Queue.  

Is this possible?

Any advise would be very much appreciated.
  • February 10, 2015
  • Like
  • 0
Hello,

Is it possible to create a report, which only shows 5 or more Open Cases for a Customer?  Not sure how to apply this criteria of 5 or more. 

Any help would be greatly appreciated.
 
  • November 10, 2014
  • Like
  • 0
Hi,

Is it possible to prevent users from editing a record based on a specfic value in a field?  
For example users should not be able to edit a opportunity record if Stage equals 'Won OR Lost'?

Would appreciate any help!!
  • September 03, 2014
  • Like
  • 1
Hi,

I would like one of my Case Worklows to only trigger during Business Days.  Currently users are receving email alerts on a Sunday and Saturday whereas they should only receive alerts Monday to Friday. 
Unable to use the Escalation functioanlty due to limitations. 

Can this be done?

any help would be greatly appreciated.
  • July 08, 2014
  • Like
  • 0
Hi,

I want to restrict what Cases users can assign to other users / queues by implementing some logic such as field abc__c = '123' and field xyz__c <> '456' etc.
I have tried validation rules but for this to work my criteria must equal true and so this is not a viable solution.  I believe i can only achive this through triggers.  Could some please advise?
  • June 13, 2014
  • Like
  • 0
Hi All,

I would like to implement some functionality which Closes all Cases when the status field is changed to a particulaur value in my custom object.  The Cases object is linked to the custom object via a Lookup.     

I would imagine that this can only be achieved through Apex coding (triggers?) and if so not sure how to start?
Would apprciate any help! 
  • April 25, 2014
  • Like
  • 0

Hello,

 

I have a custom button which creates a PDF file and on the pdf file there is a button called "Save".  The "Save" button allows users to save the pdf file in Notes & Attachments and so this works fine.  When i click the "Save" button i would like the previosu page displayed. Is this possible and if so any idea how i can achive this?

 

Many thanks.

  • September 25, 2013
  • Like
  • 0

Hi All,

 

Need help please.  Im not a developer and so struggling with the followng issue: 

 

I have created a custom object which behaves in a similer manner as the "Quote" standard object and so i am able to produce Quotes in PDF by clicking on a custom button called "Create PDF".  However, when I produce the PDF file i would like to incremant the file name by '1' each time.  For example, when the "Create PDF" button is clicked the file name should be Quote_V1.pdf should then become Quote_V2.PDF,  then Quote_V3.PDF etc etc

 

Not sure how to do this.  Please see a part of my apex code below which is where I think i need to make my modification :

     Public PageReference SaveQuote()
    {
        try
        {
            String QId = ApexPages.currentPage().getParameters().get('id');
            dealerQuotation = [SELECT Id,Name FROM Dealer_Quotation__c WHERE Id = :QId]; 
            PageReference pdf = Page.Dealer_Quotation;
            pdf.getParameters().put('id',Qid);
            
            Attachment attach = new Attachment();
            Blob body;
            try
            {
                body = pdf.getContentAsPdf();
            }
            catch(Exception ex)
            {
                body = Blob.ValueOf('Error occured in page');
            }
            string name;
            if(dealerQuotation != null)
            {
                name = dealerQuotation.Name + '.pdf';
            }
            else
            {
                name = 'Quotation.pdf';
            }
            attach.body = body;
            attach.Name = name;
            attach.IsPrivate = false;
            attach.ParentId = QId;
            insert attach; 
            PageReference redirectPage = New PageReference('/' + QId);
            redirectPage.setRedirect(true);
            return redirectPage;    
        }
        catch(Exception ex)
        {
            ApexPages.Message exMsg = new ApexPages.Message(ApexPages.Severity.ERROR, ex.getMessage());
            ApexPages.AddMessage(exMsg);
            return null;
        }    
       
    }

 

Any help would be greatly appreciated!

 

  • September 24, 2013
  • Like
  • 0

Hello,

 

I have created a custom button called "Email Quote" which is on my custom object called Customer Quote.

Currently when I can click on this button the email opens up in a new window which is perfect.  However, what i would like is when I click on this custom button attachments also get added?

 

Is this possible? Please advise?

 

Regards

 

  • September 23, 2013
  • Like
  • 0

Hi All,

 

Need some help please.  I have integrated Google Maps (inline) using Visualforce within the Accounts object and it works perfectly.  However, i would now like to make a small change whereby i would like to fix the zoom level and so is this possible?  If so any ideas on how to do this would be greatly appreciated.

 

Please see my visualforce code below (if it helps).

 

<apex:page standardController="Account">

<head>

<script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">

$(document).ready(function() {

  var myOptions = {
    Zoom: Map.SetZoom(15),
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    mapTypeControl: false
  }

  var map;
  var marker;

  var geocoder = new google.maps.Geocoder();
  var address = "{!Account.Address_Line_1__c}, " + "{!Account.Address_Line_2__c}, " + "{!Account.Address_Line_3__c}, " + "{!Account.City__c}, "+" {!Account.State_County__c}, "+" {!Account.Postal_Code__c} "+" {!Account.Country__c}";

  var infowindow = new google.maps.InfoWindow({
    content: "<b>{!Account.Name}</b><br>{!Account.Address_Line_1__c}<br>{!Account.Address_Line_2__c}, {!Account.Address_Line_3__c}<br>{!Account.City__c}<br>{!Account.State_County__c}<br>{!Account.Postal_Code__c}<br>{!Account.Country__c}"
  });

  geocoder.geocode( { address: address}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK && results.length) {
      if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {

        //create map
        map = new google.maps.Map(document.getElementById("map"), myOptions);

        //center map
        map.setCenter(results[0].geometry.location);

        //create marker
        marker = new google.maps.Marker({
            position: results[0].geometry.location,
            map: map,
            title: "{!Account.Name}"
        });

        //add listeners
        google.maps.event.addListener(marker, 'click', function() {
          infowindow.open(map,marker);
        });
        google.maps.event.addListener(infowindow, 'closeclick', function() {
          map.setCenter(marker.getPosition());
        });

      }

    } else {
      $('#map').css({'height' : '15px'});
      $('#map').html("Oops! {!Account.Name}'s address could not be found, please make sure the address is correct.");
      resizeIframe();
    }
  });

  function resizeIframe() {
    var me = window.name;
    if (me) {
      var iframes = parent.document.getElementsByName(me);
      if (iframes && iframes.length == 1) {
        height = document.body.offsetHeight;
        iframes[0].style.height = height + "px";
      }
    }
  }

});
</script>

<style>
#map {
  font-family: Arial;
  font-size:12px;
  line-height:normal !important;
  height:250px;
  background:transparent;
}
</style>

</head>

<body>
<div id="map"></div>
</body>
</apex:page>

  . 

  • June 12, 2013
  • Like
  • 0

Hi All,

 

I have requirement whereby I would like to automatically change the status of my Case (Case Object) when assigning the Case to a Queue or User.  For example when Customer Services assign a Case to the Pricing Department (queue) then I would like the status of the Case to automatically change to "Waiting for Pricing".

 

And so I would like to know please the best method for achieving this requirement  for example, do i use triggers, workflows etc

 

Any help/advise would be greatly appreciated.

 

Thank You.

  • September 18, 2012
  • Like
  • 0

Hi All,

 

Is it possible to change what fields appear in the Case Object when you Hover over the Account Name field?

 

Regards

  • July 20, 2012
  • Like
  • 0

Hi All,

 

Can someone please help me finish this test class for the apex trigger below. 

 

//Trigger will execute only when a Technical Query is created or updated
trigger UpdateWarranty on Case (before insert, before update) {   
    
    //Run a loop through each query that was created or updated  
    for(Case c : Trigger.new){
        
        //Only execute the following statements if Technical query is created else do nothing 
        If(c.RecordTypeId == '012D0000000AoAZ' && c.Serial_Number_New__C != null){
        
            //Store the value of Serial Number which was entered by the user in variable cid
            String cid = c.Serial_Number_New__c; 
            //Run a query on the Warranty__c table and find the associated fields
            List<Warranty__c> Serials = [SELECT Id, Engine_Number__c, Model_Number__c FROM Warranty__c WHERE Id = :cid] ;
            //Store the fields 
            c.Engine_s_n__c = Serials.get(0).Engine_Number__c; 
            c.Model_Number__c = Serials.get(0).Model_Number__c;
           }
           
     }
}

 This is what i have done so far:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
	@isTest        

    private class TestUpdateWarranty {
    
        public static testMethod void testUpdateWarranty() {
        
        Warranty__c Warranty = new Warranty__c(Name = 'Test11',Model_Number__c = 'MF100',Engine_Number__c = 'ENG100' );
        insert Warranty;  
        
        Warranty__c Warranty1 = [select Id, Name, Model_Number__c, Engine_Number__c FROM Warranty__c where Id =:Warranty.Id];
        Warranty1.Engine_Number__c = 'ENG200';
        update Warranty1;   
        
        System.assertEquals('Test11',Warranty1.Name);
        System.assertEquals('MF100',Warranty1.Model_Number__c);
        System.assertEquals('ENG200',Warranty1.Engine_Number__c);
        
        Case Warranty2 = new Case(Serial_Number_New__c = 'Test11');
        System.assertEquals('MF100',Warranty2.Model_Number__c);
        System.assertEquals('ENG200',Warranty2.Engine_s_n__c);

 

  • March 16, 2012
  • Like
  • 0

Hi All,

 

I currently have 67% code coverage for one of my apex classes but, I'm struggling to cover the following lines:

 

 

if (caseOwner=='' && contactName=='' && accountname!='')
{ 

con = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Owner.Name, Account.Name, Contact.Name FROM Case WHERE RecordTypeId =:RecordTypeId AND Account.Name LIKE :accountname]));
con.setPageSize(200);

}

 Any help on how i can cover these lines would be greatly appreciated!! 

  • March 14, 2012
  • Like
  • 0

Hi All,

 

I dont usually have any issues with formulas but for some reason i cant get this simple text formula below to work and so would appreciate any help please.

 

Upon the creation of a case i would like to populate let say field abc__c with the value of a team depending on the person which has created the record/case. 

 

I have tried all of the following, BUT none seem to work:

 

- IF(OwnerId = "005D0000001CFnlIAG", "Team A", Null)

- IF(CreatedBy.Alias = "JoeBloggs", "Team A", Null)

- IF( CreatedById = "005D0000001CFnl", "Team A", Null)

 

Thanks in Advance

  • March 12, 2012
  • Like
  • 0
Hi,

Is it possible to prevent users from editing a record based on a specfic value in a field?  
For example users should not be able to edit a opportunity record if Stage equals 'Won OR Lost'?

Would appreciate any help!!
  • September 03, 2014
  • Like
  • 1
Hi All,

I need help please with my Test Class.
I have 60% code coverage. See below. Any help would be great. Thanks! 
 
trigger ManageUserCase on Case (before update){
    set<String> usrIds = new set<String>();    
    
    for(Case cs :Trigger.New){
        if(Trigger.isInsert || (Trigger.isUpdate && (cs.OwnerId != Trigger.OldMap.get(cs.Id).OwnerId))){
            usrIds.add(cs.OwnerId);
        }
    }
      
    if(usrIds.size() > 0){
        map<string,User> userMap = new map<string,user>();        
        for(User u : [select Id, Back_Up__c, Back_Up__r.Name, User_Out__c from User Where Id IN: usrIds 
                      and User_Out__c = true]){
            userMap.put(u.Id,u);
        }        
        
        for(Case cs : Trigger.new){
            if(userMap.containsKey(cs.OwnerId)){
                string otherUsername = userMap.get(cs.OwnerId).Back_Up__r.Name;
                if(otherUsername == null)
                    otherUsername = 'Someone else';
                    cs.addError('Please assign Case to '+otherUsername);
            }
        }
    }
}

Test Class:
 
@isTest

private class TestManageUserCase {

public static testMethod void TestManageUserCase(){

//Insert user
        List<User> Userlist = new List<user>();
        Profile pf = [Select id from Profile where  name = 'System Administrator' LIMIT 1];
        
        for(integer i=0;i<=8;i++)
        {
         user usr = new User();
         usr.firstName = 'test12' + i;
         usr.LastName = 'test22'+ i;
         usr.Alias = '122'+ i;
         usr.Email = 'xy@demo.com' + i;
         usr.UserName='testuser2@testclass.com'+ i;
         usr.ProfileId = pf.id;
         usr.CommunityNickname = usr.firstname+'_'+usr.lastName;
         usr.EmailEncodingKey ='ISO-8859-1';
         usr.LanguageLocaleKey = 'en_US';
         usr.TimeZoneSidKey ='America/New_York';
         usr.LocaleSidKey = 'en_US';
         usr.User_Out__c = False;
         Userlist.add(usr);
        }
        
        insert Userlist;

Case cs = new Case(ownerid = userlist[0].id, status='Open', Back_Up__c=userlist[0].id);
insert cs;

Case cs1 = [select id, ownerid, back_up__c from case where id=: cs.id];
cs1.ownerid=userlist[1].id;

update cs1;

}
}

 
  • May 18, 2015
  • Like
  • 0
Hi All,

Need some help please.

I have created a trigger which should update the OwnerId on Case object using UserId from field Back_Up__c On Case object.

But i cant get this to work.  Yet i get no error messages. Any help would be most appreciated. 

trigger CaseOutofOffice on Case (after update) {

    If (Trigger.isAfter){
        List<Case> Cases = new List<Case>();
            for (Case c : cases) {
                If (c.Status != 'Closed' && (c.Back_Up__c!=null || c.Back_Up__c!='')){
                    c.OwnerId = c.Back_Up__c;
                    c.IsBackUp__c = True;                   
}
    Update c;
}}}
  • May 13, 2015
  • Like
  • 0
Hi,

I have written the following trigger which isn't working. When I change the Case Owner i get error message "Case Owner: owner cannot be blank". 
The Back_Up__c field is a lookup field and so exists in the User Object and so when you a user creates / updates a Case the Back_Up__c field is automatically populated via another Apex class.   

When my trigger is executed it seems that Salesforce has not populated field Back_Up__c and hence the erro rmessage above is displayed.  Is this correct?  How do i get around this? Please help?

trigger CaseAssignmentOutofOffice on Case (before update) {
       
   For (Case c : Trigger.New) {
        Case NewCase = Trigger.newMap.get(c.id);
        Case OldCase = Trigger.oldMap.get(c.id);
        
        If (OldCase.OwnerId != NewCase.OwnerId && c.Status != 'Closed'){
        c.OwnerId = c.Back_Up__c;
        c.IsBackUp__c = True;     
        }
}
}
  • May 13, 2015
  • Like
  • 0
Hi All,

I have written a basic trigger and currently have code coverage of 66%.

Not sure how to cover lines 8 and 9. Could anyone help me please??

trigger CaseAssignmentOutofOffice on Case (before update) {
    
    For (Case c : Trigger.new) {
        Case NewCase = Trigger.newMap.get(c.id);
        Case OldCase = Trigger.oldMap.get(c.id);

        If (OldCase.OwnerId != NewCase.OwnerId && c.Status != 'Closed' && NewCase.Back_Up__c != Null){
        c.OwnerId = NewCase.Back_Up__c;
        c.IsBackUp__c = True;
    }
}
  • May 12, 2015
  • Like
  • 0
Hi,

How can i access large volumes of data without the need to batch upload this info to Salesforce?
For example i want to look up a Marketing Code for an Item we sell and so rather uploadng 1million+ item records with there marketing code in SF.com i would like to search an external source and retrieve the info.  Is this only possible through Web services etc? 
  • March 04, 2015
  • Like
  • 0
Hello,

Is it possible to create a report, which only shows 5 or more Open Cases for a Customer?  Not sure how to apply this criteria of 5 or more. 

Any help would be greatly appreciated.
 
  • November 10, 2014
  • Like
  • 0
Hi,

Is it possible to prevent users from editing a record based on a specfic value in a field?  
For example users should not be able to edit a opportunity record if Stage equals 'Won OR Lost'?

Would appreciate any help!!
  • September 03, 2014
  • Like
  • 1
Hi,

I would like one of my Case Worklows to only trigger during Business Days.  Currently users are receving email alerts on a Sunday and Saturday whereas they should only receive alerts Monday to Friday. 
Unable to use the Escalation functioanlty due to limitations. 

Can this be done?

any help would be greatly appreciated.
  • July 08, 2014
  • Like
  • 0
Hi,

I want to restrict what Cases users can assign to other users / queues by implementing some logic such as field abc__c = '123' and field xyz__c <> '456' etc.
I have tried validation rules but for this to work my criteria must equal true and so this is not a viable solution.  I believe i can only achive this through triggers.  Could some please advise?
  • June 13, 2014
  • Like
  • 0