• Shreyanka
  • NEWBIE
  • 10 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 27
    Questions
  • 18
    Replies
Hi everyone,

I have a requirement to create custom settings for roles (say for 6-7 roles) and call it in apex class where in the IF condition it should work (custom setting) for OR condition.

So, which custom setting should i create: Hierarchy or List custom settings? also, how to use it in apex class.

Can anyone help me on this.

Thanks in advance! 
Hi Everyone,

For below apex code i have written test class but the code coverage is 70%, couldn't able to increase the coverage. 
And test class is failing, giving below errors:
User-added image

Please anyone help me in increasing the coverage of test class and resolving the above errors.

Thanks in advance!
public with sharing class CaseCommentsHandler {
    public static void checkApprovalRejectionComments(Map<Id,Case> newCaseMap, Map<Id,Case> oldCaseMap) 
    {
        Set<Id> caseIds = new Set<Id>();
        Set<String> cSubtypes = new Set<string>();
        
        for(Case_comment__mdt subtype: [Select Case_Subtype__c From Case_comment__mdt]){
            cSubtypes.add(subtype.Case_Subtype__c);
        }
         
        for(Case updatedCase : newCaseMap.values()) {
            if(cSubtypes.contains(updatedCase.Case_Subtype__c))  {
                if((oldCaseMap.get(updatedCase.Id).Approval_Status__c != updatedCase.Approval_Status__c) &&
                   (updatedCase.Approval_Status__c == 'Approved' || updatedCase.Approval_Status__c == 'Rejected'))
                {
                    caseIds.add(updatedCase.Id);
                }
            }
        }
        
        Set<Id> processInstanceIds = new Set<Id>();
        if(!caseIds.isEmpty()) {
            for(Case updatedCase : [SELECT (SELECT Id FROM ProcessInstances ORDER BY CreatedDate DESC LIMIT 1)
                                    FROM Case WHERE Id IN : caseIds]) {
                                         if (!updatedCase.ProcessInstances.isEmpty()) {
    								processInstanceIds.add(updatedCase.ProcessInstances[0].Id);
									}
                                    }
            
            for(ProcessInstance pi : [SELECT TargetObjectId, (SELECT Id, StepStatus, Comments FROM Steps WHERE StepStatus IN ('Approved', 'Rejected')
                                     ORDER BY CreatedDate DESC LIMIT 2) FROM ProcessInstance WHERE Id IN :processInstanceIds ORDER BY CreatedDate DESC]){
											if (pi.Steps.size() == 1) {
                                              if ((pi.Steps[0].Comments == null || pi.Steps[0].Comments.trim().length() == 0) &&
                                                  (pi.Steps[0].StepStatus == 'Rejected')) {
                                                      newCaseMap.get(pi.TargetObjectId).addError('Please provide rejection comments when rejecting the case!');
                                                  }
                                             else if (pi.Steps[0].StepStatus == 'Approved' && (pi.Steps[0].Comments == null || pi.Steps[0].Comments.trim().length() == 0)) {
                                                  newCaseMap.get(pi.TargetObjectId).addError('Please provide approval comments when approving the case!');
                                              }
                                          }
                                      }
        }
    }
}
 
