• anjali telikepalli
  • NEWBIE
  • 0 Points
  • Member since 2022

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

I'm wanting to remove currency, ID, and recordtypeid from my JSON file but I can't seem to find a way to remove them from the JSON file, Can someone advise where / What I need to be looking at to. Please see the code below.
 
public class JsonGenDispositionData {
    
    public String jsonString {set;get;}
    
    public static void gatherDispositionData(){
            
        List<stage_tracker__c> dispositionDataToSend = [SELECT Distribution_id__c,contact_status__c FROM Stage_Tracker__c WHERE Distribution_id__c != null LIMIT 3];
        List<Stage_tracker__c> payload = new list <Stage_Tracker__c>();
        
        // system.debug('Stage Trackers' + dispositionDataToSend);
        
        If(dispositionDataToSend.isempty()==false){
            JSONGenerator gen = JSON.createGenerator(true);
            for(Stage_Tracker__c ST : dispositionDataToSend){
                gen.writeStartArray();
                gen.writeStartObject();
                gen.writeStringField('DISTRIBUTION_ID', ST.Distribution_Id__c);
                gen.writeBooleanField('CONTACT_STATUS', ST.contact_status__c);
                gen.writeEndObject();
                gen.writeEndArray();
                payload.add(ST); 
            }
        }
        
        string jsonString = JSON.serialize(payload);
        system.debug(jsonString);
    }
    
}

My currnet output:
 
[{"attributes":{"type":"Stage_Tracker__c","url":"/services/data/v53.0/sobjects/Stage_Tracker__c/a5i3z000000UKNZAA4"},
"Distribution_Id__c":"8056fec2-b009-2cde-2d98-5f9ad4",
"contact_status__c":true,
"Id":"a5i3z000000UKNZAA4",
"RecordTypeId":"0123z000000gHwCAAU",
"CurrencyIsoCode":"GBP"}]
 I dont need the last 3 lines, (Id / RecordTypeId / CurrencyIsoCode)

How can I remove them.

Also any general code improvments would be welcomed.

Thanks
​​​​​​​
Hello all,

I am unable to insert more than 32 parameters in @httpPost method Please suggest me a better way in order to insert more parameters
Below Is my code:
@RestResource(urlMapping='/Students/*')
global with sharing class Studnets {

   
    
     @HttpPost
    global static String doPost(Integer Max,String ConcurrentAsyncGetReportInstances,String ConcurrentSyncReportRuns,Integer Max1,
    Integer Remaining,Integer Remaining1,String DailApiRequest,Integer DAPIRemaining,Integer DAPiMax,String Ant,Integer AntMax,
    Integer AntRemaining,String App,Integer AppMax,Integer AppRemaining,String DataloaderBulk,Integer DMax,Integer DRemaining,String DPartner,
    Integer DPMax,Integer DpRemaining,String FIde,Integer Fmax,Integer FRemaining,String SFMD,Integer SFMDMax,Integer SFMDRemaining,String SFTouch,Integer SFTMax,
    Integer SFTRemaining,Integer SFOMax,Integer SFORemaining,String SFOutlook)
     {
        System.debug('Entering in to APIUSAGE__c');
        APIUSAGE__c  st = new   APIUSAGE__c();
        st.ConcurrentAsync__c=ConcurrentAsyncGetReportInstances;
        st.ConcurrentSync__c=ConcurrentSyncReportRuns;
        st.Async_Max__c=Max;
        st.Max__c=Max1;
        st.SyncRemaining__c=Remaining;
        st.Async_Remaining__c=Remaining1;
        st.DailyApiRequests__c=DailApiRequest;
        st.DAPIRemaining__c=DAPIRemaining;
        st.DAPiMax__c=DAPiMax;
        st.Ant_Migration_Tool__c=Ant;
        st.Ant_Max__c=AntMax;
        st.Ant_Remaining__c=AntRemaining;
        st.App_Name__c=App;
        st.App_Max__c=AppMax;
        st.App_Remaining__c=AppRemaining;
        st.Dataloader_Bulk__c=DataloaderBulk;
        st.DMax__c=DMax;
        st.DRemaining__c=DRemaining;
        st.Dataloader_Partner__c=DPartner;
        st.DPMax__c=DPMax;
        st.DpRemaining__c=DpRemaining;
        st.ForceIDE__c=FIde;
        st.FMax__c=Fmax;
        st.FRemaining__c=FRemaining;
        st.SFMD__c=SFMD;
        st.SFMDMax__c=SFMDMax;
        st.SFMDRemaining__c=SFMDRemaining;
        st.SFTouch__c=SFTouch;
        st.SFTMax__c=SFTMax;
        st.SFTRemaining__c=SFTRemaining;
        st.SFOMax__c=SFOMax;
        st.SFOutlook__c=SFOutlook;
        st.SFORemaining__c=SFORemaining;
        
        
        
        insert st;
        return st.Id;
    }
    
    
 
}