• sfdc_beginner7
  • NEWBIE
  • 25 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 19
    Questions
  • 14
    Replies
I am new to test classes. My Test class is giving only 36% coverage.What else i  can check in my test class

Test class:

@isTest
public class ITOVC_TargetMasterGovernanceClassTest {
    @TestSetup
    static void setup(){
        ITOVC_Target__c target1 = new ITOVC_Target__c(Name='TG01',Start_Date__c=Datetime.newInstance(2018, 01, 01), End_Date__c=Datetime.newInstance(2018, 01, 31),Target_Value__c=1);
        insert target1;
    }
  @isTest  static void testDuplicateRecordsForSameStartEndDate(){
        ITOVC_Target__c target2 = new ITOVC_Target__c(Name='TG01',Start_Date__c=Datetime.newInstance(2018, 01, 01), End_Date__c=Datetime.newInstance(2018, 01, 31),Target_Value__c=1);
        try {
           insert target2;
       } catch (Exception e) { 
           System.debug('An error happened, as predicted!');
       }
    }
}
apex class:

public class ITOVC_TargetMasterGovernanceClass {
    public void DuplicateRecordsForSameStartEndDate(List<ITOVC_Target__c> newTgId){
        List<ITOVC_Target__c> TgList = ([Select Name,Target_Value__c,Start_date__c,End_date__c from ITOVC_Target__c limit 10000]);
        for(ITOVC_Target__c tg : TgList){
            system.debug('ITOVC_Target__c tg :  ' + tg);
            for(ITOVC_Target__c newTg : newTgId ){
                system.debug('ITOVC_Target__c newtg :  ' + newtg);
                if(tg.Start_Date__c !=Null || tg.End_Date__c !=Null){
                    if( 
                        ((newTg.End_Date__c >= tg.Start_Date__c && newTg.End_Date__c <= tg.End_Date__c) ||
                        (newTg.Start_Date__c >= tg.Start_Date__c && newTg.End_Date__c <= tg.End_Date__c)||
                        (newTg.Start_Date__c >= tg.Start_Date__c && newTg.Start_Date__c <= tg.End_Date__c)||
                        (newTg.Start_Date__c < tg.Start_Date__c && newTg.End_Date__c > tg.End_Date__c))&&
                        (newTg.Name >= tg.Name)&&
                              (newTg.Target_Value__c >= tg.Target_Value__c)
                      ){

                              newTg.addError('Start date and End date are getting overlapped with existing records.');

                       }
                 }
            }
     }
    }
    public void recordsCantBeDeleted(List<ITOVC_Target__c> oldTgId){

        for(ITOVC_Target__c TgDel : oldTgId){

            TgDel.addError('You can\'t delete master target record');
        }
    }
}
apex trigger:

trigger ITOVC_TargetMasterGovernanceTrigger on ITOVC_Target__c (before insert,before update, before delete) {
     ITOVC_TargetMasterGovernanceClass thClass = new ITOVC_TargetMasterGovernanceClass();
    if(trigger.isInsert || Trigger.isUpdate){
        system.debug('Trigger.new contains :   '+Trigger.new);
        thClass.DuplicateRecordsForSameStartEndDate(Trigger.new);
    }
   if(Trigger.isDelete)
    {
        thClass.recordsCantBeDeleted(Trigger.old);
        system.debug('Trigger.old contains :   '+Trigger.old);
    }

}
 
I have 6 lookup fields on Case. If the user populates 1 lookup field, then on the other 5 lookup fields I want to show values related to the one which is populated.
I have many to many relationship between the objects.
Ex Position and website are 2 custom objects which have many to many relationship.
PO1 WB1
PO1 WB2
PO2 WB2
PO3 WB3
PO4 WB3
These can be the scenarios on the association object between Position and Website if user populate website look up field with value= WB3  if user click on position lookup field user should see PO3 and PO4 in suggestions
and also it can be vice versa ex if user enters Position=PO1 then  if user click on website lookup field user should see WB1 and WB2 in suggestions
Lookup filters and validations rules  are not possible because there is many to many relationship and also it will not auto suggest the related values.
Is there any lightning component that can auto suggest values on click of lookup field?
I need to create manual cases where 'case type' is 'Manual' I have 6 lookup fields on Case as Lookup_MTO (object is MTO) Lookup_Re (object is Re) Lookup_ToP (object is ToP) Lookup_Bk (object is Bk) Lookup_To (object is To) Lookup_Ld (object is Ld) My requirement is If Lookup_To is populated by User on the New case UI, only Lookup_MTO related to that Lookup_To should appear as available options on Lookup_To field. Same with Lookup_Re , Lookup_ToP , Lookup_Bk and Lookup_Ld. Likewise user can populate any lookup filed not only Lookup_To ,in any case rest of the lookups should come up with values related to that Lookup field populated by user. Relationship between objects is : Re(child) is having Lookup to MTO(parent) To,ToP,Bk,Ld is having many to many relationship with MTO Bk is child to ToP (look up relationship) To is a child to ToP (look up relationship) How can we achieve this ?
My requirement is to show all the cases related to parent object 'MTO' on case except the one case which is open .Ex there are 5 cases on MTO if I open 1 case then I should see other 4 cases on case related list. I have created lightning component .But the look and feel is not like related list .
Currently my lightning component is looking like this 
User-added image
also the view all button is not clickable .How can I show sandard view all button functionality?
But I want it to be look like this 
User-added image
 
