• Harish GAADE 2
  • NEWBIE
  • 25 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 2
    Replies
Hi All,

i have created the  before trigger when ever  record is created it deserialze the json and get "commentValue" and store "commentValue" into text field .
But i have change her in below JSON we have two "commentValue" 
as per my trigger it will take only one "commentValue" .
but my requriment have store the both commentValue with comma sperated.
example:-
my commetValue in below json are "commentValue":"My prod comments", "commentValue":"My prod comments2"
output should be:- My prod comments,My prod comments2.
Can one help on this how to achevie this requriment.

JSON string:-
[{"productName":"Actemra - Moderate to Severe Active RA",
 "objectives:[{"picklistValueId":"a6L2F0000005g5vUAA",
               "picklistValueLabel":"Discuss ACT TAPER      to support Mono message",
                "commentValue":"My prod comments"},
              {"picklistValueId":"a6L2F0000005g5qUAA",
               "picklistValueLabel":"Discuss commercial meeting options",
                "commentValue":"My prod comments2"}]}]
Trigger:-
trigger RCH_NextCallProductObjJosonText on OCE__Call__c (before insert) {
    
         Map<String,Boolean> metaDataMap=new Map<String,Boolean>();
     for(RCH_TriggerHandler__mdt eachMetaData:[SELECT Id,RCH_HandlerName__c,RCH_IsActive__c FROM RCH_TriggerHandler__mdt WHERE RCH_Type__c='OCE__Call__c'])
        metaDataMap.put(eachMetaData.RCH_HandlerName__c,eachMetaData.RCH_IsActive__c);
    if( metaDataMap.get('RCH_NextCallProductObjJosonTextHandler')== true && (Trigger.isinsert) && Trigger.isBefore){
        RCH_NextCallProductObjJosonTextHandler nextcallproductjoson = new RCH_NextCallProductObjJosonTextHandler();
        nextcallproductjoson.convertthejosontotext(Trigger.New);
    }
}

trigger Handler
public class RCH_NextCallProductObjJosonTextHandler {
  String inputJSON;
  String CommentValue;
  
  string newvlaues ='Test name';
  public static boolean isExecuted = True;
    Map<string,OCE__Call__c> josonmap =new Map<string,OCE__Call__c>();
    list<OCE__Call__c> updatecallrecords = New list<OCE__Call__c>();
   public void convertthejosontotext(list<OCE__Call__c> scope){
     
       list<OCE__Call__c> updatecallrecords =New  list<OCE__Call__c>();
       Map<id,OCE__Call__c> mapcallrecord = new map<id,OCE__Call__c>();
       Map<String, Object> m = new map<String, Object>();
       Map<String, Object>m1 = new map<String, Object>();
     // list<Map<String, Object>>m1 = new map<String, Object>();
       Map<String, Object> m2 = new map<String, Object>();
       for(OCE__Call__c ca:scope){
           inputJSON = ca.OCE__NextCallProductObjectives__c;
           system.debug('inputJSON!'+inputJSON);
            if(inputJSON !=null && inputJSON !='[]'){
                system.debug('input Json ---->'+inputJSON);
                List<Object> inputLst = (List<Object>)JSON.deserializeUntyped(inputJSON); 
                system.debug('input List ---->'+inputLst);
                for(Object ip : inputLst) { 
               		m = (Map<String,Object>)ip;
                }
                system.debug('m ---->'+m);
               List<Object> l1 = (List<Object>)m.get('objectives');
               system.debug('l1---->'+l1);
                for(Object obj1 : l1) { 
               		m1 = (Map<String, Object>)obj1;
                }
                CommentValue =string.valueof(m1.get('commentValue'))+','+string.valueof(m2.get('commentValue'));
                system.debug('CommentValue!' +CommentValue);
                ca.RCH_NextInteractionProductObjective__c = CommentValue;
                system.debug('ca.RCH_NextInteractionProductObjective__c!' +ca.RCH_NextInteractionProductObjective__c);
               
           }
       }
   }
}

​​​​​​​
 
Hi All,

