• shikher jain
  • NEWBIE
  • 30 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 5
    Replies
Create a VF page that should use VF component. This page should contain one textarea and button. User should be able to write SOQL query in text area and when user click on Submit Query button this query should pass to VF Component.
Create a VisualForce Component for above VF page, This component should Provides following
functionality:

This component should execute query and return records.Component code should be able to handle query on any Sobject.
Component should handle SOQL validation. If query is wrong then handle exception.
 
Here is my test class please help me out how can i assert trigger error "you cant insert teacher with subject Hindi" in my test class.
@isTest
public class NotInsertTeacherTest {

    @Istest static void NotInsertTeacherHavingSubjectHindi(){
        Class__c testClass = new Class__c(Name = 'Hindi', MaxSize__c = 20);
        insert testClass;
        Contact testContact = new Contact(LastName = 'jain');
        insert testContact;
        Teach__c teacher = new Teach__c(Name = 'Shikher',Subjects__c = 'English',
                                        Teacher__c = testContact.id ,Class__c = testClass.id );

        
        
        test.startTest();
        insert teacher;
        test.startTest();
    }
}
trigger CustomStatusChanged on Class__c (before update) {

    for(Class__c cls : trigger.new){
        if(cls.Custom_Status__c == 'Reset'){
            delete [Select Name from Student__c where Class_object__c in :trigger.new];
        }
    }
}

I have written this code but got self reference error
trigger CustomStatusChanged on Class__c (before update) {

    for(Class__c cls : trigger.new){
        if(cls.Custom_Status__c == 'Reset'){
            delete [Select Name from Student__c where Class_object__c in :trigger.new];
        }
    }
}

I have written this code but got self reference error
Create a VF page that should use VF component. This page should contain one textarea and button. User should be able to write SOQL query in text area and when user click on Submit Query button this query should pass to VF Component.
Create a VisualForce Component for above VF page, This component should Provides following
functionality:

This component should execute query and return records.Component code should be able to handle query on any Sobject.
Component should handle SOQL validation. If query is wrong then handle exception.
 
trigger CustomStatusChanged on Class__c (before update) {

    for(Class__c cls : trigger.new){
        if(cls.Custom_Status__c == 'Reset'){
            delete [Select Name from Student__c where Class_object__c in :trigger.new];
        }
    }
}

I have written this code but got self reference error
Hi All,

I receive the following error when attempting to check the challenge for Apply Unit of Work

Challenge Not yet complete... here's what's wrong: 
The 'challangeComplete' method in the 'UnitOfWorkTest' class has not successfully passed all tests. Ensure that you run the tests and it passes successfully before attempting this challenge again.

However, when I run my code in Developer Console, my test passes.  Any ideas on the problem?  Here is the code:

@isTest
public class UnitOfWorkTest {
    @isTest static void challengeComplete(){
        fflib_SObjectUnitOfWork uow = new fflib_SObjectUnitOfWork(
            new Schema.SObjectType[]{
                Account.SObjectType,
                Contact.SObjectType,
                Note.SObjectType
            }
        );
        
        for (Integer i=0 ; i<100 ; i++) {
            Account a = new Account(Name= 'Test' + i);
            uow.registerNew(a);
            
            for (Integer j=0 ; j<5 ; j++) {
                Contact c = new Contact(LastName = 'Test'+i + ' ' +j);
                uow.registerNew(c, Contact.AccountId, a);
                
                Note n = new Note(Body='Test '+i + '' + j, Title='Test'+i+j);
                uow.registerRelationship(n, Note.ParentId, a);
                uow.registerNew(n, Note.ParentId, a);
            }
        }

        uow.commitWork();
 
        fflib_SObjectUnitOfWork uow2 = new fflib_SObjectUnitOfWork(
            new Schema.SObjectType[]{
                Account.SObjectType,
                Contact.SObjectType,
                Note.SObjectType
            }
        );        
        for (Account a : [SELECT Id, Name, (SELECT Id, LastName FROM Contacts), (SELECT Id, ParentId, Title, Body FROM Notes) FROM Account]) {
            a.Name = 'Test';
            uow2.registerDirty(a);
            
            Integer i = 0;
            for (Contact c : a.Contacts) {
                c.LastName = 'Test';
                uow2.registerDirty(c);
                
                a.Notes[i].Body='Test';
                uow2.registerDirty(a.Notes[i]);
                i++;
            }
        }        
        
        test.startTest();
        uow2.commitWork();
        test.stopTest();
        
        System.assertEquals(100, [Select Id from Account].size());
        System.assertEquals(500, [Select Id from Contact].size());
        System.assertEquals(500, [Select Id from Note].size());
    }
}
create an Apex class that inserts a new account named after an incoming parameter. If the account is successfully inserted, the method should return the account record. If a DML exception occurs, the method should return null?
The Apex class must be called 'AccountHandler' and be in the public scope.
The Apex class must have a public static method called 'insertNewAccount'.
The 'insertNewAccount' method must accept an incoming string as a parameter, name the account after the parameter, insert it into the system and then return the account record.
The 'insertNewAccount' method must also accept an empty string, catch the failed DML and return null.