• SFDCCrystalCo
  • NEWBIE
  • 20 Points
  • Member since 2015
  • Crystal & Co.

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies
Hello - I am receiving 0% coverage on the below trigger which seems simple enough.  Can anyone please advise here?  My unit test is below.

trigger CannotDeleteAccount on Account (before delete){

    for  (Account a: trigger.old){

        if (a.Current_User_Profile__c != 'System Administrator' && a.Client_Code__c != null){
    
            a.adderror('Account is synced and cannot be deleted or merged.');
           
        } 
    }
}

==========================================================================
Unit Test:

@isTest
public class TestCannotDeleteAccount {
    
    public void myTestMethod(){
       
       Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
       
       User u = new User(Alias = 'standt', Email='standarduser@testorg.com',
       EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
       LocaleSidKey='en_US', ProfileId = p.Id,
       TimeZoneSidKey='America/Los_Angeles', UserName='standarduser@testorg.com');
       insert u;
       
       system.runAs(u){

       SIC_Code__c sic = new SIC_Code__c(Name = 'Education',SIC_Code__c = '12345');
        
       insert sic;
        
       Account a = new Account(Name = 'Test', Legal_Entity__c = 'Corporation', Description = 'Test', Phone = '2125551234',
       Primary_City__c ='NY',Primary_Country__c = 'United States', Primary_State_Province__c = 'NY', Primary_Street__c = '32 Old Slip',          Primary_Zip_Postal_Code__c = '10001',
       Rating = 'Cold',Industry = 'Education', SIC_Code_Nmae__c = sic.id, Client_Code__c = '12345');
        
       insert a;
              
       try
        {
            Delete a;
        }
                catch(Exception e) {
                    {
                        system.assertEquals('Account is synced to billing system and cannot be deleted or merged.', e.getMessage());
                    }
                }
       }
        
    }   
}
I created a trigger easily enough using the new Process Builder that creates a child custom object record from the original Opportunity.  

Great...

Now, how do we make this custom object record (which has a master-detail to the Opportunity) visible to a Force.com user who doesn't see Opportunities at all?

Is this even possible?

Thanks!
I am trying to get some understanding of when to bulkify code.

My trigger below executes a simple field update when an Account value is changed - no other objects involved here.

I have inserted 600+ Accounts in my Sandbox and subsequently updated these same records with no issues using Data Loader.

That said, do I need to 'bulkify' this code any further?

trigger AccountAllowTransfer on Account (before update) 
{
    for (Account a : Trigger.new) 
    {
        if (a.Producer__c == null)                
        {
            a.Allow_Transfer__c = 'Yes';
        }else{
            a.Allow_Transfer__c = 'No';
        }
    }        
}
Hello - I am receiving 0% coverage on the below trigger which seems simple enough.  Can anyone please advise here?  My unit test is below.

trigger CannotDeleteAccount on Account (before delete){

    for  (Account a: trigger.old){

        if (a.Current_User_Profile__c != 'System Administrator' && a.Client_Code__c != null){
    
            a.adderror('Account is synced and cannot be deleted or merged.');
           
        } 
    }
}

==========================================================================
Unit Test:

@isTest
public class TestCannotDeleteAccount {
    
    public void myTestMethod(){
       
       Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
       
       User u = new User(Alias = 'standt', Email='standarduser@testorg.com',
       EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
       LocaleSidKey='en_US', ProfileId = p.Id,
       TimeZoneSidKey='America/Los_Angeles', UserName='standarduser@testorg.com');
       insert u;
       
       system.runAs(u){

       SIC_Code__c sic = new SIC_Code__c(Name = 'Education',SIC_Code__c = '12345');
        
       insert sic;
        
       Account a = new Account(Name = 'Test', Legal_Entity__c = 'Corporation', Description = 'Test', Phone = '2125551234',
       Primary_City__c ='NY',Primary_Country__c = 'United States', Primary_State_Province__c = 'NY', Primary_Street__c = '32 Old Slip',          Primary_Zip_Postal_Code__c = '10001',
       Rating = 'Cold',Industry = 'Education', SIC_Code_Nmae__c = sic.id, Client_Code__c = '12345');
        
       insert a;
              
       try
        {
            Delete a;
        }
                catch(Exception e) {
                    {
                        system.assertEquals('Account is synced to billing system and cannot be deleted or merged.', e.getMessage());
                    }
                }
       }
        
    }   
}
I created a trigger easily enough using the new Process Builder that creates a child custom object record from the original Opportunity.  

Great...

Now, how do we make this custom object record (which has a master-detail to the Opportunity) visible to a Force.com user who doesn't see Opportunities at all?

Is this even possible?

Thanks!