• S Balaji 8
  • NEWBIE
  • 30 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 19
    Questions
  • 10
    Replies
On Case object under attachment related lists section , we have to override the upload files button and when we click it we should have two options one is public and another one is private , if user clicks public then he should be able to add the attachment should be visible both in Salesforce as well as in community portal.
If it is private then it has to be visible only in salesforce ( right now the default is private which is out of the box ).
Is it possible to show a bell notification in salesforce when the case Milestone is within 12 hours of being reached.
Can someone share me the sample code or provide me idea of how to make an api callout in LWC on click of a button.
 
For the following code i am getting insert failed exception on insert contentList; Can someone help me with this , it is working on one sandbox but failing in another one

@isTest public static void sendemailtoAccountownerTest(){
        
        Test.startTest();
        //Create Document Parent Record
      
        Account acc =new Account();
        acc.Name = 'Test Account';
        acc.BillingCountryCode = 'CA';
        insert acc ;
        
        //Create Document
        ContentVersion cv = new ContentVersion();
        cv.Title = 'Test Document';
        cv.PathOnClient = 'TestDocument.pdf';
        cv.VersionData = Blob.valueOf('Test Content');
        cv.IsMajorVersion = true;
        Insert cv;
        
        //Get Content Documents
        Id conDocId = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =:cv.Id].ContentDocumentId;
        
        system.debug('conDocId data is :'+conDocId);
        bynder__Bynder_Asset__c bynder = new bynder__Bynder_Asset__c();
        bynder.bynder__File_Type__c = 'DOCUMENT';
        bynder.bynder__Asset_Id__c = 'Test';
        insert bynder;
        
        //Create ContentDocumentLink 
        List<ContentDocumentLink> contentList = new List<ContentDocumentLink>();
        ContentDocumentLink cdl = New ContentDocumentLink();
        cdl.LinkedEntityId = acc.Id;
        cdl.ContentDocumentId = conDocId;
        cdl.shareType = 'V';
        contentList.add(cdl);
        
        ContentDocumentLink cdl1 = New ContentDocumentLink();
        cdl1.LinkedEntityId = bynder.Id;
        cdl1.ContentDocumentId = conDocId;
        cdl1.shareType = 'V';
        contentList.add(cdl1);
        system.debug('Content list data is :' + contentList);
        insert contentList;
           
        bynder.bynder__Content_Version_Id__c = contentList[0].Id;
        update bynder;
        
        MOD_ContentDocumentLinkTriggerHelper.sendEmailToAccountOwner(contentList);
        Test.stopTest();
    }
From account, i have custom LWC component which will take me to bynder platform where i can select the pdf and after clicking it will bring the pdf to account and store it in the files related list.

And also i have bynder asset tab where each time when the pdf gets downloaded, there will be an entry in this object as attached.

My use case how to grab this render url or download url and mail it to account owner?

User-added image


 
Class.Mod_LogEngagementDetailsController.createTaskRec: line 142, column 1
19:51:58.783 (4784549213)|FATAL_ERROR|System.DmlException: Insert failed. First exception on row 0; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record or 1 records: 0018K000008YcEuQAK: []
========================================

@auraEnabled
    public static void createTaskRec(String objTask, String accId){
        Task objTsk = (Task)JSON.deserialize(objTask, Task.Class);
        if(!String.isBlank(accId) && (!String.isBlank(objTsk.description) || !String.isBlank(objTsk.OwnerId) || objTsk.ActivityDate != null)){
            Task objTaskNew= createTaskGen(objTsk.description, objTsk.OwnerId, objTsk.ActivityDate, accId);
            if(objTaskNew != null && Schema.sObjectType.Task.isUpdateable()){
                insert objTaskNew;
            }
        }
    }


Regards,
Balaji
I am getting error saying ord2.MOD_Email_Sent_Date_DR__c this is not valid variable.


