• Manvendra Chaturvedi 26
  • NEWBIE
  • 150 Points
  • Member since 2018

  • Chatter
    Feed
  • 5
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 34
    Replies
Hi,
I need help in writing a test class for the following trigger. 
trigger CaseTrigger on Case (before insert,before update) 
{
    if((Trigger.isBefore && Trigger.isUpdate)||(Trigger.isBefore && Trigger.isInsert))
    {
        
           /*
   If the Entitlement Name is not set then, check to see if the Contact on the Case has an active Entitlement
    and select the first one.  If not then check to see if the Account on the Case has an active Entitlement.
   */
   List<Id> contactIds = new List<Id>();
   List<Id> acctIds = new List<Id>();
   for (Case c: Trigger.new){
      if (c.EntitlementId == null && c.ContactId!= null && c.AccountId!= null){
         contactIds.add(c.ContactId);
         acctIds.add(c.AccountId);
      }
   }
   if(contactIds.isEmpty()==false || acctIds.isEmpty()==false){
      /* Added check for active entitlement */
      List <EntitlementContact> entlContacts = [Select e.EntitlementId,e.ContactId,e.Entitlement.AssetId From EntitlementContact e
                                                Where e.ContactId in:contactIds
                                                And e.Entitlement.EndDate >= Today And e.Entitlement.StartDate <= Today];
      if(entlContacts.isEmpty()==false){
         for(Case c: Trigger.new){
            if(c.EntitlementId == null && c.ContactId!= null){
               for(EntitlementContact ec:entlContacts){
                  if(ec.ContactId==c.ContactId){
                     c.EntitlementId = ec.EntitlementId;
                     if(c.AssetId==null && ec.Entitlement.AssetId!=null)
                        c.AssetId=ec.Entitlement.AssetId;
                     break;
                  }
               } // end for
            }
         } // end for
      } else{
         List <Entitlement> entls = [Select e.StartDate, e.Id, e.EndDate, e.AccountId, e.AssetId
                                     From Entitlement e
                                     Where e.AccountId in:acctIds And e.EndDate >= Today And e.StartDate <= Today];
         if(entls.isEmpty()==false){
            for(Case c: Trigger.new){
               if(c.EntitlementId == null && c.AccountId!= null){
                  for(Entitlement e:entls){
                     if(e.AccountId==c.AccountId){
                        c.EntitlementId = e.Id;
                        if(c.AssetId==null && e.AssetId!=null)
                           c.AssetId=e.AssetId;
                        break;
                     }
                  } // end for
               }
            } // end for
         }
      }
   } // end if(contactIds.isEmpty()==false)
        
    }
    
    
 // [Based on assignment group selection change the case owner] 
   
	if(Trigger.isBefore && Trigger.isUpdate)
    {
        System.debug('entered if condition');
		
        for(Case c : Trigger.new)
		{
            if (c.Assignment_Group__c != trigger.oldMap.get(c.Id).Assignment_Group__c){
            System.debug('Updating logic');
       	    List<Group> qid = [select Id from Group where Name = : c.Assignment_Group__c and Type = 'Queue'];
              for(Group g : qid)
                {
                    c.OwnerId = g.id;
                    System.debug('updated');
                }
            }}        
    }
    
     if(Trigger.isBefore && Trigger.isUpdate)
    {
      for(Case c : Trigger.new)
		{   
			if(c.Assignment_Group__c=='Tech Support'||c.Assignment_Group__c=='GD-IT'||c.Assignment_Group__c=='App-Support'||c.Assignment_Group__c=='GD-RM'||c.Assignment_Group__c=='GD-DB'||c.Assignment_Group__c=='Dev-Ops'||c.Assignment_Group__c=='App-Management'||c.Assignment_Group__c=='PDT-DS-Engg'||c.Assignment_Group__c=='PDT-US-Engg')
            {
                c.Group_Manager_Email__c = 'sgaware1@gmail.com'; c.Escalation_Level_2_Email__c ='sgaware1@gmail.com'; c.Escalation_Level_3_Email__c='sgaware1@gmail.com';
            }
        }
    }
    
}

 
The current situation is like this:
When i click on the radiobutton it passes the corresponding accountId to the following function.
doUpdate: function(component,event){
        var action = component.get("c.doUpdate");
        action.setParams({req : 'test'});
        action.setCallback(this, function(response){ 
            var selectedRows = event.getParam('selectedRow');
            var navigateEvent = $A.get("e.force:editRecord");
            navigateEvent.setParams({ "recordId": selectedRow[0].Id  });
            navigateEvent.fire();
        });
         $A.enqueueAction(action);
    }

