• George Laird 29
  • NEWBIE
  • 30 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 3
    Replies
Hello All,

I've got an interesting use case here.  I've got an approval process built out on Opportunities.  One of the managers wants an email anytime something is approved or rejected but only if the Oppty was created by one of the people on her team.  Otherwise she doesn't want an email at all.  

Any ideas on how to do this?  In the approval process itself, I don't see a way to send an email alert based on a criteria.   I know that I could create some formula field like a checkbox to return 'true' if the record was created by someone on her team, but I don't see a way to fire of an Approval Action based off a criteria. 

So maybe a trigger then on approval?  If so, what object would by trigger be on?  

Thanks in advance everyone!
George


 
Hello,

I am sending a PDF to a company to parse out the fields through a callout.  It's working about 43% of the time, but what is happening is that somehting in my code is corrupting some of the file.  It's turning some of the PDF green in transit and messing it all up.  

What happned is that I found some sample code from a different company called Docparser who does the same service.  I wish my company would have gone through them, but they didn't.  Big mistake.  Sorry Docparser, but I wish i went with you guys. 

So, I started by using their code.  It didn't work with this other compnay at all.  So then I found some new code online that was meant to address some of the curruption issues. 

Here is that code:

public static void uploadFile(Blob file_body, String file_name, String reqEndPoint){
      // Repost of code  with fix for file corruption issue
      // Orignal code postings and explanations
      // http://enreeco.blogspot.in/2013/01/salesforce-apex-post-mutipartform-data.html
      // http://salesforce.stackexchange.com/questions/24108/post-multipart-without-base64-encoding-the-body
      // Additional changes commented GW: that fix issue with occasional corruption of files
      String boundary = '----------------------------741e90d31eff';
      String header = '--'+boundary+'\nContent-Disposition: form-data; name="file"; filename="'+file_name+'";\nContent-Type: application/octet-stream';
      // GW: Do not prepend footer with \r\n, you'll see why in a moment
      // String footer = '\r\n--'+boundary+'--';
      String footer = '--'+boundary+'--';            
      String headerEncoded = EncodingUtil.base64Encode(Blob.valueOf(header+'\r\n\r\n'));
      while(headerEncoded.endsWith('='))
      {
       header+=' ';
       headerEncoded = EncodingUtil.base64Encode(Blob.valueOf(header+'\r\n\r\n'));
      }
      String bodyEncoded = EncodingUtil.base64Encode(file_body);
      // GW: Do not encode footer yet
      // String footerEncoded = EncodingUtil.base64Encode(Blob.valueOf(footer));
 
      Blob bodyBlob = null;
      String last4Bytes = bodyEncoded.substring(bodyEncoded.length()-4,bodyEncoded.length());
 
      // GW: Replacing this entire section
      /*
      if(last4Bytes.endsWith('='))
      {
           Blob decoded4Bytes = EncodingUtil.base64Decode(last4Bytes);
           HttpRequest tmp = new HttpRequest();
           tmp.setBodyAsBlob(decoded4Bytes);
           String last4BytesFooter = tmp.getBody()+footer;  
           bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded.substring(0,bodyEncoded.length()-4)+EncodingUtil.base64Encode(Blob.valueOf(last4BytesFooter)));
      }
      else
      {
            bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+footerEncoded);
      }
      */
     // GW: replacement section to get rid of padding without corrupting data
     if(last4Bytes.endsWith('==')) {
        // The '==' sequence indicates that the last group contained only one 8 bit byte
        // 8 digit binary representation of CR is 00001101
        // 8 digit binary representation of LF is 00001010
        // Stitch them together and then from the right split them into 6 bit chunks
        // 0000110100001010 becomes 0000 110100 001010
        // Note the first 4 bits 0000 are identical to the padding used to encode the
        // second original 6 bit chunk, this is handy it means we can hard code the response in
        // The decimal values of 110100 001010 are 52 10
        // The base64 mapping values of 52 10 are 0 K
        // See http://en.wikipedia.org/wiki/Base64 for base64 mapping table
        // Therefore, we replace == with 0K
        // Note: if using \n\n instead of \r\n replace == with 'oK'
        last4Bytes = last4Bytes.substring(0,2) + '0K';
        bodyEncoded = bodyEncoded.substring(0,bodyEncoded.length()-4) + last4Bytes;
        // We have appended the \r\n to the Blob, so leave footer as it is.
        String footerEncoded = EncodingUtil.base64Encode(Blob.valueOf(footer));
        bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+footerEncoded);
      } else if(last4Bytes.endsWith('=')) {
        // '=' indicates that encoded data already contained two out of 3x 8 bit bytes
        // We replace final 8 bit byte with a CR e.g. \r
        // 8 digit binary representation of CR is 00001101
        // Ignore the first 2 bits of 00 001101 they have already been used up as padding
        // for the existing data.
        // The Decimal value of 001101 is 13
        // The base64 value of 13 is N
        // Therefore, we replace = with N
        // Note: if using \n instead of \r replace = with 'K'
        last4Bytes = last4Bytes.substring(0,3) + 'N';
        bodyEncoded = bodyEncoded.substring(0,bodyEncoded.length()-4) + last4Bytes;
        // We have appended the CR e.g. \r, still need to prepend the line feed to the footer
        footer = '\n' + footer;
        String footerEncoded = EncodingUtil.base64Encode(Blob.valueOf(footer));
        bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+footerEncoded);             
      } else {
        // Prepend the CR LF to the footer
        footer = '\r\n' + footer;
        String footerEncoded = EncodingUtil.base64Encode(Blob.valueOf(footer));
        bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+footerEncoded); 
      }
 
      HttpRequest req = new HttpRequest();
      req.setHeader('Content-Type','multipart/form-data; boundary='+boundary);
      req.setMethod('POST');
      req.setEndpoint(reqEndPoint);
      req.setBodyAsBlob(bodyBlob);
      req.setTimeout(120000);
 
      Http http = new Http();
      HTTPResponse res = http.send(req);
}    


