• Aradhika Chawla 73
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 4
    Replies
Hi Everyone,
        I have a question on how to cover exceptions of Database.Save method. The method I want to cover is given below:

Apex Code : 
     Database.SaveResult[] lsr = Database.insert(GateReviewShrs,false); 
     // Create counter
     Integer i=0;
     // Process the save results
        for(Database.SaveResult sr : lsr){
            if(!sr.isSuccess()){
                // Get the first save result error
                Database.Error err = sr.getErrors()[0];
                if(!(err.getStatusCode() == StatusCode.FIELD_FILTER_VALIDATION_EXCEPTION  
                                               &&  err.getMessage().contains('AccessLevel'))){

                    trigger.newMap.get(GateReviewShrs[i].ParentId).
                      addError(
                       'Unable to grant sharing access due to following exception: '
                       + err.getMessage());
                }
            }
            i++;
        }
I am trying to cover this exception by making a wrong entry in my test class (one of inactive user). Code given below: 


@isTest
public class Test_PrasApexCode {
    
    static testMethod void testDoGet1() {



        
        Costpoint_Project__c testCostpointProject = new Costpoint_Project__c();
        testCostpointProject.Name = '0281300.003';

        insert testCostpointProject;

        //Fetch related Project Risk Review form.
        Project_Risk_Review__c ProRiskRev=[Select id,DVP__c,Project_Manager__c,Chair_Reviewer__c,Delegate__c 
                                           from Project_Risk_Review__c where Costpoint_Project__c=:testCostpointProject.Id];

        List<User> u2= [SELECT Id FROM User WHERE isActive=False and ProfileId=:Label.PRAS_RTI_BusinessDevelopment_Profile_Id Limit 1];

  
         ProRiskRev.Delegate__c=u2[0].Id;
         Update ProRiskRev;

      
But when I try to do this my coverage increases but test method fails . It has to fail because the user is inactive. Is there any way to pass the test method and increase the coverage?

 
Is there any way to get just the "OuterHTML" text of a richtext field through Apex (NOT Visualforce)? I've checked all the String functions but none of them seem to do this.
e.g. the actual field content is: <body> This is the contents. </body>

I would like a trigger to return the value "This is the contents."

Is this possible?
Thanks,
Matt
HI Everyone, 

My org is in desperate need of allowing users to delete themselves from Account Teams. HOWEVER, we don't want users to be able to delete OTHER users. I could easily write a trigger to do that but when i try, the system says I can not write triggers on the Account Team Object. My next plan was to track deletes so I could monitor users that are deleting other users- but, again, I hit a road block bc you can't report on Account Team deletes. In fact, account team deletes don't even go into the sandbox. 

Does anyone know of a way to query (within the system) all Account Team members that have been deleted? SFDC says to use the "getDeleted()" function but it seems like that is only for the SOAP Api. I just want to quickly pull a query of deleted account team members and the last modified by. 

If anyone has a solution, please let me know. THANK YOU!!!!!!!!!!!!!!!!!

Hey folks,

how can I accomplish a testcoverage for the Database.Error class?

 

This is my code:

 

Database.Saveresult[] lsr = Database.update(lstSchedulingsToUpdate, false);

for(Database.SaveResult sr : lsr)
{
	if(!sr.isSuccess())
	{
	  	for(Database.Error err : sr.getErrors())
	  		errorMsgs += sr.getId() + ': ' + err.getMessage() + '(' + err.getStatusCode() + ')' + '\n';
	 }
}

 

Thanks in advance!

Josh