• Sanju Sam Mathew
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
public with sharing class met1x_DVIMarkerController {
    @AuraEnabled(cacheable=true)
    public static boolean getcheckboxvalue(String recordid){
        String objName=findObjectNameFromRecordId(recordid);
        try{
            System.debug('objName'+objName);
            System.debug('recordid'+recordid);
            if(objName=='Account'){
                
                return [select GiDP_DomesticViolenceIndicator__c from Account where id=:recordid and GiDP_DomesticViolenceIndicator__c=true limit 1].GiDP_DomesticViolenceIndicator__c;
                //return obj.get(0).GiDP_DomesticViolenceIndicator__c;
            }
            else if(objName == 'Asset'){
                return [select GiDP_DomesticViolenceIndicator__c from Asset where id=:recordid and GiDP_DomesticViolenceIndicator__c=true limit 1].GiDP_DomesticViolenceIndicator__c;
            }
            else if(objName == 'vlocity_ins__InsuranceClaim__c'){
                return [select GiDP_DomesticViolenceIndicator__c from vlocity_ins__InsuranceClaim__c where id=:recordid and GiDP_DomesticViolenceIndicator__c=true limit 1].GiDP_DomesticViolenceIndicator__c;
                
            }
            else if(objName=='GiDP_ImageMetadataRepo__c'){
                // List<GiDP_ImageMetadataRepo__c> metadatarepos=[select id,]
                List<GiDP_ImageMetadataRepo__c> metadatrepos= [select id,GiDP_PolicyRecord__r.GiDP_FraudIndicator__c from GiDP_ImageMetadataRepo__c where id=:recordid and GiDP_PolicyRecord__r.GiDP_DomesticViolenceIndicator__c=true limit 1];
                if(metadatrepos.size()>0){
                    return true;
                }
            }
            /*if(Test.isRunningTest()){
                
                throw new DMLException('Static DML Exception to cover catch block');
                
            }*/
            return false;
        }
        catch (Exception ex) {
            ExceptionLogUtility.createException('getcheckboxvalue method', 'Exception', ex.getStackTraceString(), 
                                                'met1x_DVIMarkerController Class', 'Application', objName+' Object', ex.getMessage());
            return null;
        }
    }
    @AuraEnabled(cacheable=true)
    public static boolean getFraudIndicatorInfo(String recordid){
        String objName=findObjectNameFromRecordId(recordid);
        try{
            System.debug('objName'+objName);
            System.debug('recordid'+recordid);
            if(objName=='Account'){
                return [select GiDP_FraudIndicator__c from Account where id=:recordid and GiDP_FraudIndicator__c=true limit 1].GiDP_FraudIndicator__c;
                //return obj.get(0).GiDP_DomesticViolenceIndicator__c;
            }
            else if(objName == 'Asset'){
                return [select GiDP_FraudIndicator__c from Asset where id=:recordid and GiDP_FraudIndicator__c=true limit 1].GiDP_FraudIndicator__c;
            }
            else if(objName == 'vlocity_ins__InsuranceClaim__c'){
                return [select GiDP_FraudIndicator__c from vlocity_ins__InsuranceClaim__c where id=:recordid and GiDP_FraudIndicator__c=true limit 1].GiDP_FraudIndicator__c;
                
            }
            else if(objName=='GiDP_ImageMetadataRepo__c'){
                //return true;
                List<GiDP_ImageMetadataRepo__c> metadatrepos= [select id,GiDP_PolicyRecord__r.GiDP_FraudIndicator__c from GiDP_ImageMetadataRepo__c where id=:recordid and GiDP_PolicyRecord__r.GiDP_FraudIndicator__c=true limit 1];
                if(metadatrepos.size()>0){
                    return true;
                }
            }
            return false;
        }
        catch (Exception ex) {
            ExceptionLogUtility.createException('getFraudIndicatorInfo method', 'Exception', ex.getStackTraceString(), 
                                                'met1x_DVIMarkerController Class', 'Application', objName+' Object', ex.getMessage());
            return null;
        }
    }
    @AuraEnabled(cacheable=true)
    public static String findObjectNameFromRecordId(String recordId){
        String objectName = '';
        try{
            //Get prefix from record ID
            //This assumes that you have passed at least 3 characters
            String myIdPrefix = String.valueOf(recordId).substring(0,3);
            
            //Get schema information
            Map<String, Schema.SObjectType> gd =  Schema.getGlobalDescribe(); 
            
            //Loop through all the sObject types returned by Schema
            for(Schema.SObjectType stype : gd.values()){
                if(stype.getDescribe().getKeyPrefix() != null && 
                   (stype.getDescribe().getKeyPrefix() == '001' ||
                    stype.getDescribe().getKeyPrefix() == '02i' ||
                    stype.getDescribe().getKeyPrefix() == 'a')){
                        Schema.DescribeSObjectResult r = stype.getDescribe();
                        String prefix = r.getKeyPrefix();
                        System.debug('Prefix is ' + prefix);
                        
                        //Check if the prefix matches with requested prefix
                        if(prefix!=null && prefix.equals(myIdPrefix)){
                            objectName = r.getName();
                            System.debug('Object Name! ' + objectName);
                            break;
                        }
                    }
            }
        }
        catch (Exception ex) {
            ExceptionLogUtility.createException('findObjectNameFromRecordId method', 'Exception', ex.getStackTraceString(), 
                                                'met1x_DVIMarkerController Class', 'Application', objectName+' Object', ex.getMessage());
        }
        return objectName;
    }
}

Hi All,

I am facing this issue.

Anyone have any idea how to solve this.

public void SaveChanges()
{
List<Account> AccountList = [Select Id, Name,(Select Id From Contacts) From Account where Id=:this.AccountId];


if(AccountList.size() > 0)
{
Account UpdateAccount = AccountList[0];
UpdateAccount.Name = this.Name;
UpdateAccount.AccountNumber = this.AccountNumber;
update UpdateAccount;

if(AccountList[0].Contacts.size() > 0)
{
Contact UserContact = AccountList[0].Contacts[0];
UserContact.FirstName = this.FirstName;
UserContact.LastName = this.LastName;
UserContact.Email = this.PersonalEmailId;
update UserContact;
}
else
{
Contact UserContact = new CanGeneral__c(AccountId = AccountList[0].Id,FirstName = this.FirstName,
LastName = this.LastName, Email = this.PersonalEmailId);
insert UserContact;
}
}
}