So that code works, however, it messes up most of the PDF. 

I'm attaching an example.  I had to blackout some of the sentative information, but you can clearly see what is happeneing with the green part and the part right under it. 

User-added image


Does anyone have any ideas on why it could be doing this?
 
Hello, I'm a new developer in general, so I really appreciate the help in advance. 

I wrote a batch job that works great in sandbox, but fails in production becuase I have over 500k Opportunitites.  So I get the old too many queries error.  

I was told that I have to put my query in the START method, so that it wil batch the query itself.  Right now, my EXECUTE method calls the class below to do the queries.  What I need help with is that currently I'm usuing two queries and I'm unsure how to put them both into the start method.  

Here is my class that is called from EXECUTE and fails:

public class ProjectionsBatchCalculations {
    
    static date startDate;
    static integer thisYear;
    
    public static void processCalculations(List<Projections__c> proj){
        
        List<Opportunity> apiSubs = new List<Opportunity>();
        List<Projections__c> toUpdate = new List<Projections__c>();
        List<Opportunity> apisubs2018 = new List<Opportunity>();
        List<Opportunity> apiSubs2019 = new List<Opportunity>();
        
        
        for(Projections__c ps : proj){
            
            integer month = ps.Projection_Term_Start_Date__c.month();
            startDate = ps.Projection_Term_Start_Date__c;
            
            for(Opportunity o : [SELECT id,Date_Received__c FROM Opportunity WHERE API_Submission__c = true 
                                 AND Date_Received__c >= 2018-01-01
                                 AND Account.id =: ps.Related_Account__c]){
                                     
              integer year = o.Date_Received__c.year();
                integer oMonth = o.Date_Received__c.month();
                                                         
                if(oMonth==month){
                                         
                  if(year == 2019) {
                    
                        apiSubs2019.add(o);
                    
                    }else if(year == 2018){
                    
                        apiSubs2018.add(o);
                        }  
                                         
                                         
                    }
                                  

            }
            
            
            system.debug('The apiSubs2018 are' +apiSubs2018);
            system.debug('The apiSubs2019 are' +apiSubs2019);
            ps.X2019_API_Submissions__c = apiSubs2019.size();
            ps.X2018_API_Submissions__c = apiSubs2018.size();
            toUpdate.add(ps);
            apiSubs2019.clear();
            apiSubs2018.clear();
        }
        
        system.debug('The list toUpdate is:' +toUpdate);
        update toUpdate;
        
    }
    
}