================================================
public static void update2WeekPickList(List<MOD_Order_Detail__c> ordetaillist)
   {
       Set<Id>OrderDetailIds=new Set<Id>();
       for(MOD_Order_Detail__c ord:ordetaillist)
       {
           OrderDetailIds.add(ord.Id);
       }
       List<MOD_Order_Detail__c> ordetaillist2=[Select id,MOD_Email_Sent_Date_DR__c,MOD_Week__c,(SELECT Id,EffectiveDate FROM Orders1__r)
                                                                                                 from MOD_Order_Detail__c where Id=:OrderDetailIds];
       List<MOD_Order_Detail__c> UpdatedOrdDetailList=new List<MOD_Order_Detail__c>();
       Map<Id,List<Order>> OrderMap=new Map<Id,List<Order>>();
       for(MOD_Order_Detail__c ord2 :ordetaillist2)
       {
        OrderMap.put(ord2.Id, new List<Order>{ord2.Orders1__r});
       }      
         for(Order orr:OrderMap.values())
         {
            //dateCalculation2w(orr.EffectiveDate);
            Date ThirdMondayafterStartDate =orr.EffectiveDate.toStartofWeek() + 22 ;
            Date FifthMondayafterStartDate= orr.EffectiveDate.toStartofWeek() + 36 ;
            Date SeventhMondayafterStartDate=orr.EffectiveDate.toStartofWeek() + 50 ;
            Date NinthMondayafterStartDate= orr.EffectiveDate.toStartofWeek() + 64 ;
            Date ThirtneenthMondayafterStartDate= orr.EffectiveDate.toStartofWeek() + 92 ;
            Date SeventeenthMondayafterStartDate= orr.EffectiveDate.toStartofWeek() + 120 ;
            Date TwentyOneMondayafterStartDate= orr.EffectiveDate.toStartofWeek() + 148 ;
            Date TwentyFiveMondayafterStartDate= orr.EffectiveDate.toStartofWeek() + 176 ;
           
            If( orr.EffectiveDate < ord2.MOD_Email_Sent_Date_DR__c && ord2.MOD_Email_Sent_Date_DR__c <= ThirdMondayafterStartDate)
            {
                for (MOD_Order_Detail__c OrdOriginal:ordetaillist)
                {
                    MOD_Order_Detail__c ModOrdDetail=new MOD_Order_Detail__c();
                    ModOrdDetail.MOD_Week__c='2W';
                    ModOrdDetail.ID=OrdOriginal.ID;
                    UpdatedOrdDetailList.add(ModOrdDetail);
                }    
            }
         }
           if(!UpdatedOrdDetailList.isEmpty())
           {
               Update UpdatedOrdDetailList;
           }
      }
For the below code, i want to check if MOD_Responsible_Doc__c=TRUE and email id is also populated then execute

Ord1.MOD_Responsible_DR_Name__c = mapAccwithContactIds.get(Ord1.AccountId);
Ord1.MOD_Doctor__c= true;

i want to check if MOD_Responsible_Doc__c=TRUE and email id is not populated then execute only


Ord1.MOD_Responsible_DR_Name__c = mapAccwithContactIds.get(Ord1.AccountId);
=================================================
Map<Id,Id> mapAccwithContactIds = new Map<Id,Id>();
            for(Contact Con:[Select Id,AccountId,MOD_Responsible_Doc__c,Email from Contact where AccountId IN:VarAccIds AND MOD_Responsible_Doc__c=TRUE AND (Email != null OR Email = null)]){
                mapAccwithContactIds.put(Con.AccountId,Con.Id);
            }
            for (Order Ord1 : newList) {
                if(mapAccwithContactIds.containskey(Ord1.AccountId)){
                    Ord1.MOD_Responsible_DR_Name__c = mapAccwithContactIds.get(Ord1.AccountId);
                }
                /* if(Ord1.MOD_Doctor__c == FALSE){
                    Ord1.MOD_DM__c = TRUE;
                } */
            }
There are two objects:
1.Order-   Order start date and Order object is the child object looking upto Order Detail
2. Order Detail Object- 

=====================================
Basically i have a week picklist field in order detail object with different values like 2W,4W,6W,8W.

Use case to be implemented:

1.Week field should be populated as 2W: If Email sent date field is between the Order Start Date, and until 3 Mondays after the Order Start Date
2. Week field should be populated as 4W Between the 2W Monday Date, and 2 Weeks after the 2W Monday Date

For example:

IF order start date is 1st November and if the Email sent date is anywhere between 1st and 21 Nov- Then update week status as 2W.

IF order start date is 1st November and if the email is sent anywhere between 21st Nov and 5th Dec- Then update week status as 4W.

Email sent date is already populated in the order detail object.
When an Order is loaded into CRM, using the associated Account, find the child Contact using the “RDOC(field on Contact)” field as a flag, populate this Contact in “DR” Lookup field on Order 
public static String fetchUserRole(){
    String uRoleId = UserInfo.getUserRoleId();
    String roleName;
    roleName = [SELECT Id,UserRole.Id, UserRole.DeveloperName from User where UserRole.Id =: uRoleId limit 1].UserRole.DeveloperName;
    return roleName;
}
Hi all,

i have got the below class that converts lead into contacts and accounts.