The code in the setCallback lets me popup the account edit screen successfully. The problem is that the popup loads the default recordtype layout. I am expecting the custom Lightning component to be loaded in the popup ( I could override the editbutton on customer page, but how to mimic this edit button click in code?).
 
User-added image

above scrren shot shows on left hand side portion i was selected some filds  then after right hand side i was not selected any selected filds on that time i run dynamic query using Query button so the thing is i need to if i was not selected any selected field on that time it will not thogh any error can it be possible ??
I am working on aq trigger which needs to count the child records.
I have two objects :
Contact and Relationships(API NAME- hed__Relationship__c), Relationships is having a lookup to contact with field name- "hed__Contact__c"
I have picklist field on Relationship object with API Name-"hed__Type__c" and if the values of the picklist are "Father" and "Mother"then I should count the relationship records that are assosited with the contact.

Can anyone helpme out in this please. Itried the below trigger but its not working on update and if I delete all the relationship records that are assosiated the the count is showing 1 where it should show 0.
Its working when I have two relationship records and when I delete 1 record count is becoming 1 but when I remove next one too then count is not becoming 0.
trigger UpdateOrder on hed__Relationship__c (after insert, after update, after delete, after undelete) {

   List<Contact> ct = new List<Contact>();
   
   Set<Id> custord = new Set<Id>();
   
   if(Trigger.isDelete) {
     for(hed__Relationship__c test:Trigger.Old) {
      
        custord.add(test.hed__Contact__c);   
    
     }   
   
   }
   else
   if(Trigger.isUpdate) {

     for(hed__Relationship__c test:Trigger.New) {
      
        custord.add(test.hed__Contact__c);  
    
     }

     for(hed__Relationship__c test:Trigger.Old) {
      
        custord.add(test.hed__Contact__c);   
    
     }   
   
   }
   else
   {
     for(hed__Relationship__c test:Trigger.New) {
      
        custord.add(test.hed__Contact__c);   
    
     }
   }
   
   AggregateResult[] groupedResults = [SELECT COUNT(Id), hed__Contact__c FROM hed__Relationship__c where hed__Type__c='Father || Mother' AND hed__Contact__c IN :custord GROUP BY hed__Contact__c ];
   
   for(AggregateResult ar:groupedResults) {
     
     Id custid = (ID)ar.get('hed__Contact__c');
     
     Integer count = (INTEGER)ar.get('expr0');
     
     Contact cust1 = new Contact(Id=custid);
     
     cust1.Number_Of_Dependents__c = count;
     
     ct.add(cust1);
      
   }
   
   
   update ct;

}

 
string queryStr1 = 'SELECT ID, NAME, createdBy.Name, createdDate, lastModifiedBy.Name, lastModifiedDate, '+fldAPINameMap.get(selectedField)+' FROM '+selectedObject+' WHERE '+fldAPINameMap.get(selectedField)+' like \'%'+criteria+'%\'';

the above Dynamic query  is working perfectly on single select feild but now i am having multiple fields to select then after run query according to selected fields so it is not working
 
Hello ,I was trying to push lightning web component from VS Code.I am using command "SFDX: Push Source to Default Scratch Org" ,but everytime i am getting error ,sfdx force:source:push PROJECT PATH  ERROR N/A Not available for deploy for this API version. 
Any suggestion will be highly appretiated .
Thanks in Advance
public class opportunityReportController {
    public List<opportunity> oppList { get; set; }
    public boolean Lost { get; set; }
    public boolean Won { get; set; }
    public boolean Open { get; set; }
    