As you can see, I have a custom object called Projections__c, of which there arent' many records.  That object has a lookup to Account.  I only want to get the Opptys that match Accounts with Projections__c records.  

Please help!!  

I tried to do something like this:

global class ProjectionsBatchClass implements Database.Batchable<sObject>, Database.Stateful{
   
    global List<Opportunity> releventOpptys = new List<Opportunity>();
    global static List<Projections__c> proj = [SELECT id, Related_Account__c, Projection_Term_Start_Date__c FROM Projections__c];
    global final string query;
    
    
    global ProjectionsBatchClass(){
    
        query = 'SELECT id,Date_Received__c FROM Opportunity WHERE API_Submission__c = true AND Date_Received__c >= 2018-01-01 AND Account.id In: proj.Related_Account__c';
        
        
    } 
    

    
    global Database.QueryLocator start(Database.BatchableContext bc){
      
   
      return Database.getQueryLocator(query);


    } 
    
    global void execute(Database.BatchableContext bc, List<Opportunity> proj){
         
          releventOpptys.addAll(proj);  
          ProjectionsBatchCalculations.processCalculations(releventOpptys);          
    }    


But this fails becuase "proj.Realted_Account__c" is not found.  It's not in scope of the Start method.  

I'm stuck!

 
I'm stuck.  So stuck.  Can anyone help? 

I start with a public site Visualforce page that takes some input values and creates a custom object record in Salesforce and then redirects to a second page which displays those values that were just inputted. This is a guest site user.    The creation of this new record in Salesforce hits a trigger that performs a number of APEX callouts to get more data for that record.  This process takes about 30 seconds total.  After all the callouts are done, the rest of the fields on the Salesforce record are popualted. 

I need to display these NEW values on the same visualforce page that the end user is waiting for while the callouts have been running.  

So for the end user they enter the fields, are taked to a thank you page that is displaying some of the fields (the ones they inputted) and it shows some wait icon until the callouts are done, and the new fields are populated, then should populate those new fields on the VF page. 

I can't get it to work.  Even when I manually refresh the page after the update is done, the new values aren't there.  They are just null. 

Any idea on the approach I need to take here?  Any advice would be awesome!

 
Please!  I'm so stuck.  I am making a callout where the body is simply a PDF attachment.  This is working correctly in Postman, but I can't get it to work in my APEX callout.  

Here is a screen shot from postman.  The body only has to be the key 'file' and the .pdf attachment. 

User-added image


I can't get it to work.  Here is my code:

 public static void sendPDF(string collectionID, id intakeID){
        
        system.debug('You are now in the sendPDF method and the resource key is' +collectionID);
       
        // Get the attachment to pass 
        Attachment objPDF = [SELECT ID,ParentID,Name,Body FROM Attachment WHERE ParentID =: intakeID LIMIT 1]; 
        system.debug('The ID of the Attachment is '+objPDF);
        
        // change the following variables according to your use-case
        String strParserId = 'PARSERID';
        String strSeparationKey = 'A_RANDOM_STRING';

        // assemble the body payload
        String strHeader = '--' + strSeparationKey + '\nContent-Disposition: form-data; name="File"; filename="' + objPDF.Name + '"\nContent-Type: application/octet-stream\n\n';
        String strBody = EncodingUtil.base64Encode(objPDF.Body);
        String strFooter = '\n--' + strSeparationKey + '--';

        String strHeaderEncoded = EncodingUtil.base64Encode(Blob.valueOf(strHeader+'\n'));
        while(strHeaderEncoded.endsWith('=')) {
            strHeader+=' ';
            strHeaderEncoded = EncodingUtil.base64Encode(Blob.valueOf(strHeader+'\n'));
        }
        
        String strBodyEncoded = strBody;
        String strFooterEncoded = EncodingUtil.base64Encode(Blob.valueOf(strFooter));

        Blob blobBody = null;
        String last4Bytes = strBodyEncoded.substring(strBodyEncoded.length()-4,strBodyEncoded.length());

        if(last4Bytes.endsWith('=')) {
            Blob decoded4Bytes = EncodingUtil.base64Decode(last4Bytes);
            HttpRequest objHttpRequest = New HttpRequest();
            objHttpRequest.setBodyAsBlob(decoded4Bytes);
            String last4BytesFooter = objHttpRequest.getBody()+strFooter;
            blobBody = EncodingUtil.base64Decode(strHeaderEncoded+strBodyEncoded.substring(0,strBodyEncoded.length()-4)+EncodingUtil.base64Encode(Blob.valueOf(last4BytesFooter)));
        } else {
            blobBody = EncodingUtil.base64Decode(strHeaderEncoded+strBodyEncoded+strFooterEncoded);
        }

        if(blobBody.size()>3000000) {
            // throw new CustomException('File size limit is 3 MBytes');
            system.debug('File size limit is 3 MBytes');
        }else{
            system.debug('blobBody.size()'+blobBody.size());
            system.debug('The sent blob body: '+blobBody);
        }

        // send out the request
        HttpRequest req = New HttpRequest();
        req.setHeader('Content-Type', 'multipart/form-data; boundary=' + strSeparationKey);
        req.setMethod('POST');
        req.setEndpoint('callout:Omnius/collections/'+collectionID +'/documents');
        req.setBodyAsBlob(blobBody);
        Http http = New Http();
        HTTPResponse res = http.send(req);
        system.debug('res'+res.getBody());
    }   
        
    }