I have a requriment we have to created the Lightning page where i can get the text fields of all the objects  in records in table view .

And we need to have filter also so we can show/get the record only 24hours/2days/1 week/all records 

And we can able to edit the records and save the records back to database and also if user click on Export button we can  Export the records in to Excel File.

above is my requriment. Can any one help on this how to start as i new to lightning .



 
Hi All,
Handler and test class i am unable to cover the lines in below classs.
Can any on help on this.
Database.SaveResult[] lsr = Database.insert(jobShrs,false); // Create counter Integer i=0; // Process the save results for(Database.SaveResult sr : lsr){ if(!sr.isSuccess()){ // Get the first save result error Database.Error err = sr.getErrors()[0]; // Check if the error is related to a trivial access level // Access levels equal or more permissive than the object's default // access level are not allowed. // These sharing records are not required and thus an insert exception is // acceptable. if(!(err.getStatusCode() == StatusCode.FIELD_FILTER_VALIDATION_EXCEPTION && err.getMessage().contains('AccessLevel'))){ // Throw an error when the error is not related to trivial access level. trigger.newMap.get(jobShrs[i].ParentId). addError( 'Unable to grant sharing access due to following exception: ' + err.getMessage()); } }
Class:-
public class RCH_AAQReturnMailSharingHandler {
    // Create a new list of sharing objects for Job
     public void createSharingRecords(List<OCE__Askaquestion__c> newAAQlist){
        List<OCE__Askaquestion__Share> jobShrs  = new List<OCE__Askaquestion__Share>();
        
        // Declare variables for User for which record has to be shared.
        OCE__Askaquestion__Share userShr;
        ID ReturnMailRecTypeID = Schema.SObjectType.OCE__Askaquestion__c.getRecordTypeInfosByName().get('Returned Mail').getRecordTypeId(); 
        
        for(OCE__Askaquestion__c job : newAAQlist){
            if (job.RecordTypeid == ReturnMailRecTypeID ){
            // Instantiate the sharing objects
            userShr = new OCE__Askaquestion__Share();          
            // Set the ID of record being shared
            userShr.ParentId = job.Id;           
            // Set the ID of user or group being granted access
            userShr.UserOrGroupId = job.RCH_User__c;        
            // Set the access level
            userShr.AccessLevel = 'edit';
            // Add objects to list for insert
            jobShrs.add(userShr);
        }
        }
         

        // Insert sharing records and capture save result 
        // The false parameter allows for partial processing if multiple records are passed 
        // into the operation 
        Database.SaveResult[] lsr = Database.insert(jobShrs,false);
        
        // Create counter
        Integer i=0;
        
        // Process the save results
        for(Database.SaveResult sr : lsr){
            if(!sr.isSuccess()){
                // Get the first save result error
                Database.Error err = sr.getErrors()[0];
                
                // Check if the error is related to a trivial access level
                // Access levels equal or more permissive than the object's default 
                // access level are not allowed. 
                // These sharing records are not required and thus an insert exception is 
                // acceptable. 
                if(!(err.getStatusCode() == StatusCode.FIELD_FILTER_VALIDATION_EXCEPTION  
                                               &&  err.getMessage().contains('AccessLevel'))){
                    // Throw an error when the error is not related to trivial access level.
                    trigger.newMap.get(jobShrs[i].ParentId).
                      addError(
                       'Unable to grant sharing access due to following exception: '
                       + err.getMessage());
                }
            }
            i++;
        }  
}
}
Test class:-
 