@isTest
private class CaseCommentsTest{
     @isTest
     static void testCommentRequiredOnApproval() {
        //try {
        // Create a test case record
        Case c1 = new Case();
        c1.Subject = 'Test Case 1';
        c1.Case_Subtype__c = 'Capital Loan';
        c1.Approval_Status__c = 'Submitted';
        c1.Type = 'Loans';
        c1.Case_Type__c = 'Transaction';
        insert c1;

        Test.startTest();
         c1.Approval_Status__c='Approved';
         c1.addError('Please provide approval comments when approving the case!');
         try{
        	update c1;
            System.assert(false, 'Expected validation error');
        }catch(DmlException e){
			 String expectedError = 'Please provide approval comments when approving the case!';
            System.assert(e.getMessage().contains('expectedError'),'Expected validation error:' +expectedError);
        }
         
        Test.stopTest();
         
        Case updatedCase = [Select Id From Case Where Id= :c1.Id];
         
        System.assert(updatedCase.hasErrors(),'Expected validation error');
}

@IsTest
static void testCommentRequiredOnRejection() {
    //try {
        // Create a test case record
        Case c2 = new Case();
        c2.Subject = 'Test Case 1';
        c2.Case_Subtype__c = 'Capital Loan';
        c2.Approval_Status__c = 'Submitted';
        c2.Type = 'Loans';
        c2.Case_Type__c = 'Transaction';

        insert c2;
    
        Test.startTest();
        c2.Approval_Status__c='Rejected';
        c2.addError('Please provide rejection comments when rejecting the case!');
    	try{
        	update c2;
            System.assert(false, 'Expected validation error');
        }catch(DmlException e){
            String expectedError = 'Please provide rejection comments when rejecting the case!';
            System.assert(e.getMessage().contains('expectedError'),'Expected validation error:' +expectedError);
        }
        Test.stopTest();
         
       Case updatedCase = [Select Id From Case Where Id= :c2.Id];
         
       System.assert(updatedCase.hasErrors(),'Expected validation error');
}
}

 
Hi everonye,

I have a requirement where I've to use Country field as multi-select of countries which will be saved as a comma separated list. I display this field on the screen flow. Could anyone help on this "how to achieve multi-select field of countries which will be saved as a comma separated list.


Thanks in advance!
Hi everyone,

I have a requirement where i have to create multi-picklist field: Country, but already country field exists with long text area datatype. So I have to change the existing country(long text area) datatype to multi-picklist datatype where I can use global picklist value set.

But while changing there is no option to select global picklist value set. Can anyone help me on this.


Thanks in advance!
Hi everyone,

I have a requirement like, while updating case record i.e. if a specific custom picklist field value is selected, attachment should be required (Attachment is related list).

So I have created one checkbox field on case object and created record- triggered flow to
  • update the checkbox field to true if attachment is present, and
  • after uploading if attachment is deleted again it should set checkbox field to false. --> this is not working
Can someone help me on this.


Thanks in advance!
Hi everyone,

I have a requirement where i have to make attchments as required when user selects a specific picklist value of a field on Case object.

Can anyone help me to achieve this.


Thanks in advance!
Hi everyone,

My code was vulnerable to SOQL injection so added String.escapeSingleQuotes() to dynamic query, after adding that I am getting below error after running the test class: "FATAL_ERROR System.QueryException: invalid ID field: %%001DJ00000jZ2f2YAC%%".

Can anyone help me how to resolve this issue.


Thanks in Advance!
public with sharing class Sample {
   
    @AuraEnabled
    public Static List<sObject> getRealatedLists(String objectName,id parentId){
        String query =null;
       
         if(objectName=='abc__c'){
            query = 'SELECT all query fields FROM '+objectName+
                ' WHERE field1__c = '+' \'%' +String.escapeSingleQuotes(str)+ '%\''+' order by field3__c';
                                                                                         
        }
        List<SObject> sobjList = Database.query(query);
        //System.debug('test111'+sobjList[0]);
        return sobjList;
            
    }
}

 
Hi Everyone,

I want to retrieve fields, page layouts, flows, workflow rules, sharing rules, permission sets, visualforce pages, apex classes, roles, email-to-case, communities, record types, approval process, process builders with respect to 2 specific profiles.

Please help me to achieve above requirement using VS-Code.

Can anyone give package.xml file and steps to retrieve it.


Thanks in advance!
Hi Everyone,

How to find all existing Apex class, Triggers, Visualforce pages & Visualforce components version below 21.0.

And how to upgrade all of them to current Api version.

Please help me to achieve this.

Thanks in advance!
Hi Everyone,

I have a requirement like have to auto-populate account's billing address to contact's mailing address when account is updated only if checkbox field is selected on contact.
Also, the same way have to auto-populate contact's mailing address to account's billing address.

