• Rahul Kumar Dey
  • NEWBIE
  • 120 Points
  • Member since 2018
  • Developer
  • TCS


  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 40
    Replies
Hi All,

I haven't worked much on integrations so i would like to know what's the difference in these 2 syntaxes below in generating json, i personally feel they do the same thing but i would like to know the differences and any other pros and cons of both the approaches and when to use which approach.

Generating json :
Approach 1
JSONGenerator gen = JSON.createGenerator(true);
gen.writeStartObject();
gen.writeFieldName('Patient satisfaction');
gen.writeStartArray();
for (Patient_Satisfaction__c  patientSatisfaction : PrRecord) {
gen.writeStartObject();
gen.writeObjectField('First name', patientSatisfaction.Reporter_First_Name__c);
gen.writeObjectField('Last name', patientSatisfaction.Reporter_Last_Name__c);
gen.writeObjectField('Phone', patientSatisfaction.Reporter_Phone__c);
gen.writeObjectField('description', patientSatisfaction.Description_of_Feedback__c);gen.writeEndObject();
     } 
gen.writeEndArray();
gen.writeObjectField('incident_group_id',7387);
gen.writeObjectField('Name', 'TestAPI');
gen.writeEndObject();
//// This code snippet generates a json array

Approach2:
String jsonstr='{"Name":"'+ Accname +'","Phone":"'+ phone +'"}';

 Http h2= new Http();
//setting headers and other stuff required for callouts
//
//
req2.setBody(jsonstr);

            HttpResponse res2=h2.send(req2);
            System.debug(res2+'###1213createresp');
            deserializeResponse deresp2=(deserializeResponse)System.JSON.deserialize(res2.getBody(),deserializeResponse.class);



 
Hey guys, 

I try to create a validation rule where custom field ABN__c should be 14 character length if there are any spaces but if there is no space then it should be 11 characters length.

my validation as of now -
AND(NOT(ISBLANK(ABN__c)),
OR(LEN(ABN__c) != 14,
 AND(  NOT(REGEX( ABN__c,'[a-zA-Z-0-9- ]'))  ,LEN(ABN__c) != 11) )
)

Thanks in advance
Rahul:)
Hi All,

I have created a rest api webservice to insert contentVersion into salesforce but now I want to return the list of files to external system using rest api webservice. And I don't want to send exact files associated with case instead I want to send url so, external user can easily access  files from this url (list of url).
Any help how to proceed?
And any sample code really appreciate...


Best Regards,
Rahul 
Hi guys, 
I want to convert and REST API web-service synchronous to queable-
Here is the code which is perfectly worked for upload attachment upto 5.5 MB 64 encoded file. And I see in the document we can upload upto 12MB if this is in asynchronous in nature. 
 
@RestResource(urlMapping='/insertCaseWithAttachmentRestService/*')
global with sharing class insertCaseWithAttachmentRestAPI {
    //In this method we insert case with multiple attached files
   @httpPost
    global static Id insertCase(caseRequest req){
        Case caseObj = new Case();
        caseObj.Product__c = req.pdt;
        caseObj.Type = req.type;
        caseObj.Status = req.status;
        caseObj.Origin = req.origin;
        caseObj.Subject = req.subject;
        insert caseObj;
        system.debug('CaseId->>>>'+caseObj.Id);
        
        List<Attachment> attList = new List<Attachment>();
      
        for(attachmentRequest att : req.attList){
            attList.add(new Attachment(Name=att.attachmentName, 
                                      Body=EncodingUtil.base64Decode(att.blobString),
                                      ParentId=caseObj.Id
                                      ));
        }
        insert attList;
        
        return caseObj.Id;  
    }
    //Wrapper class
    global class caseRequest{
        String pdt {get; set;}
        String type {get; set;}
        String status {get; set;}
        String origin {get; set;}
        String subject {get; set;}
        
        List<attachmentRequest> attList {get; set;}
    }
    global class attachmentRequest{
        String attachmentName {get; set;}
        String blobString {get; set;}
    }
}

Any help to convert this into queueable interface?

Thanks in advance
Hi guys,

