+ Start a Discussion
Best Answer chosen by prasad p 18
Rounak SharmaRounak Sharma
hi prasad,
You can use master-detail relationships to model many-to-many relationships between any two objects. A many-to-many relationship allows each record of one object to be linked to multiple records from another object and vice versa. For example, you create a custom object called “Bug” that relates to the standard case object such that a bug could be related to multiple cases and a case could also be related to multiple bugs. When modeling a many-to-many relationship, you use a junction object to connect the two objects you want to relate to each other.

Please let me know if it helps you and mark it as the best answer so that others can get benefitted from it.
thanks
Best Answer chosen by Alina
Khan AnasKhan Anas (Salesforce Developers) 
Hi Alina,

Greetings to you!

First, create two fields with Time data type, say, Start Working Hours and End Working Hours.
Then use below validation rule:
Start_Working_Hours__c > End_Working_Hours__c

Please refer to the below links which might help you further with the validation rules.

https://trailhead.salesforce.com/en/content/learn/modules/point_click_business_logic/validation_rules

https://help.salesforce.com/articleView?id=fields_useful_field_validation_formulas.htm&type=5 (https://help.salesforce.com/articleView?id=fields_useful_field_validation_formulas.htm&type=5)

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
The new LearnerThe new Learner 
Hi Experts,

I am trying to update the State and Country ISO Code picklist values using packages but i am getting below error while deploying using workbench. can anyone tell me how to update it please

here is the package:

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>Address</members>
        <name>Settings</name>
    </types>
    <version>42.0</version>
</Package>

Error:
Invalid iso code AB for country Aruba
Best Answer chosen by The new Learner
Khan AnasKhan Anas (Salesforce Developers) 
Hi,

Greetings to you!

You can’t edit the isoCode of standard states and countries. You can’t deploy new ISO codes or update ISO code values using any API. Please refer to the below links which might help you further.

https://help.salesforce.com/articleView?id=admin_state_country_picklists_api.htm&type=5 (https://help.salesforce.com/articleView?id=admin_state_country_picklists_api.htm&type=5)

https://developer.salesforce.com/docs/atlas.en-us.220.0.api_meta.meta/api_meta/meta_addresssettings.htm?search_text=AddressSettings

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Wylie PeachWylie Peach 
Hi Everyone,

I wrote a simple trigger that concatenates some fields into a key__c, and now I am trying to test it. I am having trouble getting it to return the tested inputs. Also, I was thinking of doing some bulk testing as well, should I write a loop? Here is what I have so far: 
Trigger 
trigger Composite_Key on Purchases__c (before insert, before update) {
    if(Trigger.isBefore)
    {
        for(Purchases__c purchase : trigger.new)
        {
            String eventName = String.isBlank(purchase.Event_name__c)?'':purchase.Event_name__c+'-';
            String section = String.isBlank(purchase.section__c)?'':purchase.section__c+'-';
            String row = String.isBlank(purchase.row__c)?'':purchase.row__c+'-';
            String seat = String.isBlank(String.valueOf(purchase.seat__c))?'':String.valueOf(purchase.seat__c)+'-';
            String numseats = String.isBlank(String.valueOf(purchase.number_of_seats__c))?'':String.valueOf(purchase.number_of_seats__c)+'-';
            String adddatetime = String.isBlank(String.valueOf(purchase.add_datetime__c))?'':String.valueOf(purchase.add_datetime__c);
            purchase.Key__c = eventName + section + row + seat + numseats + adddatetime;
        }
    }
}

Test so far
@isTest
private class CompositeKeyTest {
    
    static testMethod void testPurchase() {
        //create a purchase to fire the trigger
        Purchases__c purchase = new Purchases__c(Event_name__c = 'test', section__c='test',row__c='test', seat__c=1,number_of_seats__c='test',add_datetime__c='test');
        
        insert purchase;
        System.Assert(purchase.Key__c=='testtesttest1testtest');
    }
}

 
Best Answer chosen by Wylie Peach
Maharajan CMaharajan C
Hi Wyile,