I have a parent object 'MTO' for ex 1 MTO is having 5 cases My requirement is : If i open a case in MTO ,then in that case details page in related list tab I should see other 4 cases.
can we  use  a data table from the lightning design system along with an aura:if to loop through a list of related cases and display them in the table.?
 
I have a custom object 'Object1' which is having 5 cases related to it .My requirement is if I open 1 case out of 5 then in that 1 case in related list I can see other 4 cases.
How can i implement it?

There are 2 object parent and child having look up relationship between them .I need count of child object on parent but only few times.(not always)
Instead of creating childcount field on parent using trigger is there any other way ?
because we have huge data and having triggers will be complex for us.

I have a custom child object "Child__c" which is having a "Leg__c" field of type number(2,0), "Child__c" is related to parent object "Parent__c" through look up relationship.
Ex : "Parent__c" is having 6 "Child__c" with following leg
Child001    1
Child002    6
Child003    5
Child004    4
Child005    7
Child006    3
There is a field "Max_Leg__c" on "parent__c" .I need to find the max value of "Leg__c" from child object so that means my  
Max_Leg__c should be 7 on parent object.
Can we achieve it using configuration?
 
Can we create a component that is similar to standard related list component and add collapse feature 
for ex we have contact and opportonity related list on account related tab but we cant collapse 
Can we do it using lightning component 
lightning:accordian can be used ??
If the record is active for a date range (Say 1-Jan-2018 to 31-Jan-2018)  and Todays date is 16th Jan 2018.  Users should not be able to edit the records for 01-Jan-2018 to 16-Jan-2018.  They have to change End date to 16th Jan 2018 and start a new record 

can we implememt it using validation rule?
If the record is active for a date range (Say 1-Jan-2018 to 31-Jan-2018)  and Todays date is 16th Jan 2018.  Users should not be able to edit the records for 01-Jan-2018 to 16-Jan-2018.  They have to change End date to 16th Jan 2018 and start a new record with new values  which for 17-Jan-2018 to 31-Jan-2018.  
I have custom master object "A"  with related list "R1" ,"R2", "R3" there is a record in object A with name="2018"and object R1,R2,R3 have look up to A while i am searching for 2018 in global search ,search results  returning only object A but not related list 
For example while seraching for Account "University of Arizona" in global search it is returning related conatcts ,opportunities but this is not the case with my custom objects.
User-added image
I have written vf page  to display related list in case of one to many relationship .But I am facing problems in case of many to many relationship.
I can't use apex:relatedList in case of many to many relationship
I used apex:pageBlockTable  and apex:column to display related list but the the issue is that  filed is displayed as TEXT .
I want the on click functionality so that on click of field i can open the record i.e as in standard functionality

VF page
<apex:page standardController="Master1" lightningStylesheets="true" >
    <apex:pageBlock title="Master 1 Detail">
        <apex:pageBlockSection title="Master1  :{!Master1.Name}  ">
            <apex:detail relatedList="false"/>
        </apex:pageBlockSection>
        <apex:pageBlockSection collapsible="true" title="Related List 1">
           <apex:relatedList list="Related List 1"/> 
        </apex:pageBlockSection>

        <apex:pageBlockSection collapsible="true" title="Master2">
           <apex:pageBlockTable value="{!Master1.Junction_object__r}" var="b" >
           <apex:column value="{!b.Master2.__r.Name}"/>
           </apex:pageBlockTable> 
             </apex:pageBlockSection>  
    </apex:pageBlock>   
</apex:page>

what can be done in order to syandard related list functionality ?
Hi ,I have 2 objects "Positions" and "Employment Websites" having many to many relationship between them with "Job Posting" as a junction object.
->I have a case "C1" on "Position" 
->Position "P1" is posted to 3 Employement Websites "W1" ,"W2" and "W3"
->My requirement is to show case "C1" on Employement Website "W1" ,"W2" and "W3"