please help me to achieve the above requirement.

Thanks in advance!!
Hi Everyone,
I am getting "CSRF with VF Call" checkmarx error from below code. So i have added get method to apex class as shown below. But I am not getting how to call get method in test class.

Please help me to include get method in test class.

Thanks in advance!
 
Apex class:


public class xyz {

        public abc objabc{get;set;}
        public Boolean sendEmail {get; set;}
        public Task objtask{get;set;}
        public boolean isChecked{get;set;}
    public xyz() {
        
        
        String objabcId = ApexPages.currentPage().getParameters().get('id');
                
            objabc = new abc();
        
             if(objabcId !=null && objabcId !=''){
                 
                 objabc = [Select id,OwnerId,name from abc 
                            where id=:ApexPages.currentPage().getParameters().get('id')];
             }
              
            if(objabc.id!=null){
                sendEmail = true;
                objtask= new task();
                objtask.whatid=objabc.id;
                objtask.RecordTypeId = [select Id,Name from RecordType where name='abcd' and SOBjectType='Task' limit 1].Id;
                objtask.status = 'Completed';
                objtask.type = 'Assigned';
                objtask.OwnerID = UserInfo.getUserId();
                objtask.Subject='Assignment';
            }
    }
	public abc getabc(){
		return objabc;
	}
	
      
        public pagereference save() {
            try {
                if(objtask.subject!=null){
                    insert objtask;
                    update objabc;
                    if(sendEmail){                       
                        Database.DMLOptions dlo = new Database.DMLOptions();
                        dlo.EmailHeader.triggerUserEmail = true;
                        database.update(objabc,dlo);                        
                    }
                }else{
                    Apexpages.addMessage(new Apexpages.message(ApexPages.Severity.Error,'Subject cannot be Null !!!'));
                    return null;
                }
                string abcobjurl = objabc.id;
                abcobjurl = abcobjurl.substring(0,3);
                PageReference orderPage = new PageReference('/' + abcobjurl);
                return orderPage;
            } catch (Exception e) {
                system.debug('---inside Exception---'+e.getMessage());
                system.debug('---inside Exception Line---'+e.getLineNumber());
                Apexpages.addMessage(new Apexpages.message(ApexPages.Severity.Error,e.getMessage()));
                return null;
            }
        }
        
}

Below code is the test class that i have written but not getting how to include get method in it.
"i just tried by calling it as Classname.methodname" getting error.
Test class:

@IsTest
Public class TestShareFilesWithCommunityUsers {
    @IsTest
    Public static void testmethod1(){
        Test.startTest();
        abc oAbc =new abc (Name='Demo');//Fill All Required Fields
        insert oAbc ; 
       ApexPages.currentPage().getParameters().put('id',oAbc .id);
       xyz abc= new xyz();
        abc.save();
        abc.objabc = oAbc;
        abc.sendEmail = true;
        Test.stopTest();
        
    }
}

 
Hi Everyone,
I am new to Apex, please help me in writing apex class for " auto populating contact mailing address with account Billing address".

Thanks in advance!
Hi everyone,
I am getting error "Method does not exist or incorrect signature: void method3(List<opportunity>) from the type SampleTriggerHandler" on SampleTrigger class.

Please help me to fix this error.

Thanks in advance!
 
Trigger Code:

trigger SampleTrigger on Abc (before insert,before update, after undelete, after insert, after update) {
    
    if( trigger.isInsert && trigger.isBefore) 
    {
		SampleTriggerHandler.method1(trigger.new,Trigger.oldMap);
    }
    if( (trigger.isUpdate && trigger.isBefore) ||  (trigger.isundelete))
    {
        
        SampleTriggerHandler.method1(trigger.new,Trigger.oldMap);
    }
    if(Trigger.isAfter && (Trigger.isInsert || Trigger.isUpdate || Trigger.isUndelete)) 
	{
        SampleTriggerHandler.method2(Trigger.new, Trigger.oldMap);
    }
    
    if(Trigger.isAfter && (Trigger.isInsert || Trigger.isUpdate ))
    {
		SampleTriggerHandler.method3(trigger.new);
    }
    
}
 