Try the beloe class:

@isTest
private class CompositeKeyTest {
    
    static testMethod void testPurchase() {
        //create a purchase to fire the trigger
        Purchases__c purchase = new Purchases__c(Event_name__c = 'test', section__c='test',row__c='test', seat__c=1,number_of_seats__c='test',add_datetime__c='test');
        
        insert purchase;
        System.assertEquals('testtesttest1testtest',purchase.Key__c,'Key is not Valid');
    }
    
    static testMethod void testbulkPurchase() {
        //create a purchase to fire the trigger
        List<Purchases__c> purchaseList = new List<Purchases__c>();
        for(Integer i=0 ; i < 10 ; i++ )
        {
            Purchases__c purchaserec = new Purchases__c(Event_name__c = 'test', section__c='test',row__c='test', seat__c= i+1 ,number_of_seats__c='test',add_datetime__c='test');
            purchaseList.add(purchaserec);
        }
        insert purchaseList;
        System.assertEquals('testtesttest5testtest',purchaseList[4].Key__c,'Key is not Valid');
    }


Thanks,
Maharajan.C
SandrineSandrine 
Hello,

I am creating a reports on Contracts.
I filtered by date.

I dont see all the contracts.

is there any standard field that blocks the display of contracts in reports ?

thank you for suggestion
Best Answer chosen by Sandrine
Jega DeivaJega Deiva
Hello,

Standard Report Type:
   If fields are not visible you have to search the fields in the sidebar of the report builder and include it in the report.
Custom Report Type :
  You have to edit layouts in custom report type and add the fields which you want.

If this the count of contract missing you have to give the date field as "All Time". Eventhough it will only shows 2000 records this is the standard functionality of Salesforce, we have to export the report using export details buttons.This will show all contracts.

This might be helpful.

Thanks,
Jega

 
SandrineSandrine 
Hello,

I have below error, what can be reason:

Non static method cannot be referenced from a static context: void ContractTriggerHandler.OnAfterUpdate(List<Contract>, List<Contract>, Map<Id,Contract>, Map<Id,Contract>)

Any suggestions ?
Best Answer chosen by Sandrine
Alain CabonAlain Cabon
If the method OnAfterUpdate is not static, the call must done by using an instance created with "new myObjectName ()".

ContractTriggerHandler cth = new ContractTriggerHandler( ... perhaps with some parameters ... );

cth.OnAfterUpdate( ...);

 
Nick GachowiczNick Gachowicz 
Hi all, I'm a new developer and would appreciate any help with this question.

I am trying to pre-populate a lightning:select field based on a variable in the URL.

I am able to dynamically generate the list of options for the field, but I can't seem to get it to populate with the variable from the URL.

I am using a wrapper class to get both the list of options and my chosen option in the same call - class adapated from here: http://sfdcmonkey.com/2017/07/06/use-wrapper-class-lightning-component/

Here is my code:

Lightning Component:
<aura:component implements="flexipage:availableForAllPageTypes,forceCommunity:availableForAllPageTypes,force:appHostable,force:hasRecordId" controller="SADC_Contact_Us" access="global">
    
  
    <aura:attribute name="variableURL"                type="String" default="Nothing"/>
    <aura:attribute name="srvList"                type="Object"/> 
      
    <aura:handler name="init"    value="{!this}"                 action="{!c.onInit}" /> 
  
    <fieldset class="slds-box slds-m-top_small ">
        <legend class="slds-text-heading_medium">Provide us with some extra details</legend>
        

