• sree prasad
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 7
    Replies
I need Test Class for this Trigger


 trigger AOS_Case_Creation on Payment_Schedule__c (After Update) {
            List<Case> listC = new List<case>();
            Set<Id> regId=new Set<Id>();
            List<Case> Existingcase = new List<case>();
            Map<String,opportunity> mapReg=new Map<String,opportunity>();
            
            for(Payment_Schedule__c updatep:trigger.new){
                regId.add(updatep.opportunity__c);
                if(regId.size()>0){
                mapReg=new Map<String,opportunity>([SELECT Id,Name,AccountId,Account.PersonContactId  FROM Opportunity]);
                  } 
                   if(updatep.Display_Order__c == 1.0 && updatep.Status__c == 'Completed'){
                   Existingcase =[select Subject,Type from case where Opportunity__c=:updatep.Opportunity__c and Subject='Agreement for Sale'];
                   if(Existingcase.size()==0){
                   Case Cs= new Case();
                   cs.Payment_Schedule__c=updatep.id;
                   cs.ownerid=updatep.id;
                   Cs.Subject='Agreement for Sale';
                   Cs.Type='Agreement for Sale'; 
                   cs.Opportunity__c=updatep.Opportunity__c;
                   system.debug('================== cs.Opportunity__c ===================='+cs.Opportunity__c);
                   cs.AccountId=mapReg.get(updatep.Opportunity__c).AccountId;
                   system.debug('============================cs.AccountId======================='+cs.AccountId);
                   cs.ContactId=mapReg.get(updatep.Opportunity__c).Account.PersonContactId ;
                   listC .add(Cs);
                    
                    }
                 }
              }
               Insert listC;
}
i want to assign cases one user to another user when case limit is more than 100 ...i mean  once user is having more than 100 cases  then another case will assign next User
trigger PaymentscheduleCases on Payment_Schedule__c (after update) 
{
    set<string> oppid=new set<string>();
    set<string> psidD=new set<string>();
    Map<id,opportunity> opp=new map<id,opportunity>();
    List<case> cse=new List<case>(); 
    List<Payment_Schedule__c> psListDemand=new List<Payment_Schedule__c>();
    Map<id,Payment_Schedule__c> lstPsD=new Map<id,Payment_Schedule__c>();
    
    if(checkRecursive.runDemand==True)
    {
        //checkRecursive.runDemand=false;
        if(trigger.oldMap.get(p.id).Demand_Note_Raised__c!=p.Demand_Note_Raised__c&& p.Demand_Note_Raised__c==true)
            {
                psidD.add(p.id);
                oppid.add(p.Opportunity__c);
            }
      }
        psListDemand=[SELECT Id,Name,Demand_Note_Raised__c,Opportunity__c FROM Payment_Schedule__c WHERE id=:psidD ];
         if(psidD.size()>0)
        {
            for(Opportunity o:[SELECT id,accountid,ownerid,Unit_Number1__c,CRM__c,account.PersonContactId,Project1__r.Minimum_Amount__c,(SELECT id,name FROM Payment_Schedules__r) FROM opportunity WHERE id=:oppid])
            {
                opp.put(o.id,o);
                 for(Payment_Schedule__c p1: psListDemand)
                {
                    lstPsD.put(p1.id,p1);
                }
            }
       for(Payment_Schedule__c p1: trigger.new)
            {
                if(trigger.oldMap.get(p1.id).Demand_Note_Raised__c!=p1.Demand_Note_Raised__c && p1.Demand_Note_Raised__c==true)
                {
                    Case cs= new Case();
                     if(opp.get(p1.Opportunity__c).Project1__r.Minimum_Amount__c != Null)
                    {
                       if(opp.get(p1.Opportunity__c).Project1__r.Minimum_Amount__c < p1.Amount_Pending__c)
                        {
                            cs.Payment_Schedule__c=p1.id;
                            if(opp.containskey(p1.Opportunity__c))
                            {
                                cs.AccountId=opp.get(p1.Opportunity__c).accountid;
                                cs.ContactId=opp.get(p1.Opportunity__c).account.PersonContactId;
                               if(opp.get(p1.Opportunity__c).CRM__c !=null)
                                {
                                    cs.ownerid=opp.get(p1.Opportunity__c).CRM__c;
                                }
                                else
                                {
                                    cs.ownerid=opp.get(p1.Opportunity__c).ownerid;
                                }
                             system.debug('++++++++++'+opp.get(p1.Opportunity__c).ownerid);
                            }
                             
          /*  if(P1.Status__c == 'Completed' && p1.Amount_Pending__c ==0){
            system.debug('----------------P1.Status__c-------'+P1.Status__c);
            cs.Status = 'Closed';
            system.debug('----------------P1.Status__c-------'+ cs.Status);
            cs.Origin = 'clsoed';
            system.debug('----------------P1.Status__c-------'+ cs.Origin);
            update cs;                                
                       
          }*/

                            cs.Subject= 'Unit Number('+opp.get(p1.Opportunity__c).Unit_Number1__c+') Amount Pending('+p1.Amount_Pending__c+') Due Date('+ system.today().day()+'/'+system.today().month()+'/'+system.today().year()+')';
                            cs.Opportunity__c=p1.Opportunity__c;
                            cs.Type='Payment Schedule';
                            cse.add(cs);
                        } 
                    }
                }
            }
        }
        if(cse.size()>0)
        {
          checkRecursive.runDemand=False;
            insert cse;
        }
    }
}