TriggerHandler Code:


public class SampleTriggerHandler {

public static void method1
{
//code block
}

public static void method2
{
//code block
}

    
public static void method3 (List<opportunity> opp)
{
set<id> oppid = new set<id>();

List<opportunity> oppList = [select id, opp_name, from Opportunity where id=:oppid];

List<opportunity> updateList = new List<opportunity>();

Map<Id, opportunity> oppMap= new Map<id,opportunity>();

for(opportunity opp1: oppList) {

}
}
}

 
Hi Everyone,
Please help me in writing test class for below code

Thanks in advance!
Apex Code example:

public class Example{
public class myMethod{

//code block

}

public Example getAbc{
return abc;
}

 public pagereference save() {

//code block

}
}
Hi Everyone,
I am getting "CSRF with VF call"  checkmarx errorfrom the below code.

Please help me to fix this error.

Thanks in advance!
 
1) Apex code:

public class xyz {

        public abc objabc{get;set;}
        public Boolean sendEmail {get; set;}
        public Task objtask{get;set;}
        public boolean isChecked{get;set;}
    public xyz() {
        
        
        String objabcId = ApexPages.currentPage().getParameters().get('id');
                
            objabc = new abc();
        
             if(objabcId !=null && objabcId !=''){
                 
                 objabc = [Select id,OwnerId,name from abc 
                            where id=:ApexPages.currentPage().getParameters().get('id')];
             }
              
            if(objabc.id!=null){
                sendEmail = true;
                objtask= new task();
                objtask.whatid=objabc.id;
                objtask.RecordTypeId = [select Id,Name from RecordType where name='abcd' and SOBjectType='Task' limit 1].Id;
                objtask.status = 'Completed';
                objtask.type = 'Assigned';
                objtask.OwnerID = UserInfo.getUserId();
                objtask.Subject='Assignment';
            }
    }
      
        public pagereference save() {
            try {
                if(objtask.subject!=null){
                    insert objtask;
                    update objabc;
                    if(sendEmail){                       
                        Database.DMLOptions dlo = new Database.DMLOptions();
                        dlo.EmailHeader.triggerUserEmail = true;
                        database.update(objabc,dlo);                        
                    }
                }else{
                    Apexpages.addMessage(new Apexpages.message(ApexPages.Severity.Error,'Subject cannot be Null !!!'));
                    return null;
                }
                string abcobjurl = objabc.id;
                abcobjurl = abcobjurl.substring(0,3);
                PageReference orderPage = new PageReference('/' + abcobjurl);
                return orderPage;
            } catch (Exception e) {
                system.debug('---inside Exception---'+e.getMessage());
                system.debug('---inside Exception Line---'+e.getLineNumber());
                Apexpages.addMessage(new Apexpages.message(ApexPages.Severity.Error,e.getMessage()));
                return null;
            }
        }
        
}
 
2) VF page code:

<apex:page lightningStylesheets="true" Controller="XYZ" >
    <apex:form >
    <apex:pageblock id="PageBlock-Id" title="Select New Owner">
        <apex:pageBlockSection >
            <apex:outputfield value="{!objabc.Name}"/><br/>
            <apex:inputField value="{!objabc.OwnerId}"/>
                <br/>
            
            <apex:inputcheckbox label="Send Notification Email" value="{!sendEmail}" />
            
        </apex:pageBlockSection> 
        
        <apex:pageBlockSection title="Create Task and Log Hours" >
            <apex:pageMessages id="PageMsgId" /><br/>
            <apex:outputField value="{!objtask.RecordTypeId}"/>
            <apex:outputField value="{!objtask.Status}"/>
            <apex:inputField value="{!objtask.Priority}"/>
            <apex:outputField value="{!objtask.type}" />
            <apex:inputField value="{!objtask.Time_Logged__c}"/>
            <apex:inputField style="width:240px;" value="{!objtask.Description}"/>
        </apex:pageBlockSection> 
        
        <div align="center" draggable="false" >
            <apex:commandButton action="{!save}" value="Save" rerender="PageMsgId"/>
        </div>
    </apex:pageblock> 
    </apex:form> 