         <div class="slds-form-element__row">
            <div class="slds-form-element slds-size__2-of-2 slds-medium-size__1-of-2">
                <lightning:select aura:id="formField" name="formField" label="Service Area" required="true" value="{!v.variableURL}">
                    <option value="">- Not Specified -</option>
                    <aura:iteration items="{!v.srvList.lstServices}" var="ans">
                        <option value="{!ans.Name}" text="{!ans.Name}" selected="{!ans.Name == v.srvList.selectServ.Name}"></option>
                    </aura:iteration>
                </lightning:select>                             
            </div>
        </div> 
        
        
    </fieldset>
   
</aura:component>


Controller:
({
    onInit : function(component, event, helper) {
       
       var action = component.get("c.initMethod");
       var variableURL = component.get("v.variableURL");

       action.setParams({
           variableURL : variableURL
       });
        
       action.setCallback(this, function(a) {
            
         var state = a.getState();
         console.log("state: ",state);
            
         if (state === 'SUCCESS'){
                
             //set response value in wrapperList attribute on component.
             var response = a.getReturnValue();
             console.log("response: ",response);
                
                
             component.set("v.srvList",response);
            
            }
            
       });
      $A.enqueueAction(action);
        
    }
    
})


Apex Class:
public class SADC_Contact_Us {
    
       @AuraEnabled
           public static wrapperClass initMethod(String variableURL){
             //create a wrapper class object and set the wrapper class @AuraEnabled properties and return it to the lightning component.
               wrapperClass returnwrapperClass = new  wrapperClass ();        
               returnwrapperClass.lstServices = [SELECT Name from Website_Service__c WHERE Service_Level__c =1 LIMIT 25];
                returnwrapperClass.selectServ = [SELECT Name from Website_Service__c WHERE Service_Level__c =1 AND Name=:variableURL LIMIT 1];
              return returnwrapperClass;    
    }
    
       //wrapper or Inner class with @AuraEnabled {get;set;} properties*    
        public class wrapperClass{
                @AuraEnabled public List<Website_Service__c> lstServices{get;set;}
                @AuraEnabled public List<Website_Service__c> selectServ {get;set;}
        }    
}



So the aura:iteration on items="{!v.srvList.lstServices}" works fine, but this part does not load anything:

selected="{!ans.Name == v.srvList.selectServ.Name}

Can anyone advise how to get this selected part working?
Best Answer chosen by Nick Gachowicz
Nick GachowiczNick Gachowicz
Got an answer on Stack Exchange which solved it:

"That is because you are assigning List<Website_Service__c> to selectServ and when you try to get value on it like selectServ.Name, it will be undefined. You should rather get it from a particular record. I see that you are are fetching single element LIMIT 1. You can use below:

selected="{!ans.Name == v.srvList.selectServ[0].Name}

This will fetch the Name of 1st element (0th index).
Service Cloud 60Service Cloud 60 
Hi, 
Can anyone tell me how to get record Id when i click on the checkbox of datatable in lightning component ?

TIA
Best Answer chosen by Service Cloud 60
Khan AnasKhan Anas (Salesforce Developers) 
Hi,

Greetings to you!

You can use onrowselection event handler. Try like this:

Component:
<lightning:datatable data="{! v.mydata }" 
                         columns="{! v.mycolumns }" 
                         keyField="Id" 
                         onrowselection="{! c.handleRowAction }"/>

Controller:
handleRowAction : function(component, event, helper){
        var selRows = event.getParam('selectedRows');
        console.log('selRows -> ' + JSON.stringify(selRows));
        var selectedRowsIds = [];
        for(var i=0;i<selRows.length;i++){
            selectedRowsIds.push(selRows[i].Id);  
            console.log('selectedRowsIds -> ' + selectedRowsIds);
        }   
    },

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
SandrineSandrine 
Hello,

I want to implemeent below usecase

After update
 - I want to check that if the Picklist_Custom__c value = XYZ
IF true i want to call a Apex_classNAme.ApexFucntion()

How can i write the code for same.

thank you 
Best Answer chosen by Sandrine
Rounak SharmaRounak Sharma
hi sandrine,
You can implement the code in this manner:
if( Picklist_Custom__c value =='XYZ'){
Apex_classNAme.ApexFucntion();
}
Please let me know if it helped in any way. 
Thanks
Ramana V 8Ramana V 8 
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
Best Answer chosen by Ramana V 8
Shashidhar NaruShashidhar Naru
Hi Ramana
You can try this
select id, createdDate from case where CreatedDate = LAST_N_Days:730 AND CreatedDate < LAST_N_Days:1