Can anyone tell me what I am doing wrong?   I think the problem is the body and that's all.  As I said, it's working in Postman correctly.  

Any help at all would be awesome!
 
Hello.  I am getting a very simple JSON response back but can't seem to deseralize it correctly to get the ID that I need.  The response looks like this:

{
    "duration": 0.024,
    "success": true,
    "error_message": null,
    "status_code": 201,
    "payload": {
        "id": "XXXXXXXXXXXXXXX",
        "name": "test4204201112"
    }
}


My apex looks like this:

 if(res.getStatusCode() < 300){
            Type resultType = Type.forName('ResponseModel'); 
            ResponseModel r1 = (ResponseModel)JSON.deserialize(responseJSON1, ResponseModel.class);      

         }
        
    }
    

    public class ResponseModel{
        
        public decimal duration;
        public boolean success;
        public string error_message;
        public integer status_code;
        public string payload;
        public list<string> id;
        public list<string> Name;
     
    }



Of course this doesn't work.  I think the whole list thing is wrong.  Since payload is a JSON object, I'm having trouble getting that ID out of it.  All I need is that ID.  Can anyone help and change my code so that it works?  

I've also tried making another class for payload and deseralize it again to there, but no luck. 

 
Hello All,

I'm brand new to this and I'm having trouble with generating JSON.  
I am getting an error like "Cannot start array, expecting field name"
Please help!!!!


Here is what I'm trying to emulate:


{
  "RatingZip": "",
  "YearsInBusiness": "",
  "NatureOfBusiness": "",
  "IsNonProfit": "",
  "Product": "", REQUIRED
  "IsIncumbantAgent": "",
  "ClassCodeList": [
    {
      "ClassCode": "", REQUIRED
      "ClassDescriptionCode": "",
      "LocState": "", REQUIRED
      "Payroll": "", REQUIRED
      "FullTimeEmployees": "",
      "PartTimeEmployees": ""
    }
  ],
  "GenerateProposal": "",
  "LegalEntity": "",
  "Fein": "",
  "Applicant": { REQUIRED
    "BusinessName": "", REQUIRED
    "BusinessAddress1": "", REQUIRED
    "BusinessCity": "", REQUIRED
    "BusinessState": "", REQUIRED
    "BusinessZip": "", REQUIRED
    "MailingAddress1": "",
    "MailingCity": "",
    "MailingState": "",
    "MailingZip": "",
    "ContactInformation": { REQUIRED
      "FirstName": "", REQUIRED
      "LastName": "", REQUIRED
      "Email": "", REQUIRED
      "Phone": "" REQUIRED
    }
  },
  "Salutation": "",
  "CompanyWebsiteAddress": "",
  "EffectiveDate": "", REQUIRED
  "ExpiredPremium": ""
}

And here is my code:

JSONGenerator gen = JSON.createGenerator(true);   
        gen.writeStartObject();
        gen.writeStringField('RatingZip', '');
        gen.writeNumberField('YearsInBusiness', 0);
        gen.writeStringField('NatureOfBusiness', '');
        gen.writeBooleanField('IsNonProfit', false);
        gen.writeStringField('Product', 'WC');
        gen.writeBooleanField('IsIncumbantAgent', false);
        gen.writeStringField('ClassCodeList', '');
        gen.writeStartArray();
        gen.writeStringField('ClassCode', i.Class_Code__c);
        gen.writeStringField('ClassDescriptionCode', '');
        gen.writeStringField('LocState', '');
        gen.writeStringField('Payroll', i.Payroll__c);
        gen.writeStringField('FullTimeEmployees', '');
        gen.writeStringField('PartTimeEmployees', '');
        gen.writeEndArray();
        gen.writeBooleanField('GenerateProposal', true);
        gen.writeNumberField('LegalEntity', 0);
        gen.writeStringField('Fein', '');
        gen.writeObjectField('Applicant', '');
        gen.writeStartObject();
        gen.writeStringField('BusinessName', i.Business_Name__c);
        gen.writeStringField('BusinessAddress1', i.Business_Address__c);
        gen.writeStringField('BusinessCity', i.Business_City__c);
        gen.writeStringField('BusinessState', i.Business_State__c);
        gen.writeStringField('BusinessZip', i.Business_Zip__c);
        gen.writeStringField('MailingAddress1', '');
        gen.writeStringField('MailingCity', '');
        gen.writeStringField('MailingState', '');
        gen.writeStringField('MailingZip', '');
        gen.writeStartObject();
        gen.writeObjectField('ContactInformation', '');
        gen.writeStringField('FirstName', i.First_Name__c);
        gen.writeStringField('LastName', i.Last_Name__c);
        gen.writeStringField('Email', i.Email__c);
        gen.writeStringField('Phone', i.Phone__c);
        gen.writeEndObject();
        gen.writeEndObject();
        gen.writeStringField('Salutation', '');
        gen.writeStringField('CompanyWebsiteAddress', '');
        gen.writeStringField('EffectiveDate', i.Effective_Date__c);
        gen.writeNumberField('ExpiredPremium', 0);
        gen.writeEndObject();
        
Hello, I'm a new developer in general, so I really appreciate the help in advance. 

I wrote a batch job that works great in sandbox, but fails in production becuase I have over 500k Opportunitites.  So I get the old too many queries error.  

I was told that I have to put my query in the START method, so that it wil batch the query itself.  Right now, my EXECUTE method calls the class below to do the queries.  What I need help with is that currently I'm usuing two queries and I'm unsure how to put them both into the start method.  

Here is my class that is called from EXECUTE and fails:

public class ProjectionsBatchCalculations {
    
    static date startDate;
    static integer thisYear;
    