I want to insert attachments and combine this attachments with custom object 'Grade__c' in related list using Rest API web service.
I have created webservice which insert Grade object records but unable to insert attachment at same record-

Here is my code -
@RestResource(urlMapping='/UploadAttachmentRestService/*')
global with sharing class UploadAttachmentRestAPI {
    //In this method we insert custom object(Grade__c) records with attachments, comes from response body
    @httpPost
    global static Id insertGrade(String dt, Integer score, String name){
        Grade__c gradeObj = new Grade__c();
        gradeObj.Date__c = dt;
        gradeObj.Score__c = score;
        gradeObj.Name = name;
        
        insert gradeObj;
        system.debug('Grade ID->>>>'+gradeObj.Id);
        return gradeObj.Id;
       
    }

request body that i pass from workbench -
{
   "dt":"2016-12-10", 
   "score":9876, 
   "name":"Test Grade"
}

And the 'Test Grade' will Inserted.

any solution for attachment part, much appreciate.

Regards,
Rahul 
Hi guys , can anyone share me the recruiting app .pdf file, I am unable to get this file because Salesforce site says me this document retaired... Email: deyrahul.7687@gmail.com
Thaks & Regards, 
Rahul
Hey guys, 

I try to create a validation rule where custom field ABN__c should be 14 character length if there are any spaces but if there is no space then it should be 11 characters length.

my validation as of now -
AND(NOT(ISBLANK(ABN__c)),
OR(LEN(ABN__c) != 14,
 AND(  NOT(REGEX( ABN__c,'[a-zA-Z-0-9- ]'))  ,LEN(ABN__c) != 11) )
)

Thanks in advance
Rahul:)
Hi All,

I have created a rest api webservice to insert contentVersion into salesforce but now I want to return the list of files to external system using rest api webservice. And I don't want to send exact files associated with case instead I want to send url so, external user can easily access  files from this url (list of url).
Any help how to proceed?
And any sample code really appreciate...


Best Regards,
Rahul 
Hi guys, 
I want to convert and REST API web-service synchronous to queable-
Here is the code which is perfectly worked for upload attachment upto 5.5 MB 64 encoded file. And I see in the document we can upload upto 12MB if this is in asynchronous in nature. 
 
@RestResource(urlMapping='/insertCaseWithAttachmentRestService/*')
global with sharing class insertCaseWithAttachmentRestAPI {
    //In this method we insert case with multiple attached files
   @httpPost
    global static Id insertCase(caseRequest req){
        Case caseObj = new Case();
        caseObj.Product__c = req.pdt;
        caseObj.Type = req.type;
        caseObj.Status = req.status;
        caseObj.Origin = req.origin;
        caseObj.Subject = req.subject;
        insert caseObj;
        system.debug('CaseId->>>>'+caseObj.Id);
        
        List<Attachment> attList = new List<Attachment>();
      
        for(attachmentRequest att : req.attList){
            attList.add(new Attachment(Name=att.attachmentName, 
                                      Body=EncodingUtil.base64Decode(att.blobString),
                                      ParentId=caseObj.Id
                                      ));
        }
        insert attList;
        
        return caseObj.Id;  
    }
    //Wrapper class
    global class caseRequest{
        String pdt {get; set;}
        String type {get; set;}
        String status {get; set;}
        String origin {get; set;}
        String subject {get; set;}
        
        List<attachmentRequest> attList {get; set;}
    }
    global class attachmentRequest{
        String attachmentName {get; set;}
        String blobString {get; set;}
    }
}

Any help to convert this into queueable interface?

Thanks in advance
Hi guys,

I want to insert attachments and combine this attachments with custom object 'Grade__c' in related list using Rest API web service.
I have created webservice which insert Grade object records but unable to insert attachment at same record-