I have written a trigger for the above requirement but i am stuck
Objects :
Position
Employment Websites
Job Posting (Junction object for Position and Employement Websites)
CaseRelatedList( junction object between case and employement websites)
case (look up to Position)
I am trying to copy case related list from Position to Employment Websites .
Trigger :
trigger CloneCaseRelatedList on Case (after insert) {
    set<string> posId = new set<string>();
    Map<string,Job_Posting__c> posEmpWebsite = new Map<String,Job_Posting__c>();
    if(Trigger.isInsert)
    {
        for(Case c : Trigger.new)
        {
            posId.add(c.Position__c);
                system.debug(posId);
        }
        
    }
    for(Job_Posting__c j : [Select Position__c ,Employment_Website__c from Job_Posting__c where Position__c in : posId ])
    {
        posEmpWebsite.put(j.Position__c, j);
        system.debug(posEmpWebsite);
    }
    //I am stuck at this point How I can loop through all employmemt websites that position have
        
    }
1.I have created CaseRelatedList as a junction object for Employement Website and Case
2.Created trigger on case and from there I am getting positions
3.finding employemnt websites related to position through junction object 'Job Posting'
4.Need to loop through result of step 3. 
How can I loop through it so that I can insert case and employment website on junction object caseRelatedList.
Thanks in advance!!
Hi ,I have 2 objects "Positions" and "Employment Websites" having many to many relationship between them with "Job Posting" as a junction object.
->I have a case "C1" on "Position" 
->Position "P1" is posted to 3 Employement Websites "W1" ,"W2" and "W3"
->My requirement is to show case "C1" on Employement Website "W1" ,"W2" and "W3"
How can we acheive the above requirement?
Is it possible to collapse related list on an object or limiting it to 1 or 2 records per related list ?
There is a custom object Designation which have 3 fields :
Employee_Designation (text) ,
Account_Name(look up to account),
Contact_Name(look up to contact)
I want to do  a duplicate check so that value in all the 3 field should be different.
Eg : Suppose there is an existing record in Designation
  Employee_Designation=Test Lead and Account_Name=Universal containers and Conatct_Name=Daniel Philz
i dont want any new or updated record to have same values in all 3 fields
If i go for duplicate management rule ,then the matching rule wont allow 2 look up fields.
How it can be done?
 
I have a below requirement  ,Need to create a custom object "Custom A"  which will have 2 look fields Account Name and Contact Name
.I need to create a vf page such that if I click on account name it shows me 10 records and a search box that
let me search account by putting 3 alphabets and same funcationality in contact name but it should search contact only related  to selected
account.

I have created a basic code .
Apex class
public class create_employee_mv {
    public List<String> listofAccountName {get;set;}
    public List<String> listofContactFirstName {get;set;}
    public Set<Id> AccId;
    public create_employee_mv(ApexPages.StandardController stdcntrl)
    {
        listofAccountName = new List<String>();
        Accid = new Set<Id>();
        for(Account a : [Select Id, Name,(select Employee_Designation__c from Employee_MVs__r)
                         from Account])
        {
         listofAccountName.add(a.name);
         Accid.add(a.id);
        }
        
        
    }

}

VF page
<apex:page standardController="Employee_MV__c" extensions="create_employee_mv" docType="html-5.0">
    <apex:form>
        
        <apex:inputText list="{!listofAccountName}"  /> &nbsp;
        <apex:inputField value="{!Contact_Name__c}"/>
        
    </apex:form>
</apex:page>



 
trigger prevent_duplicate_account on Account (before insert) {
    map<id,Account> mapAcc = new map<id,Account>([Select id,name,rating from Account ]);
    for(Account a : Trigger.new)
    {
        if(a.Name==mapAcc.get(a.id).name && a.rating==mapAcc.get(a.id).rating)
            a.adderror('you cant add duplicate account');
    }

}
I have already an account with name as IGA ,i am updating this account with rating =warm ,it is preventing to save record .since I have used && condition ,if both are true then only it should save the record to save . Also If i am creating a record with name as IGA and rating different from the previous one than also I am getting error .What can be done please help
Thanks in advance!!
My requirement is to show all the cases related to parent object 'MTO' on case except the one case which is open .Ex there are 5 cases on MTO if I open 1 case then I should see other 4 cases on case related list. I have created lightning component .But the look and feel is not like related list .
Currently my lightning component is looking like this 
User-added image
also the view all button is not clickable .How can I show sandard view all button functionality?
But I want it to be look like this 
User-added image
 
I have a custom object 'Object1' which is having 5 cases related to it .My requirement is if I open 1 case out of 5 then in that 1 case in related list I can see other 4 cases.
How can i implement it?
I have a custom child object "Child__c" which is having a "Leg__c" field of type number(2,0), "Child__c" is related to parent object "Parent__c" through look up relationship.
Ex : "Parent__c" is having 6 "Child__c" with following leg
Child001    1
Child002    6
Child003    5
Child004    4
Child005    7
Child006    3
There is a field "Max_Leg__c" on "parent__c" .I need to find the max value of "Leg__c" from child object so that means my  
Max_Leg__c should be 7 on parent object.
Can we achieve it using configuration?
 
