• Ramana V
  • NEWBIE
  • 20 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 4
    Replies
Hi All,
I am facing issues with test class for batch apex. Please find below my classes.

Batch Apex:
 
global class conuserDeactivate implements Database.Batchable<sObject>{
   
    global Database.Querylocator Start(Database.BatchableContext BC)
    {
		set<id> userId = new set<id>();
        List<contact> conList = [select id,User__c from contact where user__r.lastlogindate < =:syste.now().adddays(-14)];        
       for(contact c : caseList){
            uid.add(c.User__c);
           
        }
        string s = 'select isActive from user where id =: userid';    
        return Database.getQuerylocator(s);
    }
   
    global void Execute(Database.BatchableContext BC, List<User> scope){      
        for(User u : scope){
            u.isActive = false;
        }        
        update scope;
    }  
   
    global void finish(Database.BatchableContext BC){
       
    }
}

Test class:
@isTest
public class conuserDeactivateTest {
    static testMethod void deactivateMethod() {
        
        List<sObject> us = Test.loadData(User.sObjectType, 'userResource');
        User u = (User)us[0];
        Id uid = u.id;    
        
        Contact c = new Contact();
        c.LastName = 'TestContact';
       
        c.UserB__c = uid;
        insert c;
       
        Test.startTest();
        conuserDeactivate CUD = new conuserDeactivate();
        DataBase.executeBatch(CUD);            
        Test.stopTest();
    }
}


​​​​​​​
I am facing issues in covering of for loop in start method. I am not able to get user based on last log in date in test class.
Please help me how to cover this in test class.
Thanks in Advance
Regards,
Ramana V
 
Hi All,
I have two object. Student__c (Child) and College__c (Parent).
I want to fetch records of college which are not in Student. So, I have written SOQL like this.

List<college__c> colList = [select id, name from college where ID NOT IN (select college__c from student)];

Now, I have to retrieve colleges from last year (2019) and department equals to Physics. If I am moving to 2021 then I want to see only 2020 records.

How can I modify above SOQL for my requirement.

Please help me.

Thanks in Advance.

Regards,

Ramana V

SOQL Query to retrieve last year records
Hi All,
I have account created basic account creation page in LWC. If I have entered address in any other language other than English then I want to put some validation method in LWC to check that the address is entered in other language. Can someone help me, how to check this.

Thanks in Advance
Hi All,
I have written following inbound email service for lead object.
global class LeadServices implements Messaging.InboundEmailHandler
{
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, Messaging.InboundEnvelope env)
    {
        Messaging.InboundEmailResult result = new  Messaging.InboundEmailResult();
        string emailbody = email.plaintextbody;
        string emailsubject = email.subject;
        string subToCompare = emailsubject.Substring(emailsubject.indexof('ref :') + 5).trim();
        try
        {
            lead l = [SELECT
                Id, 
                Name, 
                Email
            FROM
                lead
            WHERE
                id  = : subToCompare];
            // Add a new Task to the lead record we just found above.
            Task newTask = new  Task();
            newTask.Description = emailbody;
            newTask.Priority = 'Normal';
            newTask.Status = 'Inbound Email';
            newTask.Subject = emailsubject;
            newTask.IsReminderSet = true;
            newTask.ReminderDateTime = System.now();
            newTask.WhoId = l.Id;
           
            Insert newTask;
        }
        catch(QueryException e)
        {
            System.debug('Issue: ' + e);
        }
        result.success = true;
        return result;
    }
}
I am have having 55% code coverage now.
Can someone please hepl me with test class for this?

Thanks in Advance

Regards,
Ramana
Hi All,
I am getting following error in javascript. Please help me with this error.
 
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}   
 
var newRecords = [];   
 
var coapp = new sforce.SObject("Lead");  
coapp.id ="{!Lead.Id}"; 
coapp.Name="{!Lead.Name}" 
coapp.Rating="Hot";             
 
newRecords.push(coapp); 
result = sforce.connection.update(newRecords); 
window.location.reload();

Error: The Name field is required.

Thanks in Advance
Hi All,
I want retrieve case records which from today to 2 years ago exactly. I have tried by using Last_N_DAYS:730. but it is giving even 2016 and before records also. I want only records between today and two years. Not before two years.
Can some please help me with SOQL query

Thanks in Advance!!

Regards,
Ramana
Hi All,
I have written a trigger to create record in price book entry when record is created in product. Now, I want to update the record in proce book entry which created due to this trigger.
Can some give me idea how to do this.

Thanks in advance
Hi All,
I have two object. Student__c (Child) and College__c (Parent).
I want to fetch records of college which are not in Student. So, I have written SOQL like this.

List<college__c> colList = [select id, name from college where ID NOT IN (select college__c from student)];

Now, I have to retrieve colleges from last year (2019) and department equals to Physics. If I am moving to 2021 then I want to see only 2020 records.

How can I modify above SOQL for my requirement.

Please help me.

Thanks in Advance.

Regards,

Ramana V

SOQL Query to retrieve last year records
Hi All,
I have account created basic account creation page in LWC. If I have entered address in any other language other than English then I want to put some validation method in LWC to check that the address is entered in other language. Can someone help me, how to check this.

Thanks in Advance
Hi All,
I want retrieve case records which from today to 2 years ago exactly. I have tried by using Last_N_DAYS:730. but it is giving even 2016 and before records also. I want only records between today and two years. Not before two years.
Can some please help me with SOQL query

Thanks in Advance!!

Regards,
Ramana