Here is my code -
@RestResource(urlMapping='/UploadAttachmentRestService/*')
global with sharing class UploadAttachmentRestAPI {
    //In this method we insert custom object(Grade__c) records with attachments, comes from response body
    @httpPost
    global static Id insertGrade(String dt, Integer score, String name){
        Grade__c gradeObj = new Grade__c();
        gradeObj.Date__c = dt;
        gradeObj.Score__c = score;
        gradeObj.Name = name;
        
        insert gradeObj;
        system.debug('Grade ID->>>>'+gradeObj.Id);
        return gradeObj.Id;
       
    }

request body that i pass from workbench -
{
   "dt":"2016-12-10", 
   "score":9876, 
   "name":"Test Grade"
}

And the 'Test Grade' will Inserted.

any solution for attachment part, much appreciate.

Regards,
Rahul 
How to get all the SObjects fields and datatype in single table in an org
Hi All,

I haven't worked much on integrations so i would like to know what's the difference in these 2 syntaxes below in generating json, i personally feel they do the same thing but i would like to know the differences and any other pros and cons of both the approaches and when to use which approach.

Generating json :
Approach 1
JSONGenerator gen = JSON.createGenerator(true);
gen.writeStartObject();
gen.writeFieldName('Patient satisfaction');
gen.writeStartArray();
for (Patient_Satisfaction__c  patientSatisfaction : PrRecord) {
gen.writeStartObject();
gen.writeObjectField('First name', patientSatisfaction.Reporter_First_Name__c);
gen.writeObjectField('Last name', patientSatisfaction.Reporter_Last_Name__c);
gen.writeObjectField('Phone', patientSatisfaction.Reporter_Phone__c);
gen.writeObjectField('description', patientSatisfaction.Description_of_Feedback__c);gen.writeEndObject();
     } 
gen.writeEndArray();
gen.writeObjectField('incident_group_id',7387);
gen.writeObjectField('Name', 'TestAPI');
gen.writeEndObject();
//// This code snippet generates a json array

Approach2:
String jsonstr='{"Name":"'+ Accname +'","Phone":"'+ phone +'"}';

 Http h2= new Http();
//setting headers and other stuff required for callouts
//
//
req2.setBody(jsonstr);

            HttpResponse res2=h2.send(req2);
            System.debug(res2+'###1213createresp');
            deserializeResponse deresp2=(deserializeResponse)System.JSON.deserialize(res2.getBody(),deserializeResponse.class);



 
I'm new in apex I tried my best. Here is my requirement We are sending a Post request to External system and we want salesforce fields to go to external system along with external system required fields(Name and Incident_group_id). I'm not able to conctenate Salesforce fields along with external system required field in Json format. Not sure what is wrong in the code. I'm calling this code in trigger. sorry for messy code, still trying to figure out apex. It doesn't send Json object (Patient satisfaction) it just sends incident_group_id and Name(both external system fields)

public class RadarUpdate {
@future (callout=true)
public static void postcallout(string id) { 
List<Patient_Satisfaction__c> PrIds = new list<Patient_Satisfaction__c>();
List<Patient_Satisfaction__c> PrRecord  = [select id, Name, Reporter_First_Name__c, Reporter_Last_Name__c, 
Reporter_Phone__c, Description_of_Feedback__c from Patient_Satisfaction__c where id IN :PrIds ] ;
JSONGenerator gen = JSON.createGenerator(true);
gen.writeStartObject();
gen.writeFieldName('Patient satisfaction');
gen.writeStartArray();
for (Patient_Satisfaction__c  patientSatisfaction : PrRecord) {
gen.writeStartObject();
gen.writeObjectField('First name', patientSatisfaction.Reporter_First_Name__c);
gen.writeObjectField('Last name', patientSatisfaction.Reporter_Last_Name__c);
gen.writeObjectField('Phone', patientSatisfaction.Reporter_Phone__c);
gen.writeObjectField('description', patientSatisfaction.Description_of_Feedback__c);gen.writeEndObject();
     } 
gen.writeEndArray();
gen.writeObjectField('incident_group_id',7387);
gen.writeObjectField('Name', 'TestAPI');
gen.writeEndObject();
String jsonS = gen.getAsString();
System.debug('jsonMaterials'+jsonS);
  
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://api.radarfirst.com/incidents');
request.setMethod('POST');
request.setHeader('Content-Type','application/json;charset=UTF-8');
request.setHeader('User-agent', 'Salesforce-integration-client');
request.setHeader('Authorization','Bearer abc');
request.setBody(jsonS);
// Set the body as a JSON object
HttpResponse response = http.send(request);
if (response.getStatusCode() != 422) {
System.debug('The status code returned was not expected: ' +
response.getStatusCode() + ' ' + response.getStatus());
} else {
System.debug(response.getBody());
}
}
}
 
Question about design patterns for Lighting Aura components.  I'm working on a feature that will have some nested components.  Like a main component, a couple components that manage lists, and a couple components that present an item for the list.

The main component will have a back-end Apex controller in Apex. 

Is the best patern to also declare some of the inner components to have their own Apex.  For example, list component would call their controller to get data.   

Or would be be better for the inner components to always use the controller for the main component, and if so, is there a example of a coding pattern for doing so?

I seem to remember a lecture on Lightning Aura components when they were new covering this topic and having examples but since it was a couple years ago, I don't recall where I saw it.
Hi,

As I am able to update on single records but not working when its on bulk.

here is my code///
public class UpdateActivityHistoryCallCount {
    
    
    //To update the Count of Activity History in Lead object
    
    public static void countActivityHistoryOnLead(list<Task> newTaskList,list<Task> oldTaskList){
        set<Id> LeadIds=new set<Id>();
        list<Lead> leadList=new list<Lead>();
        Map<Id, String> error = new Map<Id, String>();
        
        if(trigger.isInsert || trigger.isUnDelete || trigger.isUpdate){
            for(Task tsk:newTaskList){
                if(string.valueOf(tsk.WhoId).startsWith('00Q'))
                    LeadIds.add(tsk.WhoId);
                
            }
        }
        if(trigger.isDelete || trigger.isUpdate){
            for(Task tk:oldTaskList){
                if(string.valueOf(tk.WhoId).startsWith('00Q'))
                    LeadIds.add(tk.whoId);
                
            }
        }
        if(LeadIds.size()>0){
            for(Lead l:[select id,(select id,subject,Due_Date__c,CreatedDate
                                   from tasks where (subject='Call' and status='Completed'
                                                     and  Due_Date__c < Today) or (subject='Call' and status='Completed' and Due_Date__c =  null)  ) 
                        from lead where id in :LeadIds limit 50000])
                leadList.add(new lead(id=l.Id,Call_count__c=l.tasks.size()));
            
            
        }
        Database.SaveResult[] results= database.update (leadList,false);
        system.debug('@@@@' +results);
        
    }
    
}

Thanks
Hey,

I'm developing a lightning:datatable which supports the inline editing and multiselect functionality, however this doesn't seem to work with date or datetime.

Example:
My Datatable:
<lightning:datatable aura:id="relatedDataTable" columns="{!v.FieldList}" data="{!v.RecordsPage}"
                    keyField="Id" draftValues="{!v.draftValues}" onsave="{!c.handleSave}" oncancel="{!c.handleCancel}"
                    oncellchange="{!c.handleEdit}" sortedBy="{!v.sortedBy}" sortedDirection="{!v.sortedDirection}"
                    defaultSortDirection="{!v.defaultSortDirection}" onsort="{!c.updateColumnSorting}" onrowaction="{!c.handleRowAction}"
                    onrowselection="{!c.updateSelectedRow}" rowNumberOffset="{!v.rowOffset}" showRowNumberColumn="true" />
Example date column:
{fieldName:'Date__c', type:'date-local', label:'Date', sortable:true, editable:true}
The following happens:
The moment you try to check the "Update 3 selected items", the popup disappears and you are unable to set a date. It doesn't matter which order you try it. If you try to first set a date then check the checkbox the box disappears without posting the changes to the datatable. I have a feeling this has something to do with the way "focus" works on the date input. Even if you click right next to the date input, as soon as the input field loses focus, the box closes. the image below shows the scenario.

Does anybody know a solution to this? If this is a bug with the lightning:datatable, how do i notify Salesforce of this issue.
Lightning:datatable date multi edit



 
I have a lightning component that implements lightning:actionOverride how do I get the recordId of the parent when the action is triggered from a related list?