@isTest
public class RCH_AAQReturnMailSharingHandler_TC {    
   // Test for the manualShareRead method
   private static testMethod void testManualShareRead(){
      User adminUser =RCH_TestUtils.createUser([select id from Profile where Name = 'OCE Admin Archetype 2'].Id);
      insert adminUser;
      User salesRepUser =RCH_TestUtils.createUser([select id from Profile where Name = 'Sales Representative Archetype 2'].Id);
      insert salesRepUser;      
      Test.startTest();
          // Create new job.
          System.runAs(adminUser){
              OCE__Askaquestion__c askAQuestionRecord = new OCE__Askaquestion__c(RCH_User__c=salesRepUser.Id,Recordtypeid=Schema.SObjectType.OCE__AskAQuestion__c.getRecordTypeInfosByName().get('Returned Mail').getRecordTypeId());
              askAQuestionRecord.Name = 'Test Job';      
              insert askAQuestionRecord;    
          }
      
           OCE__Askaquestion__c aaqRecord = [select id from OCE__Askaquestion__c limit 1];
          // Query job sharing records.
          List<OCE__Askaquestion__Share> jShrs = [SELECT Id, UserOrGroupId, AccessLevel FROM OCE__Askaquestion__Share WHERE ParentId = :aaqRecord.Id];      
          System.Assert(jShrs.size()>1,'AAQ Record is not shared to Rep' );
      Test.stopTest(); 
   } 

}

 
Hi All,

Can any one help on below test class . i am new to salesforce.
 Apex class
public class RCH_PeerLoginAndCallCreation {
    String callID;
    public string errMsg{get;set;}
    public RCH_PeerLoginAndCallCreation (){
        CallID=ApexPages.currentPage().getParameters().get('ID'); 
        errMsg='';
    }
    
     public PageReference SendCallInfoToPeer(){//List<OCE__Call__c> callList
        PageReference pageRef;
        try{
                OCE__Call__c  call = [Select ID,OCE__Account__c,CreatedById,OCE__CallAddress__c,OCE__CallDateTime__c,RCH_PEER_ID__c,CreatedBy.FederationIdentifier from OCE__Call__c where Id=:callID]; 
                if(call.RCH_PEER_ID__c!=null){
                    pageRef = new PageReference(Label.RCH_Peer_EndPoint_URL+'/apex/activity_peer?id='+call.RCH_PEER_ID__c);
                    pageRef.setRedirect(true);   
                    return pageRef;
                }
                RCH_PeerGetUsername getpeerUserhandler = new RCH_PeerGetUsername();    
                String peerUsername=getpeerUserhandler.getUserName(call.CreatedBy.FederationIdentifier);
                RCH_SAMLBearerAssertion samlBearer = new RCH_SAMLBearerAssertion(peerUsername);
                String access_token = samlBearer.postSAML();
                String AccountName = [select Name,ID from Account where ID=:call.OCE__Account__c].Name;
                User createdUser = [select Name,ID,Country from User where ID=:call.CreatedById];
                String activityTitle = 'Call with '+AccountName +' at '+call.OCE__CallAddress__c;
            	activityTitle = activityTitle.replaceAll('[^a-zA-Z0-9\\s+]', '').left(80);            	
                String endDate = call.OCE__CallDateTime__c.format('yyyy-MM-dd');  
                String startDate = call.OCE__CallDateTime__c.format('yyyy-MM-dd');         
                String country = createdUser.Country;
                String  isPeer  = 'true';
                String CreatedBy = createdUser.Name;                
                String callJSONString = '{"oceCallId":"'+CallID+'","activityTitle":"'+activityTitle+'","startDate":"'+startDate+'","endDate":"'+endDate+'","countryISOCode":"'+Country+'"}' ;             
                Http peerHttp= new Http();
                HttpRequest peerHTTPreq= new HttpRequest();
                peerHTTPreq.setHeader('Authorization','OAuth ' + access_token );           
                peerHTTPreq.setHeader('Content-Type','application/json');
                peerHTTPreq.setHeader('accept','application/json');
                peerHTTPreq.setBody(callJSONString);
                peerHTTPreq.setMethod('POST');
                peerHTTPreq.setTimeOut(120000);
                peerHTTPreq.setEndpoint(Label.RCH_Peer_EndPoint_URL+Label.RCH_Peer_REST_URL);
                HttpResponse peerResponse;            
                peerResponse = peerHttp.send(peerHTTPreq);
                if(peerResponse!=null){
                    resultResponse peerActivityResponse=(resultResponse)JSON.deserialize(peerResponse.getBody(),resultResponse.class);                    
                    call.RCH_PEER_ID__c=(String)peerActivityResponse.crmId;
                        update call;
                   if(peerActivityResponse.success==true){
                        pageRef = new PageReference(Label.RCH_Peer_EndPoint_URL+'/apex/activity_peer?id='+(String)peerActivityResponse.crmId);
                        pageRef.setRedirect(true);
                    }
                   else{
                        pageRef=null;
                        string tempErrMsg='';
                        for(Map<string,string> errMsgMap:peerActivityResponse.errors){
                            for(string errMsgVal:errMsgMap.values()){
                                tempErrMsg=errMsgVal;
                                if(tempErrMsg.endsWith(')'))
                                    tempErrMsg=tempErrMsg.removeEnd(')');
                                if(tempErrMsg.startsWith('('))
                                    tempErrMsg=tempErrMsg.removeEnd('(');
                                errMsg+=tempErrMsg+' ';
                            }
                        }
                   }
                }
         }Catch(Exception e){
             errMsg='An error has occured please contact your System Administrator';
             system.debug('An error has occured===>'+e.getMessage());
             pageRef=null;
         }
        return pageRef;
    }
     public class deserializeResponse{
        public String id;
        public Boolean success;
        public String access_token;   
    } 
    public class resultResponse{
        public String crmId;
        public Boolean success;
        public String url;   
        public List<Map<String, String>> errors;
    } 
}
----