    public static void processCalculations(List<Projections__c> proj){
        
        List<Opportunity> apiSubs = new List<Opportunity>();
        List<Projections__c> toUpdate = new List<Projections__c>();
        List<Opportunity> apisubs2018 = new List<Opportunity>();
        List<Opportunity> apiSubs2019 = new List<Opportunity>();
        
        
        for(Projections__c ps : proj){
            
            integer month = ps.Projection_Term_Start_Date__c.month();
            startDate = ps.Projection_Term_Start_Date__c;
            
            for(Opportunity o : [SELECT id,Date_Received__c FROM Opportunity WHERE API_Submission__c = true 
                                 AND Date_Received__c >= 2018-01-01
                                 AND Account.id =: ps.Related_Account__c]){
                                     
              integer year = o.Date_Received__c.year();
                integer oMonth = o.Date_Received__c.month();
                                                         
                if(oMonth==month){
                                         
                  if(year == 2019) {
                    
                        apiSubs2019.add(o);
                    
                    }else if(year == 2018){
                    
                        apiSubs2018.add(o);
                        }  
                                         
                                         
                    }
                                  

            }
            
            
            system.debug('The apiSubs2018 are' +apiSubs2018);
            system.debug('The apiSubs2019 are' +apiSubs2019);
            ps.X2019_API_Submissions__c = apiSubs2019.size();
            ps.X2018_API_Submissions__c = apiSubs2018.size();
            toUpdate.add(ps);
            apiSubs2019.clear();
            apiSubs2018.clear();
        }
        
        system.debug('The list toUpdate is:' +toUpdate);
        update toUpdate;
        
    }
    
}

As you can see, I have a custom object called Projections__c, of which there arent' many records.  That object has a lookup to Account.  I only want to get the Opptys that match Accounts with Projections__c records.  

Please help!!  

I tried to do something like this:

global class ProjectionsBatchClass implements Database.Batchable<sObject>, Database.Stateful{
   
    global List<Opportunity> releventOpptys = new List<Opportunity>();
    global static List<Projections__c> proj = [SELECT id, Related_Account__c, Projection_Term_Start_Date__c FROM Projections__c];
    global final string query;
    
    
    global ProjectionsBatchClass(){
    
        query = 'SELECT id,Date_Received__c FROM Opportunity WHERE API_Submission__c = true AND Date_Received__c >= 2018-01-01 AND Account.id In: proj.Related_Account__c';
        
        
    } 
    

    
    global Database.QueryLocator start(Database.BatchableContext bc){
      
   
      return Database.getQueryLocator(query);


    } 
    
    global void execute(Database.BatchableContext bc, List<Opportunity> proj){
         
          releventOpptys.addAll(proj);  
          ProjectionsBatchCalculations.processCalculations(releventOpptys);          
    }    


But this fails becuase "proj.Realted_Account__c" is not found.  It's not in scope of the Start method.  

I'm stuck!

 
Hello.  I am getting a very simple JSON response back but can't seem to deseralize it correctly to get the ID that I need.  The response looks like this:

{
    "duration": 0.024,
    "success": true,
    "error_message": null,
    "status_code": 201,
    "payload": {
        "id": "XXXXXXXXXXXXXXX",
        "name": "test4204201112"
    }
}


My apex looks like this:

 if(res.getStatusCode() < 300){
            Type resultType = Type.forName('ResponseModel'); 
            ResponseModel r1 = (ResponseModel)JSON.deserialize(responseJSON1, ResponseModel.class);      

         }
        
    }
    

    public class ResponseModel{
        
        public decimal duration;
        public boolean success;
        public string error_message;
        public integer status_code;
        public string payload;
        public list<string> id;
        public list<string> Name;
     
    }



Of course this doesn't work.  I think the whole list thing is wrong.  Since payload is a JSON object, I'm having trouble getting that ID out of it.  All I need is that ID.  Can anyone help and change my code so that it works?  