Now In Payment_Schedule__c  object when Status Picklist field is Completed and amount Pending Field is  '0' i want to close that case


How can i Achive this Trigger.

Please Reply Fast 
 
How To write test class to this class

@RestResource(urlMapping='/LeadMapping/*')
global with sharing class Rest_Lead_Insert {

@HttpPost  
  global static String CreateNewLead(String lastname, String status,String Call_duration, string Service_Number, string AgentPhone, string Ofc_Call_Status,string Ofc_Call_Time,string office_lead_id,string AgentName,string Recording_File_Path,Boolean Office24by7,string call_type){
     System.debug('lead Name: '+lastname);
     System.debug('lead Status: '+status);
     try
     {
         lead le                    =          new lead();
         le.lastname                =          lastname;
         le.Office_Number__c        =          Service_Number;
         le.Phone                   =          AgentPhone;
         le.Ofc_Call_duration__c    =          Call_duration;
         le.Ofc_Call_Type__c        =          call_type;
         le.Ofc_Call_Status__c      =          Ofc_Call_Status;
         le.Ofc_Call_Time__c        =          Ofc_Call_Time;
         le.office_lead_id__c       =          office_lead_id;
         le.AgentName__c            =          AgentName;
         le.Recording_File_Path__c  =          Recording_File_Path;
         le.Office24by7__c          =          Office24by7;
         le.status                  =          status;
         insert le;
         return 'lead has been inserted succesfully: '+le.Id;
     }
     catch(DMLException de)
     {
        return de.getDmlMessage(0);
     }
               
    // return null;
  }
}
I got Limit 50001 Exception so, i need to be clear through batch apex.so how can i call this class from batch apex 

    trigger LeadTrigger on Lead (before insert) {
    final String errMsg = ' Email already exists ';
    final String errMsg1 = 'Phone number already exists ';
    Map< String, Lead > duplicatePhoneLeadMap = new Map< String, Lead >();
    Map< String, Lead > duplicateEmailLeadMap = new Map< String, Lead >();
    for( Lead l : [select Id,Name, Email,Phone from Lead] ){
        if( l.Email!= null){
            duplicateEmailLeadMap.put(l.email,l);
        }
        if( l.Phone != null){
            duplicatePhoneLeadMap.put(l.Phone,l);
        }
    }
    for( Lead l : Trigger.new ){
        if(duplicateEmailLeadMap.containsKey(l.Email)){
            l.Email.addError(errMsg);
        }
        if(!duplicatePhoneLeadMap.isEmpty() && duplicatePhoneLeadMap.containsKey(l.Phone) && duplicatePhoneLeadMap.get(l.Phone)!=NULL ){
            l.Phone.addError(errMsg1);
        }
    }
}
public class OfficedataSync {

public List<officewrap> myd{get;set;}
public string searchStr {get; set;}
public string searchStrfrm {get; set;}

public void getperformcallout(){

myd = new List<officewrap>();


HttpRequest req = new HttpRequest();

HttpResponse res = new HttpResponse();

Http http = new Http();
String url='https://mail.google.com/mail/u/0/#inbox/FMfcgxvzLDrvZsWbCZhTnVxCtDRwNjNv'
req.setEndpoint(url);

req.setMethod('GET');

res = http.send(req);

if(res.getstatusCode() == 200 && res.getbody() != null){

try{
myd=(List<officewrap>)json.deserialize(res.getbody(),List<officewrap>.class);

list<Lead> ld= new list<Lead>();   
for (Integer i = 0; i < myd.size(); i++) {

ld = [select id from Lead where office_lead_id__c LIKE :myd[i].call_id+'%' ]; 
if(ld.size()==0){ 

Lead lstLead = new Lead();
lstLead.office_lead_id__c=myd[i].call_id;
lstLead.LastName=myd[i].phone_number;
insert lstLead;
}

}


}catch(Exception ex){

myd=null;

}
i want to assign cases one user to another user when case limit is more than 100 
I have one Multiselect picklist,this values are  1,2,3,4,5,6 and one check bok is also there.now if i am selecting  1,2 values and select the checkbox is true i want display two Empty Text Fields and if i am selecting  only one value in That picklist and select checkbox is true i want to display only one Empty Text Field How can i achieve this Requirement  Without Coding 
 
trigger PaymentscheduleCases on Payment_Schedule__c (after update) 
{
    set<string> oppid=new set<string>();
    set<string> psidD=new set<string>();
    Map<id,opportunity> opp=new map<id,opportunity>();
    List<case> cse=new List<case>(); 
    List<Payment_Schedule__c> psListDemand=new List<Payment_Schedule__c>();
    Map<id,Payment_Schedule__c> lstPsD=new Map<id,Payment_Schedule__c>();
    
    if(checkRecursive.runDemand==True)
    {
        //checkRecursive.runDemand=false;
        if(trigger.oldMap.get(p.id).Demand_Note_Raised__c!=p.Demand_Note_Raised__c&& p.Demand_Note_Raised__c==true)
            {
                psidD.add(p.id);
                oppid.add(p.Opportunity__c);
            }
      }
        psListDemand=[SELECT Id,Name,Demand_Note_Raised__c,Opportunity__c FROM Payment_Schedule__c WHERE id=:psidD ];
         if(psidD.size()>0)
        {
            for(Opportunity o:[SELECT id,accountid,ownerid,Unit_Number1__c,CRM__c,account.PersonContactId,Project1__r.Minimum_Amount__c,(SELECT id,name FROM Payment_Schedules__r) FROM opportunity WHERE id=:oppid])
            {
                opp.put(o.id,o);
                 for(Payment_Schedule__c p1: psListDemand)
                {
                    lstPsD.put(p1.id,p1);
                }
            }
       for(Payment_Schedule__c p1: trigger.new)
            {
                if(trigger.oldMap.get(p1.id).Demand_Note_Raised__c!=p1.Demand_Note_Raised__c && p1.Demand_Note_Raised__c==true)
                {
                    Case cs= new Case();
                     if(opp.get(p1.Opportunity__c).Project1__r.Minimum_Amount__c != Null)
                    {
                       if(opp.get(p1.Opportunity__c).Project1__r.Minimum_Amount__c < p1.Amount_Pending__c)
                        {
                            cs.Payment_Schedule__c=p1.id;
                            if(opp.containskey(p1.Opportunity__c))
                            {
                                cs.AccountId=opp.get(p1.Opportunity__c).accountid;
                                cs.ContactId=opp.get(p1.Opportunity__c).account.PersonContactId;
                               if(opp.get(p1.Opportunity__c).CRM__c !=null)
                                {
                                    cs.ownerid=opp.get(p1.Opportunity__c).CRM__c;
                                }
                                else
                                {
                                    cs.ownerid=opp.get(p1.Opportunity__c).ownerid;
                                }
                             system.debug('++++++++++'+opp.get(p1.Opportunity__c).ownerid);
                            }
                             
          /*  if(P1.Status__c == 'Completed' && p1.Amount_Pending__c ==0){
            system.debug('----------------P1.Status__c-------'+P1.Status__c);
            cs.Status = 'Closed';
            system.debug('----------------P1.Status__c-------'+ cs.Status);
            cs.Origin = 'clsoed';
            system.debug('----------------P1.Status__c-------'+ cs.Origin);
            update cs;                                
                       
          }*/

                            cs.Subject= 'Unit Number('+opp.get(p1.Opportunity__c).Unit_Number1__c+') Amount Pending('+p1.Amount_Pending__c+') Due Date('+ system.today().day()+'/'+system.today().month()+'/'+system.today().year()+')';
                            cs.Opportunity__c=p1.Opportunity__c;
                            cs.Type='Payment Schedule';
                            cse.add(cs);
                        } 
                    }
                }
            }
        }
        if(cse.size()>0)
        {
          checkRecursive.runDemand=False;
            insert cse;
        }
    }
}

Now In Payment_Schedule__c  object when Status Picklist field is Completed and amount Pending Field is  '0' i want to close that case


How can i Achive this Trigger.

Please Reply Fast 
 
How To write test class to this class

@RestResource(urlMapping='/LeadMapping/*')
global with sharing class Rest_Lead_Insert {

@HttpPost  
  global static String CreateNewLead(String lastname, String status,String Call_duration, string Service_Number, string AgentPhone, string Ofc_Call_Status,string Ofc_Call_Time,string office_lead_id,string AgentName,string Recording_File_Path,Boolean Office24by7,string call_type){
     System.debug('lead Name: '+lastname);
     System.debug('lead Status: '+status);
     try
     {
         lead le                    =          new lead();
         le.lastname                =          lastname;
         le.Office_Number__c        =          Service_Number;
         le.Phone                   =          AgentPhone;
         le.Ofc_Call_duration__c    =          Call_duration;
         le.Ofc_Call_Type__c        =          call_type;
         le.Ofc_Call_Status__c      =          Ofc_Call_Status;
         le.Ofc_Call_Time__c        =          Ofc_Call_Time;
         le.office_lead_id__c       =          office_lead_id;
         le.AgentName__c            =          AgentName;
         le.Recording_File_Path__c  =          Recording_File_Path;
         le.Office24by7__c          =          Office24by7;
         le.status                  =          status;
         insert le;
         return 'lead has been inserted succesfully: '+le.Id;
     }
     catch(DMLException de)
     {
        return de.getDmlMessage(0);
     }
               
    // return null;
  }
}
I got Limit 50001 Exception so, i need to be clear through batch apex.so how can i call this class from batch apex 

    trigger LeadTrigger on Lead (before insert) {
    final String errMsg = ' Email already exists ';
    final String errMsg1 = 'Phone number already exists ';
    Map< String, Lead > duplicatePhoneLeadMap = new Map< String, Lead >();
    Map< String, Lead > duplicateEmailLeadMap = new Map< String, Lead >();
    for( Lead l : [select Id,Name, Email,Phone from Lead] ){
        if( l.Email!= null){
            duplicateEmailLeadMap.put(l.email,l);
        }
        if( l.Phone != null){
            duplicatePhoneLeadMap.put(l.Phone,l);
        }
    }
    for( Lead l : Trigger.new ){
        if(duplicateEmailLeadMap.containsKey(l.Email)){
            l.Email.addError(errMsg);
        }
        if(!duplicatePhoneLeadMap.isEmpty() && duplicatePhoneLeadMap.containsKey(l.Phone) && duplicatePhoneLeadMap.get(l.Phone)!=NULL ){
            l.Phone.addError(errMsg1);
        }
    }
}
public class OfficedataSync {

public List<officewrap> myd{get;set;}
public string searchStr {get; set;}
public string searchStrfrm {get; set;}

public void getperformcallout(){

myd = new List<officewrap>();


HttpRequest req = new HttpRequest();

HttpResponse res = new HttpResponse();

Http http = new Http();
String url='https://mail.google.com/mail/u/0/#inbox/FMfcgxvzLDrvZsWbCZhTnVxCtDRwNjNv'
req.setEndpoint(url);

req.setMethod('GET');

res = http.send(req);

if(res.getstatusCode() == 200 && res.getbody() != null){

try{
myd=(List<officewrap>)json.deserialize(res.getbody(),List<officewrap>.class);

list<Lead> ld= new list<Lead>();   
for (Integer i = 0; i < myd.size(); i++) {

ld = [select id from Lead where office_lead_id__c LIKE :myd[i].call_id+'%' ]; 
if(ld.size()==0){ 

Lead lstLead = new Lead();
lstLead.office_lead_id__c=myd[i].call_id;
lstLead.LastName=myd[i].phone_number;
insert lstLead;
}

}


}catch(Exception ex){

myd=null;

}
i want to assign cases one user to another user when case limit is more than 100