test class 
@isTest
public class RCH_PeerLoginAndCallCreation_TC {
    @testSetup
    private static void setUp(){
        Account customerProfile = RCH_TestUtils.createCustomerProfile();
        insert customerProfile;
        List<OCE__Call__c> callList=new List<OCE__Call__c>();
        OCE__Call__c callInstance1=RCH_TestUtils.createCustomerProfilePeerCall(customerProfile);
        callList.add(callInstance1);
        OCE__Call__c callInstance2=RCH_TestUtils.createCustomerProfilePeerCall(customerProfile);
        callInstance2.OCE__Account__c=null;
        callList.add(callInstance2);
        insert callList;
    }
    static testMethod void peerIntegrationMethod(){
        List<OCE__Call__c> callList=[select Id from OCE__Call__c limit 2];
        Test.startTest();
            ApexPages.currentPage().getParameters().put('ID',callList[0].id);
            RCH_PeerLoginAndCallCreation peerObj=new RCH_PeerLoginAndCallCreation();
            peerObj.SendCallInfoToPeer();
            ApexPages.currentPage().getParameters().put('ID',callList[1].id);
            peerObj=new RCH_PeerLoginAndCallCreation();
            peerObj.SendCallInfoToPeer();
        Test.stopTest();
    }
    static testMethod void redirectTOPeerMethod(){
        List<OCE__Call__c> callList=[select Id from OCE__Call__c limit 1];
        callList[0].RCH_PEER_ID__c = 'Peer ID';
        update callList;
        Test.startTest();
            ApexPages.currentPage().getParameters().put('ID',callList[0].id);
            RCH_PeerLoginAndCallCreation peerObj=new RCH_PeerLoginAndCallCreation();
            peerObj.SendCallInfoToPeer();
            
        Test.stopTest();
    }
}

thank you
Hi All,
I am new to salesfroce can any on help on trigger which i have worte.
trigger RCH_ContentDocumentLinkTrigger on ContentDocumentLink (before insert) {
If(trigger.isinsert && trigger .isBefore){
}
RCH_ContentDocumentLinkMIRFHandler CDLH = new RCH_ContentDocumentLinkMIRFHandler();
        CDLH.BlockUploadFile(trigger.new);

}

Handler
public class RCH_ContentDocumentLinkMIRFHandler {

