This record type Bunk cannot be deactivated because the following profiles use this record type as default.

We had a custom object which had a couple of record types and later we realized record types are not needed. Since record types are saved in profiles, I got an error shown below

In order to resolve this, we can use the link shown below ( and replace the url and id from your org )

https://myorgds.my.salesforce.com/00e8A000000QTvu/e?s=ObjectsAndTabs&o=01I8A000000EAYT

where 00e8A000000QTvu is the profile Id for system admin in my org

01I8A000000EAYT is the id for custom object where we want to change the recordtype

This approach will work for all profiles except chatter profiles

  • Chatter External User
  • Chatter Free User
  • Chatter Moderator User

You can use this another url to update the default recordtype for these profiles

https://myorgds.my.salesforce.com/setup/ui/profilerecordtypeedit.jsp?id=00e1N0000021rXI&tid=01I8A000000EAYT

where id=’profile Id’ and tid=objectid

you can update the master record type as default record type and once it is done for all profiles, you can deactivate the record type and then later delete it.

Permanent link to this article: https://salesforcebuddy.com/2020/11/this-record-type-bunk-cannot-be-deactivated-because-the-following-profiles-use-this-record-type-as-default/

Error Debugging – Permission Issue

Recently, we noticed an error in our salesforce org

You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary

From the initial look, it appears to be some permission of access related issue. On deeper dive, this could have occurred because of various reasons.

  1. OWD is very restrictive and does not let the user access the data
  2. Profile does not have required access to this object. BTW, this is Contact data that we are (not) seeing here.
  3. The code ( lightning component ) could have any code block which does not work well.

After debugging a little, OWD for Account/Contact was Public Read only, and we could not change it

Instructor ( custom ) profile has read for Contact and we could not change it.

The lightning component was using, although there was no usecase of editing the contact record

   <lightning:recordEditForm recordId="{!v.instructorData.Id}"
                                              objectApiName="Contact"
                                                                                       class="slds-p-around_x-small">
                      
                        <lightning:outputField fieldName="Name" variant="label-inline"/>
                       
                        <lightning:outputField fieldName="Phone" variant="label-inline"/>
                        <lightning:outputField fieldName="HomePhone" variant="label-inline"/>
                        <lightning:outputField fieldName="Email" variant="label-inline"/>
                        <lightning:outputField fieldName="MailingAddress" variant="label-inline"/>

                      
                    </lightning:recordEditForm>

Once I replaced,

lightning:recordEditForm with lightning:recordViewForm, the page started showing up as needed

Permanent link to this article: https://salesforcebuddy.com/2020/09/error-debugging-permission-issue/

Export to Calendar using Aura Components

My project had a requirement to download a calendar file (ICS File) from a list of training records in data table

The idea is to create an ics file and download it, similar to how we download csv file. Once this file is downloaded, it can be saved in any calendar used by the user.

Component Code

  <lightning:datatable
                  class="client-table-text_wrap"
                  keyField="tkeyField"
                  data="{! v.programDetails.hhProgramData.upcomingPrograms }"
                  columns="{! v.upcomingProgramColumns }"
                  hideCheckboxColumn="true"
                  onrowaction="{!c.handleRowUpcomingCancel}"
                  showRowNumberColumn="false"
                />

Controller JS Code

 handleRowUpcomingCancel: function (component, event, helper) {
      var action = event.getParam('action');
      var row = event.getParam('row');
      switch (action.name) {
          case 'cancelProduct':
              helper.cancelProductAction(component,event);
              break;
          case 'exportProduct':
            helper.exportProductAction(component,event);
            break;              
 
      }
    },

Helper JS Code

 exportProductAction: function(component,event) {
        var action = component.get("c.getExportToCalendar");
        var row = event.getParam('row');
        action.setParams({
            'recordId' : row.recordId
        });
        action.setCallback(this, function(response) {
            var status = response.getState();
            if (status === "SUCCESS") {
                var vCal = response.getReturnValue();
                var hiddenElement = document.createElement('a');
                hiddenElement.href = 'data:text/calendar;charset=utf-8,' + encodeURI(vCal);
                hiddenElement.target = '_self'; // 
                hiddenElement.download = row.programName+'.ics'; 
                document.body.appendChild(hiddenElement);
                hiddenElement.click();
                this.showToast("Success", "Success!", 'Export completed successfully');                
            }
            else {
                var errors = response.getError();
                this.handleError(errors);
            }
        });    
        $A.enqueueAction(action);
     },

Apex Class

@AuraEnabled
public Static String getExportToCalendar(String recordId){
        String vCal='';
        //TODO - query from an object which has data for event date, time,
  // Location etc
   // Assuming it comes from Event_Record__c

 Event_Record__c evt = [actual SOQL ];
            vCal += 'BEGIN:VCALENDAR\n'+'VERSION:2.0 \n'+ 'PRODID:-//salesforce.com//Calendar//EN \n';
            vCal += 'BEGIN:VEVENT\n';
            vCal += 'UID:'+recordId+'\n';
            vCal += 'DTSTAMP;TZID=America/New_York:'+System.now().format('yyyyMMdd\'T\'HHmmss\'Z\'','America/New_York')+'\n';
            vCal += 'SUMMARY:'+evt.Product_Name__c+'\n';
            vCal += 'DESCRIPTION:'+evt.Product_Name__c+'\n';
            vCal += 'CATEGORIES:salesforce.com'+'\n';
            vCal += 'CREATED;TZID=America/New_York:'+System.now().format('yyyyMMdd\'T\'HHmmss\'Z\'','America/New_York')+'\n';
            vCal += 'LAST-MODIFIED;TZID=America/New_York:'+System.now().format('yyyyMMdd\'T\'HHmmss\'Z\'','America/New_York')+'\n';
            vCal += 'STATUS:CONFIRMED'+'\n';
            vCal += 'LOCATION:'+evt.Facility__r.Name+'\n';            
            vCal += 'DTSTART;TZID=America/New_York:'+evt.startDate.format('yyyyMMdd\'T\'HHmmss\'Z\'','America/New_York')+'\n';
            vCal += 'DTEND;TZID=America/New_York:'+evt.endDate.format('yyyyMMdd\'T\'HHmmss\'Z\'','America/New_York')+'\n';
            vCal += 'END:VEVENT \n'+'END:VCALENDAR\n';  
        }else{
            throw new AuraHandledException('Error in exporting to Calendar');
        }


        return vCal;
     }

when you open this ics file, you get a prompt like shown below

you can save in any calendar you follow like outlook or gmail or any other

Permanent link to this article: https://salesforcebuddy.com/2020/07/export-to-calendar-using-aura-components/