    public opportunityReportController (){
    open=false;
    lost=false;
    won=false;
    }
    public void mytableData() {
    oppList =new List<opportunity>();
    list<opportunity> oppOpenList=[Select id,name,amount,stageName from opportunity where stageName NOT IN('Closed Won','Closed Lost')];
    list<opportunity> oppWonList=[Select id,name,amount,stageName from opportunity where stageName ='Closed Won'];
    list<opportunity> oppLostList=[Select id,name,amount,stageName from opportunity where stageName ='Closed Lost'];
    
    system.debug('>>>>>i am here>>');
    if(open==true && Won==false && Lost==False){
        oppList.addall(oppOpenList);
    }
    else if(open==true && Won==true && Lost==False){
        oppList.addall(oppOpenList);
        oppList.addall(oppWonList);
    }
   else if(open==true && Won==true && Lost==true){
        oppList.addall(oppOpenList);
        oppList.addall(oppWonList);
        oppList.addall(oppLostList);
    }
    else if(open==false && Won==true && Lost==false){
        oppList.addall(oppWonList);
    }
    else if(open==false && Won==true && Lost==true){
        oppList.addall(oppWonList);
        oppList.addall(oppLostList);
    }
    else if(open==false && Won==false && Lost==true){
        oppList.addall(oppLostList);
    }
    else if(open==true && Won==false && Lost==true){
        oppList.addall(oppLostList);
        oppList.addall(oppOpenList);
    }
    
    }

    
}
  • January 31, 2019
  • Like
  • 0
Hi,
I need help in writing a test class for the following trigger. 
trigger CaseTrigger on Case (before insert,before update) 
{
    if((Trigger.isBefore && Trigger.isUpdate)||(Trigger.isBefore && Trigger.isInsert))
    {
        
           /*
   If the Entitlement Name is not set then, check to see if the Contact on the Case has an active Entitlement
    and select the first one.  If not then check to see if the Account on the Case has an active Entitlement.
   */
   List<Id> contactIds = new List<Id>();
   List<Id> acctIds = new List<Id>();
   for (Case c: Trigger.new){
      if (c.EntitlementId == null && c.ContactId!= null && c.AccountId!= null){
         contactIds.add(c.ContactId);
         acctIds.add(c.AccountId);
      }
   }
   if(contactIds.isEmpty()==false || acctIds.isEmpty()==false){
      /* Added check for active entitlement */
      List <EntitlementContact> entlContacts = [Select e.EntitlementId,e.ContactId,e.Entitlement.AssetId From EntitlementContact e
                                                Where e.ContactId in:contactIds
                                                And e.Entitlement.EndDate >= Today And e.Entitlement.StartDate <= Today];
      if(entlContacts.isEmpty()==false){
         for(Case c: Trigger.new){
            if(c.EntitlementId == null && c.ContactId!= null){
               for(EntitlementContact ec:entlContacts){
                  if(ec.ContactId==c.ContactId){
                     c.EntitlementId = ec.EntitlementId;
                     if(c.AssetId==null && ec.Entitlement.AssetId!=null)
                        c.AssetId=ec.Entitlement.AssetId;
                     break;
                  }
               } // end for
            }
         } // end for
      } else{
         List <Entitlement> entls = [Select e.StartDate, e.Id, e.EndDate, e.AccountId, e.AssetId
                                     From Entitlement e
                                     Where e.AccountId in:acctIds And e.EndDate >= Today And e.StartDate <= Today];
         if(entls.isEmpty()==false){
            for(Case c: Trigger.new){
               if(c.EntitlementId == null && c.AccountId!= null){
                  for(Entitlement e:entls){
                     if(e.AccountId==c.AccountId){
                        c.EntitlementId = e.Id;
                        if(c.AssetId==null && e.AssetId!=null)
                           c.AssetId=e.AssetId;
                        break;
                     }
                  } // end for
               }
            } // end for
         }
      }
   } // end if(contactIds.isEmpty()==false)
        
    }
    
    
 // [Based on assignment group selection change the case owner] 
   
	if(Trigger.isBefore && Trigger.isUpdate)
    {
        System.debug('entered if condition');
		
        for(Case c : Trigger.new)
		{
            if (c.Assignment_Group__c != trigger.oldMap.get(c.Id).Assignment_Group__c){
            System.debug('Updating logic');
       	    List<Group> qid = [select Id from Group where Name = : c.Assignment_Group__c and Type = 'Queue'];
              for(Group g : qid)
                {
                    c.OwnerId = g.id;
                    System.debug('updated');
                }
            }}        
    }
    
     if(Trigger.isBefore && Trigger.isUpdate)
    {
      for(Case c : Trigger.new)
		{   
			if(c.Assignment_Group__c=='Tech Support'||c.Assignment_Group__c=='GD-IT'||c.Assignment_Group__c=='App-Support'||c.Assignment_Group__c=='GD-RM'||c.Assignment_Group__c=='GD-DB'||c.Assignment_Group__c=='Dev-Ops'||c.Assignment_Group__c=='App-Management'||c.Assignment_Group__c=='PDT-DS-Engg'||c.Assignment_Group__c=='PDT-US-Engg')
            {
                c.Group_Manager_Email__c = 'sgaware1@gmail.com'; c.Escalation_Level_2_Email__c ='sgaware1@gmail.com'; c.Escalation_Level_3_Email__c='sgaware1@gmail.com';
            }
        }
    }
    
}

 
The current situation is like this:
When i click on the radiobutton it passes the corresponding accountId to the following function.
doUpdate: function(component,event){
        var action = component.get("c.doUpdate");
        action.setParams({req : 'test'});
        action.setCallback(this, function(response){ 
            var selectedRows = event.getParam('selectedRow');
            var navigateEvent = $A.get("e.force:editRecord");
            navigateEvent.setParams({ "recordId": selectedRow[0].Id  });
            navigateEvent.fire();
        });
         $A.enqueueAction(action);
    }