    public void BlockUploadFile(list<ContentDocumentLink> CDLNewlist){
        Map<Id,OCE__MedicalInquiryRequest__c> MedicalInquirylist = new Map<Id,OCE__MedicalInquiryRequest__c>();

     for(ContentDocumentLink CDL: CDLNewlist){
        if(CDL.LinkedEntityId.getSobjectType() == OCE__MedicalInquiryRequest__c.SobjectType){
            MedicalInquirylist.put(CDL.LinkedEntityId,null);
        }
    }
    
    List<OCE__MedicalInquiryRequest__c> MedicalInREQlist=[select id, name,RCH_ParentIDCheckbox__c from OCE__MedicalInquiryRequest__c where id in:MedicalInquirylist.keySet()];
    if(MedicalInREQlist.size()>0){
    for(OCE__MedicalInquiryRequest__c MIR: MedicalInREQlist){
        
        for(ContentDocumentLink CDL: CDLNewlist){
            if(MIR.RCH_ParentIDCheckbox__c != True){
                 
                CDL.addError('Cannot upload files from here..');
            }
        }
       
        }
    }
    
    }
}

My trigger is working fine but develp​​​​​oper told me even though  its working but it is not write.
And he told me i should  not use outer for loop.
for(OCE__MedicalInquiryRequest__c MIR: MedicalInREQlist){
        
        for(ContentDocumentLink CDL: CDLNewlist){
            if(MIR.RCH_ParentIDCheckbox__c != True){
                 
                CDL.addError('Cannot upload files from here..');
            }
        }

 
Hi All,
I am not able to finish this requriment can any on help on this 

my requriment is user should not upload files through Notes &attachments which is in related list of parent object it because user only  attach document at the time  parent record is created so we have created lighting component for uploading the documents but user can upload the document in related lsit we don't wanted allow the users to upload.
can any one give me the suggestion how to achive this requirment/complete .
Or any one done this requriment
but i tried to through trigger through error message on related list page but it is not happening are we can't achive through trigger can any on help
User-added image
Hi All,
I am new to salesfroce can any on help on trigger which i have worte.
trigger RCH_ContentDocumentLinkTrigger on ContentDocumentLink (before insert) {
If(trigger.isinsert && trigger .isBefore){
}
RCH_ContentDocumentLinkMIRFHandler CDLH = new RCH_ContentDocumentLinkMIRFHandler();
        CDLH.BlockUploadFile(trigger.new);

}

Handler
public class RCH_ContentDocumentLinkMIRFHandler {

    public void BlockUploadFile(list<ContentDocumentLink> CDLNewlist){
        Map<Id,OCE__MedicalInquiryRequest__c> MedicalInquirylist = new Map<Id,OCE__MedicalInquiryRequest__c>();

     for(ContentDocumentLink CDL: CDLNewlist){
        if(CDL.LinkedEntityId.getSobjectType() == OCE__MedicalInquiryRequest__c.SobjectType){
            MedicalInquirylist.put(CDL.LinkedEntityId,null);
        }
    }
    
    List<OCE__MedicalInquiryRequest__c> MedicalInREQlist=[select id, name,RCH_ParentIDCheckbox__c from OCE__MedicalInquiryRequest__c where id in:MedicalInquirylist.keySet()];
    if(MedicalInREQlist.size()>0){
    for(OCE__MedicalInquiryRequest__c MIR: MedicalInREQlist){
        
        for(ContentDocumentLink CDL: CDLNewlist){
            if(MIR.RCH_ParentIDCheckbox__c != True){
                 
                CDL.addError('Cannot upload files from here..');
            }
        }
       
        }
    }
    
    }
}

My trigger is working fine but develp​​​​​oper told me even though  its working but it is not write.
And he told me i should  not use outer for loop.
for(OCE__MedicalInquiryRequest__c MIR: MedicalInREQlist){
        
        for(ContentDocumentLink CDL: CDLNewlist){
            if(MIR.RCH_ParentIDCheckbox__c != True){
                 
                CDL.addError('Cannot upload files from here..');
            }
        }

 
Hi All,
I am not able to finish this requriment can any on help on this 

my requriment is user should not upload files through Notes &attachments which is in related list of parent object it because user only  attach document at the time  parent record is created so we have created lighting component for uploading the documents but user can upload the document in related lsit we don't wanted allow the users to upload.
can any one give me the suggestion how to achive this requirment/complete .
Or any one done this requriment
but i tried to through trigger through error message on related list page but it is not happening are we can't achive through trigger can any on help
User-added image