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

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 4
    Replies
Hi All,
I have written a batch apex to copy approval object information to another custome object. Below is my code and I am facing issues with test class.
global class approvalcopy implements Database.Batchable<sObject>{

    global Database.QueryLocator start(Database.BatchableContext BC) {
        String query = 'Select id,Approver_Comments__c,Approv__Approval_Status__c,(Select Id,CreatedDate,Approval__Actual_Approver__r.UserName,Approval__Initial_Submitter__r.username,Approval__Approver_Comments__c,Approval__SubprocessSequence__c FROM Approv__ApprovalRequests__r) From Proposal__Proposal__c where Approv__Approval_Status__c = \'Approved\' ';
        return Database.getQueryLocator(query);
    }     
    global void execute(Database.BatchableContext BC, List<Proposal__Proposal__c> setaudList) {
        list<Audit_Log__c> aud = new List<Audit_Log__c>();
        for(Proposal__Proposal__c s : setaudList) {        
            Audit_Log__c a = new Audit_Log__c();
            a.Action__c = 'Approval Information';
            a.Description__c = s.Approv__ApprovalRequests__r[0].Approval__Approver_Comments__c;
            a.Date__c = s.Approv__ApprovalRequests__r[0].CreatedDate;
            a.User__c = s.Approv__ApprovalRequests__r[0].Approval__Initial_Submitter__r.username;
            a.Delegate_User__c = s.Approv__ApprovalRequests__r[0].Approval__Actual_Approver__r.UserName;
            aud.add(a);
        }
        try {
            insert aud;
            
        } catch(Exception e) {
            System.debug(e);
        }
        
    }   
    
    global void finish(Database.BatchableContext BC) {
        
    }
}

I have written a test class by creating test data for proposal object, approval object and called batch class inside Test.starttest and stop. But still it is not covering code coverage. Please help me with any suggestions.

Thanks in Advance

Regards,
Ramana
Hi All,
I am trying to update related record field values into parent record in a self lookup. I tried writing a triggrt for this but it is not working. This is my code.

 
trigger updComments on college__c (after insert, after update, after delete)
   Set<id> accIdList = new Set<id>();
    List<College__c> colllist = new List<College__c>();
   for(College__c con : Trigger.new)
   {
    accIdList.add(con.College__c);
   }
    for(College__c acc : [Select id, name, University__c,Comments__c,Combined_COmments__c, 
                             (Select Id, name,University__c,Comments__c,Combined_COmments__c From College__r) 
                        From College__c Where Id In : accIdList])
{
    List<String> lstSrting = new List<String>();
    for(College__c con : acc.University__c__r)
    {
        lstSrting.add(con.Comments__c);
    }
    College__c a = new College__c();
    a.id = acc.College__c;
    a.Combined_COmments__c = String.join(lstSrting, ',');
    colllist.add(a);
}
    update colllist;



In above code University__c is a self lookup, I am updaing Comments__c child values into Combined_COmments__c parent record.

Can anyone please suggest me where I am doing wrong
Thanks in Advance

Hi All,
I am trying to cover wrapper class in calss. But it s not covering. I am sharing my class and test class.

Apex class
public class accountCController {
    @AuraEnabled (cacheable=true)
    public static List<accWrapper> getNameValues(List<string> acname){
        List<accWrapper> resultObject = new List<accWrapper>();
        string query = 'SELECT Id,Name FROM account  WHERE  Name';
        query+='=: acname';
        List<SObject> lstResult = Database.query(query);
        for (SObject res : lstResult) {
            accWrapper obj = new accWrapper();
            obj.testId = (String)res.get('Id');
            obj.testName = (String)res.get('Name');
            resultObject.add(obj);
        }       
        return resultObject;
    }
    public class accWrapper{
        @AuraEnabled
        public String testId;
        @AuraEnabled
        public String testName;
    }
	}

Test class:
@isTest
public class accountController_Test {
    static testMethod void testName(){  
        List<string> strList = new List<string>();
        strList.add('A');
        strList.add('B');
        accountCController.getNameValues(strList);
       
    }
}


Its covering "getNameValues" method but it is not covering wrapper class. Please help me on this.​​​​​​​

Thanks in advance

Regards,
​​​​​​​Ramana

Hi All,
I have one number field called seats__c in custom object. My requirement is when I change Seats__c value, I want to capture subtraction of old and new value in another number field(Removed__c). I have written trigger as below. But I am getting some error on this. Can anyone tell me that where I am doing wrong. Please see my code below.
 
trigger quanCol on College__c (after update) {
    List<college__c> collist = [select id,Seats__c, Removed__c from College__c where Id =: Trigger.New];
    for(College__c c : collist)
    {
            c.removed__c = c.Seats__c - trigger.oldMap.get(c.id).Seats__c;
        
    }
    update collist;
}
Please help me here. Thanks in Advance
Error
User-added image
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