The code in the setCallback lets me popup the account edit screen successfully. The problem is that the popup loads the default recordtype layout. I am expecting the custom Lightning component to be loaded in the popup ( I could override the editbutton on customer page, but how to mimic this edit button click in code?).
 
Hi All,
         i have a batch on Account to Calculate Quality score. with a scoring system . like if the fields has values than give a particular score to the field According to  specific record type. and after calculation the result is shown in Quality score.
My batch is given below:-
 public without sharing class BatchCADUtilization implements Database.Batchable<sObject>{
    
    public Map<String, Map<String, Integer>> mapRecordTypeToScores = new Map<String, Map<String, Integer>> {
        
        'Cachet' => new Map<String, Integer> {
                        'ACH_Provider__c' => 5,
                        'Payroll_Software__c' => 3, 
                        'HR_Software__c' => 3,
                        'Payroll_Tax_Processor__c' => 3,
                        'Current_Bank__c' =>  3,
                        'Payroll_Business_Consultant__c' => 2,
                        'Time_Attendance__c' => 2,
                        'CPA_Accounting_Firm__c' => 2
                     },
       'TimeRack' =>  new Map<String, Integer> {
                        'Time_Attendance__c' => 5,
                        'CPA_Accounting_Firm__c' => 3,
                        'Payroll_Software__c' => 3,
                        'Current_Bank__c' =>  3,    
                        'HR_Software__c' => 3,
                        'Payroll_Business_Consultant__c' => 2,
                        'ACH_Provider__c' => 2,
                        'Payroll_Tax_Processor__c' => 2
                      },          
       'PTM' => new Map<String, Integer> {
                        'Payroll_Tax_Processor__c' => 5,
                        'ACH_Provider__c' => 3,
                        'Payroll_Software__c' => 3,
                        'Current_Bank__c' =>  3,
                        'Payroll_Business_Consultant__c' => 2,
                        'Time_Attendance__c' => 2,
                        'HR_Software__c' => 2,
                        'CPA_Accounting_Firm__c' => 2
                    },
       'SBS' => new Map<String, Integer> {
                        'Payroll_Software__c' => 5,
                        'ACH_Provider__c' => 3,
                        'Payroll_Tax_Processor__c' => 3,
                        'Current_Bank__c' =>  3,
                        'Time_Attendance__c' => 3,
                        'Payroll_Business_Consultant__c' => 2,
                        'HR_Software__c' => 2,
                        'CPA_Accounting_Firm__c' => 2
                    }               
    };
        
    public static void run( Set<Id> AccIds ) {
        List<Account> accountRecords =  [Select id, RecordTypeId, RecordType.Name, ACH_Provider__c,
                                         RecordType.developerName, Payroll_Software__c, HR_Software__c,
                                         Payroll_Tax_Processor__c, Current_Bank__c, Payroll_Business_Consultant__c,
                                         Time_Attendance__c, CPA_Accounting_Firm__c,Quality_Score__c
                                         from Account
                                         where Id IN:  AccIds ];
        //executeHelper( accountRecords );                  
    }
    
    public Database.querylocator start(Database.BatchableContext BC){
        String query = 'Select id, RecordTypeId, RecordType.Name, ACH_Provider__c, ' +
            'RecordType.developerName, Payroll_Software__c, HR_Software__c, ' + 
            'Payroll_Tax_Processor__c, Current_Bank__c, ' +
            'Payroll_Business_Consultant__c,Quality_Score__c, ' + 
            'Time_Attendance__c, CPA_Accounting_Firm__c ' +
            'FROM Account' ;
        return Database.getQueryLocator(query);
    }
    
    public void execute(Database.BatchableContext BC, List<Account> scope){
        List<Account> accListToUpdate = new List<Account>();
        
        for(Account acc : scope) {
           
            Integer totalScoreAchieved = 0;
            Integer totalScorePossible = 0;
            
            String recordTypeDeveloperName = acc.RecordType.developerName;
            if( recordTypeDeveloperName != null ) {
                Map<String, Integer> mapFieldAPINameToScore = mapRecordTypeToScores.get( recordTypeDeveloperName );
                totalScoreAchieved = 0;
                if( mapFieldAPINameToScore != null ) {
                    
                    for( String fieldAPIName : mapFieldAPINameToScore.keySet() ) {
                        Object fieldValue = acc.get( fieldAPIName );
                        Integer scoreForTheField = mapFieldAPINameToScore.get( fieldAPIName );
                        totalScorePossible += scoreForTheField;
                        if( fieldValue != null && String.valueOf( fieldValue ) != 'Other' ) {
                            totalScoreAchieved += scoreForTheField;

                        }
                    }
                }

                if( totalScorePossible > 0 ) {
                    acc.Quality_Score__c = (totalScoreAchieved * 100)/totalScorePossible;   
                }
            }
              System.assert(false,acc.Quality_Score__c);
  }
        update accListToUpdate;
    }
        
    public void finish(Database.BatchableContext BC){
      
    }
}
Its giving me no value in the Quality score field?
Any suugestions how to solve it?
I am trying to convert one Visualforce page to a lightning component. Kindly sugget best way in which this can be done for the below code.

