Posts

Showing posts from May, 2022

Write a trigger with its test class for only system admin user should be able to delete the task.

....Trigger.... trigger DeleteCheck on Task (before delete) { Id profileid=Userinfo.getProfileId(); profile profilname=[select Name from Profile where id=:profileid]; for(Task accountDuplicate:Trigger.old) { if(profilname.Name!='System Administrator') { accountDuplicate.addError('No Access for Deletion'); } } } . ...Test Class.... @istest public class DeleteCheckTest  {     @istest     static  void TestAccountTrigger(){         Task Tcc = new Task();         Tcc.Subject =  'Email';         Tcc.Priority =  'Low';         Tcc.Status = 'in progress';         insert Tcc;                  Id profileid=Userinfo.getProfileId();         profile profilname=[select Name from Profile where id=:pro...

Populate Description field with the user first name who creates or updates the record by using userInfo standard keyword , and also does not allow user to delete the record. Write it's Test class also.

Example : If user is Test User "Author Last updated by user firstName (use userInfo to fetch firstname)" ....TRIGGER.... trigger PopulateDescription on Account (before insert, before update, before delete){ If(trigger.isInsert) { for(Account Acc: Trigger.new){ Acc.Description = 'Account Created by '+ userInfo.getFirstName(); } } else If(trigger.isUpdate) { for(Account Acc: Trigger.new){ Acc.Description = 'Account Last updated by '+ userInfo.getFirstName(); } } if(Trigger.isDelete&&Trigger.isbefore){ for(Account Rec:trigger.old) { Rec.adderror('You Cannot Delete the Account Record'); } } } ....Test Class.... public class PopulateDescriptionTest { @isTest public static void populatedescription(){ Account acc = new Account(); acc.Name = 'Test'; ...

Write a trigger with its test class that does the following when an Account is created: - Create a new case - Assign the owner to Account owner - Subject : Dedupe this Account - Associate with the Account

  Write a trigger with its test class that does the following when an Account is created: - Create a new case - Assign the owner to Account owner - Subject : Dedupe this Account - Associate with the Account ....Trigger.... Trigger trigger DedupeReminder on Account (after Insert) { for (Account acc: Trigger.New){ Case c = New Case(); c.subject = 'Dedupe this Account'; c.OwnerId = '0055g000009H34XAAS'; c.AccountId = acc.Id; insert c; } } Find the owner id using this query - Select Ownerid, name from Account .... Test Class.... @istest public class DedupeTestClass { @istest static void TestAccountTri(){ Account Acc = new Account(); Acc.Name = 'Test'; insert Acc; Case c = New Case(); c.subject = 'Dedupe this Account'; c.OwnerId = '0055g000009H34XAAS'; c.AccountId = acc.Id; insert c...