Can someone help how to actually pass the accountId in the flow inorder to invoke the apex class that identifies existing accounts and add the contact to it.



=====================================================
public with sharing class ConvertLeadsInvocable {

    public class LeadConvertRequest {
        @InvocableVariable(
            label = 'Lead ID'
            description = 'ID of the Lead to convert'
            required = true
        )
        public ID leadId;
        //@InvocableVariable(
            //label = 'Converted Status'
           // description = 'Lead Status picklist value that indicates this Lead is converted'
            //required = true
        //)
        //public String convertedStatus;
        @InvocableVariable(
            label = 'Account ID'
            description = 'The specific Account to convert Lead into. If blank then creates new Account.'
        )
        public ID accountId;
        @InvocableVariable(
            label = 'Contact ID'
            description = 'The specific Contact to convert Lead into. If blank then creates new Contact.'
        )
        public ID contactId;
        @InvocableVariable(
            label = 'Overwrite Lead Source?'
            description = 'Overwrite the LeadSource field on the target Contact with the LeadSource field from the Lead? Default is false. If true then must also specify "Contact ID".'
        )
        public Boolean overwriteLeadSource = false;
        @InvocableVariable(
            label = 'Create Opportunity?'
            description = 'Create an Opportunity? Default is true.'
        )
        public Boolean createOpportunity = true;
        @InvocableVariable(
            label = 'Opportunity Name'
            description = 'If "Create Opportunity" is true then this is the name of the new opportunity. If blank then defaults to Company field from the Lead.'
        )
        public String opportunityName;
       
        @InvocableVariable(
            label = 'Associate with Exisiting Account?'
            description = 'Search for Company name in Account and associate contact with Exisiting Account? Default is true.'
        )
        public Boolean existingacc = true;
       
        @InvocableVariable(
            label = 'Associate with Exisiting Contact?'
            description = 'Search for Email in Contact and associate contact with Exisiting Account? Default is true.'
        )
        public Boolean existingcon = true;
        @InvocableVariable(
            label = 'Owner ID'
            description = 'Specific user to own the new Account, Contact, and Opportunity records created. Default is the Lead owner.'
        )
        public ID ownerId;
        @InvocableVariable(
            label = 'Send Email to Owner?'
            description = 'Send an email notification to owner specified in "Owner ID"? Default is false.'
        )
        public Boolean sendEmailToOwner = false;
    }

    public class LeadConvertResult {
        @InvocableVariable( label = 'Lead ID' )
        public ID leadId;
        @InvocableVariable( label = 'Account ID' )
        public ID accountId;
        @InvocableVariable( label = 'Contact ID' )
        public ID contactId;
        @InvocableVariable( label = 'Opportunity ID' )
        public ID opportunityId;
    }
    // --------------------------------------------------------------------------------
    @InvocableMethod(
        label = 'Convert Leads'
    )
    public static List<LeadConvertResult> convertLeads( List<LeadConvertRequest> requests ) {
        // Bulkifying - Upsert Account/Contact (to remove duplication) // By @mhamzas
        Map<Id, Lead> MapofLeads = new Map<Id,Lead>();
        Map<String, Id> MapofCompany_LeadId = new Map<String,Id>();
        Map<String, Id> MapofEmail_LeadId = new Map<String,Id>();
        Map<Id, Id> MapofLead_acc = new Map<Id,Id>();
        Map<Id, Id> MapofLead_con = new Map<Id,Id>();
        List<String> CompanyNames = new List<String>();
        List<String> LeadEmails = new List<String>();
        List<Id> LeadIds = new List<Id>();
       
        for (LeadConvertRequest request : requests ) {
            LeadIds.add(request.leadId);
        }
       
        if(leadIds.size() > 0 & leadIds !=null){
            for(Lead l : [select id, Name, Email, Company from Lead where Id IN : LeadIds]){
                MapofLeads.put(l.id,l);
                MapofCompany_LeadId.put(l.Company,l.id);
                MapofEmail_LeadId.put(l.email,l.id);
                CompanyNames.add(l.company);
                LeadEmails.add(l.email);
            }
        }
       
        if(CompanyNames != null && CompanyNames.size() > 0){
            for(Account acc : [select id, Name from Account where Name IN : CompanyNames]){
                if(MapofCompany_LeadId.containsKey(acc.Name)){
                    MapofLead_acc.put(MapofCompany_LeadId.get(acc.Name),acc.id);
                }
            }
        }
       
        if(LeadEmails != null && LeadEmails.size() > 0){
            for(Contact con : [select id, Email from Contact where Email IN : LeadEmails]){
                if(MapofEmail_LeadId.containsKey(con.email)){
                    MapofLead_con.put(MapofEmail_LeadId.get(con.email),con.id);
                }
            }
        }
        // transform the invocable request to database convert request
        List<Database.LeadConvert> convertRequests = new List<Database.LeadConvert>();
        for ( LeadConvertRequest request : requests ) {
            // If Map Contains AccountId for Lead
            if(request.accountId == null && MapofLead_acc.containskey(request.leadId) && request.existingacc ==  TRUE){
                request.accountId = MapofLead_acc.get(request.leadId);
            }
            // If Map Contains ContactId for Lead
            if(request.contactId == null && MapofLead_con.containskey(request.leadId)  && request.existingcon ==  TRUE){
                request.contactId = MapofLead_con.get(request.leadId);
            }
            convertRequests.add( transform( request ) );
        }
        // convert leads, all or none
        // if any has error then exception is thrown automatically and changes rolled back
        List<Database.LeadConvertResult> convertResults = Database.convertLead( convertRequests, true );
        // transform the database convert results to invocable result
        List<LeadConvertResult> results = new List<LeadConvertResult>();
        for ( Database.LeadConvertResult convertResult : convertResults ) {
            results.add( transform( convertResult ) );
        }
        return results;
    }
    // --------------------------------------------------------------------------------
    private static Database.LeadConvert transform( LeadConvertRequest request ) {
               
        Database.LeadConvert convertRequest = new Database.LeadConvert();
               
        convertRequest.setLeadId( request.leadId );
        //convertRequest.setConvertedStatus( request.convertedStatus );
        if ( request.accountId != null ) {
            convertRequest.setAccountId( request.accountId );
        }
       
        if ( request.contactId != null ) {
            convertRequest.setContactId( request.contactId );
        }
       
        if ( request.overwriteLeadSource != null && request.overwriteLeadSource ) {
            convertRequest.setOverwriteLeadSource( request.overwriteLeadSource );
        }
        if ( request.createOpportunity != null && !request.createOpportunity ) {
            convertRequest.setDoNotCreateOpportunity( !request.createOpportunity );
        }
        if ( request.opportunityName != null ) {
            convertRequest.setOpportunityName( request.opportunityName );
        }
        if ( request.ownerId != null ) {
            convertRequest.setOwnerId( request.ownerId );
        }
        if ( request.sendEmailToOwner != null && request.sendEmailToOwner ) {
            convertRequest.setSendNotificationEmail( request.sendEmailToOwner );
        }
        return convertRequest;
    }
    private static LeadConvertResult transform( Database.LeadConvertResult convertResult ) {
        LeadConvertResult result = new LeadConvertResult();
        result.leadId = convertResult.getLeadId();
        result.accountId = convertResult.getAccountId();
        result.contactId = convertResult.getContactId();
        result.opportunityId = convertResult.getOpportunityId();
        return result;
    }
    public class ConvertLeadException extends Exception {}
}
==========================================

 
From account, i have custom LWC component which will take me to bynder platform where i can select the pdf and after clicking it will bring the pdf to account and store it in the files related list.