</apex:page>

 
Hi Everyone,
I am getting "CSRF with VF call" MethodInvokeExpr checkmarx issue in the line 1 of the below code.

Please help me to resolve this.
Thanks in advance!


<apex:page lightningStylesheets="true" Controller="XYZ" >
    <apex:form >
    <apex:pageblock id="PageBlock-Id" title="Select New Owner">
        <apex:pageBlockSection >
            <apex:outputfield value="{!objabc.Name}"/><br/>
            <apex:inputField value="{!objabc.OwnerId}"/>
                <br/>
            
            <apex:inputcheckbox label="Send Notification Email" value="{!sendEmail}" />
            
        </apex:pageBlockSection> 
        
        <apex:pageBlockSection title="Create Task and Log Hours" >
            <apex:pageMessages id="PageMsgId" /><br/>
            <apex:outputField value="{!objtask.RecordTypeId}"/>
            <apex:outputField value="{!objtask.Status}"/>
            <apex:inputField value="{!objtask.Priority}"/>
            <apex:outputField value="{!objtask.type}" />
            <apex:inputField value="{!objtask.Time_Logged__c}"/>
            <apex:inputField style="width:240px;" value="{!objtask.Description}"/>
        </apex:pageBlockSection> 
        
        <div align="center" draggable="false" >
            <apex:commandButton action="{!save}" value="Save" rerender="PageMsgId"/>
        </div>
    </apex:pageblock> 
    </apex:form> 
</apex:page>
Hi everyone,
Please help me in writting test class for the below apex code:

public class xyz {

        public abc objabc{get;set;}
        public Boolean sendEmail {get; set;}
        public Task objtask{get;set;}
        public boolean isChecked{get;set;}
    public xyz() {
        
        
        String objabcId = ApexPages.currentPage().getParameters().get('id');
                
            objabc = new abc();
        
             if(objabcId !=null && objabcId !=''){
                 
                 objabc = [Select id,OwnerId,name from abc 
                            where id=:ApexPages.currentPage().getParameters().get('id')];
             }
              
            if(objabc.id!=null){
                sendEmail = true;
                objtask= new task();
                objtask.whatid=objabc.id;
                objtask.RecordTypeId = [select Id,Name from RecordType where name='abcd' and SOBjectType='Task' limit 1].Id;
                objtask.status = 'Completed';
                objtask.type = 'Assigned';
                objtask.OwnerID = UserInfo.getUserId();
                objtask.Subject='Assignment';
            }
    }
      
        public pagereference save() {
            try {
                if(objtask.subject!=null){
                    insert objtask;
                    update objabc;
                    if(sendEmail){                       
                        Database.DMLOptions dlo = new Database.DMLOptions();
                        dlo.EmailHeader.triggerUserEmail = true;
                        database.update(objabc,dlo);                        
                    }
                }else{
                    Apexpages.addMessage(new Apexpages.message(ApexPages.Severity.Error,'Subject cannot be Null !!!'));
                    return null;
                }
                string abcobjurl = objabc.id;
                abcobjurl = abcobjurl.substring(0,3);
                PageReference orderPage = new PageReference('/' + abcobjurl);
                return orderPage;
            } catch (Exception e) {
                system.debug('---inside Exception---'+e.getMessage());
                system.debug('---inside Exception Line---'+e.getLineNumber());
                Apexpages.addMessage(new Apexpages.message(ApexPages.Severity.Error,e.getMessage()));
                return null;
            }
        }
        
}


Thanks in advance!
Hi everyone,

