• Krishnamurthy KA 10
  • NEWBIE
  • 5 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
I have a one to many relationship between Project and Insurance. When a record is created on Insurance object, it needs to get the Project record and then count how many Insurance records are present and it needs to input the value in the Name field of the Insurance record.

The below code does that exactly but it inserts the records based on the order it receives it. When I try to mass upload the Insurance__c using excel, the record that I insert first gets inserted and assigned a reference as INS-001 and so on.

The sequence will be incorrect if the records are not in order. For that reason, I want to sort it by start date field in the Insurance__c object. I don't think this is achievable in before insert trigger since I don't have the record Id's. I am confused as to how to go about it for 2 days now. Can you please help? Many thanks in advance!

Trigger
trigger InsuranceTrigger on Insurance__c (before insert) {
        
    SWITCH ON Trigger.operationType {
        WHEN BEFORE_INSERT{
            InsuranceClass.insuranceAutomation(Trigger.new);
        }
    }
}

Apex Class:
public class InsuranceClass {
    public static void insuranceAutomation(List<Insurance__c> insuranceList){
        Set<Id> insuranceIds = new Set<Id>();
        
        //Get all the project Id for the corresponding new insurance records
        for(Insurance__c i : insuranceList){
            insuranceIds.add(i.Project__c);
            system.debug(insuranceIds);
        }

        //Query the number of insurance records for the corresponding projects
        Map<Id,Milestone1_Project__c> is = new Map<Id,Milestone1_Project__c>([SELECT Id, Cleantech_Reference__c, 
                                                                              (SELECT Id, Project__c, Name FROM Insurance__r) 
                                                                              FROM Milestone1_Project__c WHERE Id in :insuranceIds]);
        
        Map<Id, Integer> newMap = new Map<Id, Integer>();        
        for(Insurance__c i : insuranceList){
            
            //if there is no insurance record associated with the project and if the newMap is empty
            if(is.get(i.Project__c).Insurance__r.isEmpty() && !newMap.containskey(i.Project__c)){
                Integer count = 1;
                i.Name = is.get(i.Project__c).Cleantech_Reference__c+'/'+'INS-'+string.valueOf(count);
                newMap.put(i.Project__c, count);
                
            }
            //if there are insurance records and the newMap is empty
            else if(!is.get(i.Project__c).Insurance__r.isEmpty()&& !newMap.containskey(i.Project__c) )
            {
                Integer count = is.get(i.Project__c).Insurance__r.size()+1;
                i.Name = is.get(i.Project__c).Cleantech_Reference__c+'/'+'INS-'+string.valueOf(count);
                newMap.put(i.Project__c, count);
            }
            //if the newMap is not empty
            else{
                Integer count = newMap.get(i.Project__c)+1;
                i.Name = is.get(i.Project__c).Cleantech_Reference__c+'/'+'INS-'+string.valueOf(count);
                newMap.put(i.Project__c, count);
                
            }
        }   
    }
}

 
Hi everyone, we are planning to integrate sharepoint with salesforce with a vendor. The vendor is asking for integration user in Sharepoint. What does that mean?
I am new to integration and would like to know what are the ways with which we could integrate SharePoint online with Salesforce efficiently. From what I have found online we can use REST API to connect to SharePoint online. We approached a Salesforce vendor who estimated the number of hours for each task. Does the below sound reasonable or can you please guide me as to what further questions that I need to ask the vendor on the below integration?
  • Create Data model to store the Folder Structure if required based on the Month/Year - 10 hours.
  • Write the Authentication logic for SharePoint access - 40 hours.
  • Embed the file creation & folder creation (if required) code in existing "Send To Client" lightning component to store the files in SharePoint - 60 hours.
  • Implement the Logging mechanism for any failures occurred - 30 hours.
  • Apex Test Classes - 20 hours.
  • UAT Testing & Bug fixes - 10 hours.
  • Contingency - 10 hours plus or minus.
I am new to integration and would like to know what are the ways with which we could integrate SharePoint online with Salesforce efficiently. From what I have found online we can use REST API to connect to SharePoint online. We approached a Salesforce vendor who estimated the number of hours for each task. Does the below sound reasonable or can you please guide me as to what further questions that I need to ask the vendor on the below integration?
  • Create Data model to store the Folder Structure if required based on the Month/Year - 10 hours.
  • Write the Authentication logic for SharePoint access - 40 hours.
  • Embed the file creation & folder creation (if required) code in existing "Send To Client" lightning component to store the files in SharePoint - 60 hours.
  • Implement the Logging mechanism for any failures occurred - 30 hours.
  • Apex Test Classes - 20 hours.
  • UAT Testing & Bug fixes - 10 hours.
  • Contingency - 10 hours plus or minus.