Apex Assignment
Apex Assignment
Data Model
Trigger
Prevented using SOQL and DML operations within loop to avoid Governer Limitations.
Used try-catch for exception handling.
for(Course__c c: cList)
{
certCourseMap.add(c.Certification__c);
}
for(Voucher__c v: vList)
{
certVoucherMap.put(v.Certification__c,v);
}
if(!certCourseMap.contains(vr.Certification__c))
{
errorString += '- Course Not Completed.\n';
}
if(!certVoucherMap.containsKey(vr.Certification__c))
{
errorString += '- Voucher Not Available.\n';
}
else
{
vr.Voucher__r = certVoucherMap.get(vr.Certification__c);
vr.Voucher__c = certVoucherMap.get(vr.Certification__c).Id;
}
if(errorString.length()>0)
{
vr.addError('Record Cannot be inserted because of the
following errors:\n\n'+errorString);
}
}
}
catch(Exception e)
{
System.debug('Error: '+e.getMessage());
}
Asynchronous Apex
Future Method
To Log details of newly created voucher requests
@future
public static void logMethod(String msg)
{
System.debug(msg);
}
Queueable Interface
To automatically Update Certification Expiry Date after the date is past.
Schedulable Job
@isTest
public class CertificationTesting
{
@isTest(SeeAllData=true)
public static void testCreateVoucherRequest()
{
System.assert(!result.isSuccess());
}
}
Frontend UI
Features:
user details.
courses enrolled.
course completion status.
Details of the available certifications.
Search certifications by name.
Contoller
@AuraEnabled(cacheable=true)
public static List<Course__c> getCourseByUser(Id userId)
{
System.debug(userid);
return [Select
Id,Name,Status__c,Certification__r.Name,Certification__r.Description__c,Certif
ication__r.Image_Url__c from Course__c where CreatedById =:userId];
}
@AuraEnabled(cacheable=true)
public static List<Certification__c> searchCertificationByName(String n)
{
try
{
String searchString = '%'+n+'%';
return [Select
Id,Name,Active__c,Description__c,Cost__c,Level__c,Image_Url__c from
Certification__c where Name like :searchString Limit 100];
}
catch(Exception e)
{
System.debug(e.getMessage());
return new List<Certification__c>();
}
@AuraEnabled(cacheable=true)
public static Certification__c getCertificationByName(String n)
{
try
{
return [Select Id,Name,Active__c,Description__c,Cost__c,Level__c
from Certification__c where Name =:n limit 1];
}
catch(Exception e)
{
System.debug(e.getMessage());
return null;
}
}
@AuraEnabled(cacheable=true)
public static Certification__c getCertificationById(Id certificationId)
{ try
{
return [Select Id,Name,Active__c,Description__c,Cost__c,Level__c
from Certification__c where Id=:certificationId];
}
catch(Exception e)
{
System.debug('Error: '+e.getMessage());
return null;
}
}
@AuraEnabled(cacheable=true)
public static List<Certification__c> getAllCertifications()
{
try
{
return [Select
Id,Name,Active__c,Description__c,Cost__c,Level__c,Image_Url__c from
Certification__c Limit 100];
}
catch(Exception e)
{
System.debug(e.getMessage());
return new List<Certification__c>();
}
}
}