I have created Approval process for approving records. Here I also want to give access to assigned approvers to edit the Read-only fields present in the record when it is submitted for approval.

I am trying on this. Please help me to achieve this.

Thanks in advance!
Hi everyone,
I have a requirement like "three read-only fields have to be edited only by assigned approvers when the record is submitted for approval".

Please help me to achieve this.

Thanks in advance!
I have created permission set for users who can create records. Also, created "Custom permission" too. Now I have to write a validation rule by calling custom permission into it to prevent users from creating records. How to write validation rules to achieve this.

Please help me to achieve this.


Thanks in advance!!
Hi everyone,

I have a requirement to create custom settings for roles (say for 6-7 roles) and call it in apex class where in the IF condition it should work (custom setting) for OR condition.

So, which custom setting should i create: Hierarchy or List custom settings? also, how to use it in apex class.

Can anyone help me on this.

Thanks in advance! 
Hi everonye,

I have a requirement where I've to use Country field as multi-select of countries which will be saved as a comma separated list. I display this field on the screen flow. Could anyone help on this "how to achieve multi-select field of countries which will be saved as a comma separated list.


Thanks in advance!
Hi everyone,

I have a requirement like, while updating case record i.e. if a specific custom picklist field value is selected, attachment should be required (Attachment is related list).

So I have created one checkbox field on case object and created record- triggered flow to
  • update the checkbox field to true if attachment is present, and
  • after uploading if attachment is deleted again it should set checkbox field to false. --> this is not working
Can someone help me on this.


Thanks in advance!
Hi everyone,

I have a requirement where i have to make attchments as required when user selects a specific picklist value of a field on Case object.

Can anyone help me to achieve this.


Thanks in advance!
Hi everyone,

My code was vulnerable to SOQL injection so added String.escapeSingleQuotes() to dynamic query, after adding that I am getting below error after running the test class: "FATAL_ERROR System.QueryException: invalid ID field: %%001DJ00000jZ2f2YAC%%".

Can anyone help me how to resolve this issue.


Thanks in Advance!
public with sharing class Sample {
   
    @AuraEnabled
    public Static List<sObject> getRealatedLists(String objectName,id parentId){
        String query =null;
       
         if(objectName=='abc__c'){
            query = 'SELECT all query fields FROM '+objectName+
                ' WHERE field1__c = '+' \'%' +String.escapeSingleQuotes(str)+ '%\''+' order by field3__c';
                                                                                         
        }
        List<SObject> sobjList = Database.query(query);
        //System.debug('test111'+sobjList[0]);
        return sobjList;
            
    }
}

 
Hi Everyone,

How to find all existing Apex class, Triggers, Visualforce pages & Visualforce components version below 21.0.

And how to upgrade all of them to current Api version.

Please help me to achieve this.

Thanks in advance!
Hi Everyone,
I am getting "CSRF with VF Call" checkmarx error from below code. So i have added get method to apex class as shown below. But I am not getting how to call get method in test class.

Please help me to include get method in test class.

Thanks in advance!
 
Apex class:


public class xyz {