<apex:page id="poac" standardController="MyCustomObject__c" tabStyle="MyCustomObject__c">
<apex:sectionHeader title="Message" subtitle="{!MyCustomObject__c.Name}"/>
<div id="poac_content">
<h3>Please Wait.. Processing {!MyCustomObject__c.Name}</h3>
<img class="waitingImage" src="/img/loading.gif" title="Please Wait.. Processing {!MyCustomObject__c.Name}"/>
</div> <script src="/soap/ajax/22.0/connection.js" type="text/javascript">
</script>
<script src="/soap/ajax/22.0/apex.js" type="text/javascript">
</script>
<script type="text/javascript">
sforce.connection.sessionId = "{!$Api.Session_ID}";
//var returnPath = "/{!MyCustomObject__c.id}";
var poaId = "{!MyCustomObject__c.Id}";
var result = sforce.apex.execute( "COE_Alignment_Request_Handler",
                                                      "processRequest",
                                                       {selectedID:poaId,bAdd:"FALSE"} );
if(result == 'true') {
window.location.href= "/apex/RecordRemoved"; }
else
{ var errorDisplayPanel= document.getElementById("poac_content");
errorDisplayPanel.innerHTML("<h2><b>"+result+"</b></h2>"+
                                                                      "<br/><br/><a href='"+returnPath+"'> Click Here</a> to return" ); }