And also i have bynder asset tab where each time when the pdf gets downloaded, there will be an entry in this object as attached.

My use case how to grab this render url or download url and mail it to account owner?

User-added image


 
There are two objects:
1.Order-   Order start date and Order object is the child object looking upto Order Detail
2. Order Detail Object- 

=====================================
Basically i have a week picklist field in order detail object with different values like 2W,4W,6W,8W.

Use case to be implemented:

1.Week field should be populated as 2W: If Email sent date field is between the Order Start Date, and until 3 Mondays after the Order Start Date
2. Week field should be populated as 4W Between the 2W Monday Date, and 2 Weeks after the 2W Monday Date

For example:

IF order start date is 1st November and if the Email sent date is anywhere between 1st and 21 Nov- Then update week status as 2W.

IF order start date is 1st November and if the email is sent anywhere between 21st Nov and 5th Dec- Then update week status as 4W.

Email sent date is already populated in the order detail object.
When an Order is loaded into CRM, using the associated Account, find the child Contact using the “RDOC(field on Contact)” field as a flag, populate this Contact in “DR” Lookup field on Order 
public static String fetchUserRole(){
    String uRoleId = UserInfo.getUserRoleId();
    String roleName;
    roleName = [SELECT Id,UserRole.Id, UserRole.DeveloperName from User where UserRole.Id =: uRoleId limit 1].UserRole.DeveloperName;
    return roleName;
}