I've also tried making another class for payload and deseralize it again to there, but no luck. 

 
Hello All,

I'm brand new to this and I'm having trouble with generating JSON.  
I am getting an error like "Cannot start array, expecting field name"
Please help!!!!


Here is what I'm trying to emulate:


{
  "RatingZip": "",
  "YearsInBusiness": "",
  "NatureOfBusiness": "",
  "IsNonProfit": "",
  "Product": "", REQUIRED
  "IsIncumbantAgent": "",
  "ClassCodeList": [
    {
      "ClassCode": "", REQUIRED
      "ClassDescriptionCode": "",
      "LocState": "", REQUIRED
      "Payroll": "", REQUIRED
      "FullTimeEmployees": "",
      "PartTimeEmployees": ""
    }
  ],
  "GenerateProposal": "",
  "LegalEntity": "",
  "Fein": "",
  "Applicant": { REQUIRED
    "BusinessName": "", REQUIRED
    "BusinessAddress1": "", REQUIRED
    "BusinessCity": "", REQUIRED
    "BusinessState": "", REQUIRED
    "BusinessZip": "", REQUIRED
    "MailingAddress1": "",
    "MailingCity": "",
    "MailingState": "",
    "MailingZip": "",
    "ContactInformation": { REQUIRED
      "FirstName": "", REQUIRED
      "LastName": "", REQUIRED
      "Email": "", REQUIRED
      "Phone": "" REQUIRED
    }
  },
  "Salutation": "",
  "CompanyWebsiteAddress": "",
  "EffectiveDate": "", REQUIRED
  "ExpiredPremium": ""
}

And here is my code:

JSONGenerator gen = JSON.createGenerator(true);   
        gen.writeStartObject();
        gen.writeStringField('RatingZip', '');
        gen.writeNumberField('YearsInBusiness', 0);
        gen.writeStringField('NatureOfBusiness', '');
        gen.writeBooleanField('IsNonProfit', false);
        gen.writeStringField('Product', 'WC');
        gen.writeBooleanField('IsIncumbantAgent', false);
        gen.writeStringField('ClassCodeList', '');
        gen.writeStartArray();
        gen.writeStringField('ClassCode', i.Class_Code__c);
        gen.writeStringField('ClassDescriptionCode', '');
        gen.writeStringField('LocState', '');
        gen.writeStringField('Payroll', i.Payroll__c);
        gen.writeStringField('FullTimeEmployees', '');
        gen.writeStringField('PartTimeEmployees', '');
        gen.writeEndArray();
        gen.writeBooleanField('GenerateProposal', true);
        gen.writeNumberField('LegalEntity', 0);
        gen.writeStringField('Fein', '');
        gen.writeObjectField('Applicant', '');
        gen.writeStartObject();
        gen.writeStringField('BusinessName', i.Business_Name__c);
        gen.writeStringField('BusinessAddress1', i.Business_Address__c);
        gen.writeStringField('BusinessCity', i.Business_City__c);
        gen.writeStringField('BusinessState', i.Business_State__c);
        gen.writeStringField('BusinessZip', i.Business_Zip__c);
        gen.writeStringField('MailingAddress1', '');
        gen.writeStringField('MailingCity', '');
        gen.writeStringField('MailingState', '');
        gen.writeStringField('MailingZip', '');
        gen.writeStartObject();
        gen.writeObjectField('ContactInformation', '');
        gen.writeStringField('FirstName', i.First_Name__c);
        gen.writeStringField('LastName', i.Last_Name__c);
        gen.writeStringField('Email', i.Email__c);
        gen.writeStringField('Phone', i.Phone__c);
        gen.writeEndObject();
        gen.writeEndObject();
        gen.writeStringField('Salutation', '');
        gen.writeStringField('CompanyWebsiteAddress', '');
        gen.writeStringField('EffectiveDate', i.Effective_Date__c);
        gen.writeNumberField('ExpiredPremium', 0);
        gen.writeEndObject();