Hi ,I have 2 objects "Positions" and "Employment Websites" having many to many relationship between them with "Job Posting" as a junction object.
->I have a case "C1" on "Position" 
->Position "P1" is posted to 3 Employement Websites "W1" ,"W2" and "W3"
->My requirement is to show case "C1" on Employement Website "W1" ,"W2" and "W3"

I have written a trigger for the above requirement but i am stuck
Objects :
Position
Employment Websites
Job Posting (Junction object for Position and Employement Websites)
CaseRelatedList( junction object between case and employement websites)
case (look up to Position)
I am trying to copy case related list from Position to Employment Websites .
Trigger :
trigger CloneCaseRelatedList on Case (after insert) {
    set<string> posId = new set<string>();
    Map<string,Job_Posting__c> posEmpWebsite = new Map<String,Job_Posting__c>();
    if(Trigger.isInsert)
    {
        for(Case c : Trigger.new)
        {
            posId.add(c.Position__c);
                system.debug(posId);
        }
        
    }
    for(Job_Posting__c j : [Select Position__c ,Employment_Website__c from Job_Posting__c where Position__c in : posId ])
    {
        posEmpWebsite.put(j.Position__c, j);
        system.debug(posEmpWebsite);
    }
    //I am stuck at this point How I can loop through all employmemt websites that position have
        
    }
1.I have created CaseRelatedList as a junction object for Employement Website and Case
2.Created trigger on case and from there I am getting positions
3.finding employemnt websites related to position through junction object 'Job Posting'
4.Need to loop through result of step 3. 
How can I loop through it so that I can insert case and employment website on junction object caseRelatedList.
Thanks in advance!!
Hi ,I have 2 objects "Positions" and "Employment Websites" having many to many relationship between them with "Job Posting" as a junction object.
->I have a case "C1" on "Position" 
->Position "P1" is posted to 3 Employement Websites "W1" ,"W2" and "W3"
->My requirement is to show case "C1" on Employement Website "W1" ,"W2" and "W3"
How can we acheive the above requirement?
Is it possible to collapse related list on an object or limiting it to 1 or 2 records per related list ?
I have a below requirement  ,Need to create a custom object "Custom A"  which will have 2 look fields Account Name and Contact Name
.I need to create a vf page such that if I click on account name it shows me 10 records and a search box that
let me search account by putting 3 alphabets and same funcationality in contact name but it should search contact only related  to selected
account.

I have created a basic code .
Apex class
public class create_employee_mv {
    public List<String> listofAccountName {get;set;}
    public List<String> listofContactFirstName {get;set;}
    public Set<Id> AccId;
    public create_employee_mv(ApexPages.StandardController stdcntrl)
    {
        listofAccountName = new List<String>();
        Accid = new Set<Id>();
        for(Account a : [Select Id, Name,(select Employee_Designation__c from Employee_MVs__r)
                         from Account])
        {
         listofAccountName.add(a.name);
         Accid.add(a.id);
        }
        
        
    }

}

VF page
<apex:page standardController="Employee_MV__c" extensions="create_employee_mv" docType="html-5.0">
    <apex:form>
        
        <apex:inputText list="{!listofAccountName}"  /> &nbsp;
        <apex:inputField value="{!Contact_Name__c}"/>
        
    </apex:form>
</apex:page>



 
trigger prevent_duplicate_account on Account (before insert) {
    map<id,Account> mapAcc = new map<id,Account>([Select id,name,rating from Account ]);
    for(Account a : Trigger.new)
    {
        if(a.Name==mapAcc.get(a.id).name && a.rating==mapAcc.get(a.id).rating)
            a.adderror('you cant add duplicate account');
    }

}
I have already an account with name as IGA ,i am updating this account with rating =warm ,it is preventing to save record .since I have used && condition ,if both are true then only it should save the record to save . Also If i am creating a record with name as IGA and rating different from the previous one than also I am getting error .What can be done please help
Thanks in advance!!
Hi Experts,

i have little confuse ,Why we are using test.start and test stop test methods in test class to batch apex ? Any one can demonstrate on this  .      pls don't paste the link.

Regards,
Chanti
Has anyone completed this trail? I am stomped on challenge number 3, regarding created the process for fulfillment. Any pointers or guidance would be appreciated.
 
I need apex code , I want a  Text Box and button on VF page, when i enter Some Text (ex address)  and enter, It should need to display all records where the Text matches(ex Address)......How we can acheive this? Is this Possible? Can we do this using SOSL, If anyone has the code please give me?
  • February 04, 2014
  • Like
  • 0