</script>
</apex:page>
  • January 07, 2019
  • Like
  • 0
User-added image

above scrren shot shows on left hand side portion i was selected some filds  then after right hand side i was not selected any selected filds on that time i run dynamic query using Query button so the thing is i need to if i was not selected any selected field on that time it will not thogh any error can it be possible ??
Hi,

Good Day!

How should i assign today date to 'Actual_start_date__c', When Start Project(Custom button) is clicked. The javascript code for the custom button is given below. 
 
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 

// identify the record 
var o = new sforce.SObject("Project__c"); 
o.id = "{!Project__c.Id}"; 

// Update the Record Type 
o.RecordTypeId = '01210000000FCJwAAO'; 
o.Status__c = 'Active';
o.Actual_start_date__c = {!TODAY()};

// save the change 
//sforce.connection.update(o); 
var result = sforce.connection.update([o]); 

//refresh the page 
//window.location.reload(); 

if( result[0].success === "true" ) { 
window.location.reload(); 
} 
else { 
alert( result[0].errors.message ); 
}


Thanks in advance,
Durairaj
I am working on aq trigger which needs to count the child records.
I have two objects :
Contact and Relationships(API NAME- hed__Relationship__c), Relationships is having a lookup to contact with field name- "hed__Contact__c"
I have picklist field on Relationship object with API Name-"hed__Type__c" and if the values of the picklist are "Father" and "Mother"then I should count the relationship records that are assosited with the contact.

Can anyone helpme out in this please. Itried the below trigger but its not working on update and if I delete all the relationship records that are assosiated the the count is showing 1 where it should show 0.
Its working when I have two relationship records and when I delete 1 record count is becoming 1 but when I remove next one too then count is not becoming 0.
trigger UpdateOrder on hed__Relationship__c (after insert, after update, after delete, after undelete) {

   List<Contact> ct = new List<Contact>();
   
   Set<Id> custord = new Set<Id>();
   
   if(Trigger.isDelete) {
     for(hed__Relationship__c test:Trigger.Old) {
      
        custord.add(test.hed__Contact__c);   
    
     }   
   
   }
   else
   if(Trigger.isUpdate) {

     for(hed__Relationship__c test:Trigger.New) {
      
        custord.add(test.hed__Contact__c);  
    
     }

     for(hed__Relationship__c test:Trigger.Old) {
      
        custord.add(test.hed__Contact__c);   
    
     }   
   
   }
   else
   {
     for(hed__Relationship__c test:Trigger.New) {
      
        custord.add(test.hed__Contact__c);   
    
     }
   }
   
   AggregateResult[] groupedResults = [SELECT COUNT(Id), hed__Contact__c FROM hed__Relationship__c where hed__Type__c='Father || Mother' AND hed__Contact__c IN :custord GROUP BY hed__Contact__c ];
   
   for(AggregateResult ar:groupedResults) {
     
     Id custid = (ID)ar.get('hed__Contact__c');
     
     Integer count = (INTEGER)ar.get('expr0');
     
     Contact cust1 = new Contact(Id=custid);
     
     cust1.Number_Of_Dependents__c = count;
     
     ct.add(cust1);
      
   }
   
   
   update ct;

}

 
Hello,

I have needed to write onblur event of div which is desingned to have a background image But this is not working.If some one have implemented this functionality then please share me.
Hello ,I was trying to push lightning web component from VS Code.I am using command "SFDX: Push Source to Default Scratch Org" ,but everytime i am getting error ,sfdx force:source:push PROJECT PATH  ERROR N/A Not available for deploy for this API version. 
Any suggestion will be highly appretiated .
Thanks in Advance
string queryStr1 = 'SELECT ID, NAME, createdBy.Name, createdDate, lastModifiedBy.Name, lastModifiedDate, '+fldAPINameMap.get(selectedField)+' FROM '+selectedObject+' WHERE '+fldAPINameMap.get(selectedField)+' like \'%'+criteria+'%\'';

the above Dynamic query  is working perfectly on single select feild but now i am having multiple fields to select then after run query according to selected fields so it is not working