        public abc objabc{get;set;}
        public Boolean sendEmail {get; set;}
        public Task objtask{get;set;}
        public boolean isChecked{get;set;}
    public xyz() {
        
        
        String objabcId = ApexPages.currentPage().getParameters().get('id');
                
            objabc = new abc();
        
             if(objabcId !=null && objabcId !=''){
                 
                 objabc = [Select id,OwnerId,name from abc 
                            where id=:ApexPages.currentPage().getParameters().get('id')];
             }
              
            if(objabc.id!=null){
                sendEmail = true;
                objtask= new task();
                objtask.whatid=objabc.id;
                objtask.RecordTypeId = [select Id,Name from RecordType where name='abcd' and SOBjectType='Task' limit 1].Id;
                objtask.status = 'Completed';
                objtask.type = 'Assigned';
                objtask.OwnerID = UserInfo.getUserId();
                objtask.Subject='Assignment';
            }
    }
	public abc getabc(){
		return objabc;
	}
	
      
        public pagereference save() {
            try {
                if(objtask.subject!=null){
                    insert objtask;
                    update objabc;
                    if(sendEmail){                       
                        Database.DMLOptions dlo = new Database.DMLOptions();
                        dlo.EmailHeader.triggerUserEmail = true;
                        database.update(objabc,dlo);                        
                    }
                }else{
                    Apexpages.addMessage(new Apexpages.message(ApexPages.Severity.Error,'Subject cannot be Null !!!'));
                    return null;
                }
                string abcobjurl = objabc.id;
                abcobjurl = abcobjurl.substring(0,3);
                PageReference orderPage = new PageReference('/' + abcobjurl);
                return orderPage;
            } catch (Exception e) {
                system.debug('---inside Exception---'+e.getMessage());
                system.debug('---inside Exception Line---'+e.getLineNumber());
                Apexpages.addMessage(new Apexpages.message(ApexPages.Severity.Error,e.getMessage()));
                return null;
            }
        }
        
}

Below code is the test class that i have written but not getting how to include get method in it.
"i just tried by calling it as Classname.methodname" getting error.
Test class:

@IsTest
Public class TestShareFilesWithCommunityUsers {
    @IsTest
    Public static void testmethod1(){
        Test.startTest();
        abc oAbc =new abc (Name='Demo');//Fill All Required Fields
        insert oAbc ; 
       ApexPages.currentPage().getParameters().put('id',oAbc .id);
       xyz abc= new xyz();
        abc.save();
        abc.objabc = oAbc;
        abc.sendEmail = true;
        Test.stopTest();
        
    }
}

 
Hi Everyone,
I am new to Apex, please help me in writing apex class for " auto populating contact mailing address with account Billing address".

Thanks in advance!
Hi Everyone,
I am getting "CSRF with VF call"  checkmarx errorfrom the below code.

Please help me to fix this error.

Thanks in advance!
 
1) Apex code:

public class xyz {

        public abc objabc{get;set;}
        public Boolean sendEmail {get; set;}
        public Task objtask{get;set;}
        public boolean isChecked{get;set;}
    public xyz() {
        
        
        String objabcId = ApexPages.currentPage().getParameters().get('id');
                
            objabc = new abc();
        
             if(objabcId !=null && objabcId !=''){
                 
                 objabc = [Select id,OwnerId,name from abc 
                            where id=:ApexPages.currentPage().getParameters().get('id')];
             }
              
            if(objabc.id!=null){
                sendEmail = true;
                objtask= new task();
                objtask.whatid=objabc.id;
                objtask.RecordTypeId = [select Id,Name from RecordType where name='abcd' and SOBjectType='Task' limit 1].Id;
                objtask.status = 'Completed';
                objtask.type = 'Assigned';
                objtask.OwnerID = UserInfo.getUserId();
                objtask.Subject='Assignment';
            }
    }
      
        public pagereference save() {
            try {
                if(objtask.subject!=null){
                    insert objtask;
                    update objabc;
                    if(sendEmail){                       
                        Database.DMLOptions dlo = new Database.DMLOptions();
                        dlo.EmailHeader.triggerUserEmail = true;
                        database.update(objabc,dlo);                        
                    }
                }else{
                    Apexpages.addMessage(new Apexpages.message(ApexPages.Severity.Error,'Subject cannot be Null !!!'));
                    return null;
                }
                string abcobjurl = objabc.id;
                abcobjurl = abcobjurl.substring(0,3);
                PageReference orderPage = new PageReference('/' + abcobjurl);
                return orderPage;
            } catch (Exception e) {
                system.debug('---inside Exception---'+e.getMessage());
                system.debug('---inside Exception Line---'+e.getLineNumber());
                Apexpages.addMessage(new Apexpages.message(ApexPages.Severity.Error,e.getMessage()));
                return null;
            }
        }
        
}
 
2) VF page code:

<apex:page lightningStylesheets="true" Controller="XYZ" >
    <apex:form >
    <apex:pageblock id="PageBlock-Id" title="Select New Owner">
        <apex:pageBlockSection >
            <apex:outputfield value="{!objabc.Name}"/><br/>
            <apex:inputField value="{!objabc.OwnerId}"/>
                <br/>
            
            <apex:inputcheckbox label="Send Notification Email" value="{!sendEmail}" />
            
        </apex:pageBlockSection> 
        
        <apex:pageBlockSection title="Create Task and Log Hours" >
            <apex:pageMessages id="PageMsgId" /><br/>
            <apex:outputField value="{!objtask.RecordTypeId}"/>
            <apex:outputField value="{!objtask.Status}"/>
            <apex:inputField value="{!objtask.Priority}"/>
            <apex:outputField value="{!objtask.type}" />
            <apex:inputField value="{!objtask.Time_Logged__c}"/>
            <apex:inputField style="width:240px;" value="{!objtask.Description}"/>
        </apex:pageBlockSection> 
        
        <div align="center" draggable="false" >
            <apex:commandButton action="{!save}" value="Save" rerender="PageMsgId"/>
        </div>
    </apex:pageblock> 
    </apex:form> 
</apex:page>

 
Hi everyone,
Please help me in writting test class for the below apex code:

public class xyz {

        public abc objabc{get;set;}
        public Boolean sendEmail {get; set;}
        public Task objtask{get;set;}
        public boolean isChecked{get;set;}
    public xyz() {
        
        
        String objabcId = ApexPages.currentPage().getParameters().get('id');
                
            objabc = new abc();
        
             if(objabcId !=null && objabcId !=''){
                 
                 objabc = [Select id,OwnerId,name from abc 
                            where id=:ApexPages.currentPage().getParameters().get('id')];
             }
              
            if(objabc.id!=null){
                sendEmail = true;
                objtask= new task();
                objtask.whatid=objabc.id;
                objtask.RecordTypeId = [select Id,Name from RecordType where name='abcd' and SOBjectType='Task' limit 1].Id;
                objtask.status = 'Completed';
                objtask.type = 'Assigned';
                objtask.OwnerID = UserInfo.getUserId();
                objtask.Subject='Assignment';
            }
    }
      
        public pagereference save() {
            try {
                if(objtask.subject!=null){
                    insert objtask;
                    update objabc;
                    if(sendEmail){                       
                        Database.DMLOptions dlo = new Database.DMLOptions();
                        dlo.EmailHeader.triggerUserEmail = true;
                        database.update(objabc,dlo);                        
                    }
                }else{
                    Apexpages.addMessage(new Apexpages.message(ApexPages.Severity.Error,'Subject cannot be Null !!!'));
                    return null;
                }
                string abcobjurl = objabc.id;
                abcobjurl = abcobjurl.substring(0,3);
                PageReference orderPage = new PageReference('/' + abcobjurl);
                return orderPage;
            } catch (Exception e) {
                system.debug('---inside Exception---'+e.getMessage());
                system.debug('---inside Exception Line---'+e.getLineNumber());
                Apexpages.addMessage(new Apexpages.message(ApexPages.Severity.Error,e.getMessage()));
                return null;
            }
        }
        
}


Thanks in advance!
Hi everyone,

I have created Approval process for approving records. Here I also want to give access to assigned approvers to edit the Read-only fields present in the record when it is submitted for approval.

I am trying on this. Please help me to achieve this.

Thanks in advance!
I have created one rich-text image component for one of the lightning record home pages and I have moved the same record page via Changesets to another Sandbox Org.

But that rich-text image component is not visible in the Sandbox org.

Can anyone help me to figure out what is the issue here?

Thanks in advance!
I tried to delete files directly from the content details page, I'm getting an error: "This document is awaiting archival. Cannot delete the file at this time. Please try again later".

Anyone, please share the apex code that deletes content files from salesforce.

Thanks in advance.