Reading inline Query data in APEX
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
/* Code snippet to read inline query data into APEX */ List<Account> accounts = new List<Account>(); accounts = [select id, (select id, firstname, lastname from contacts ) from Account where id in (select accountid from AccountShare where USerOrGroupId = '00531000007eCfF')]; List<Contact> contacts = new List<Contact>(); for(Account account : accounts ) { for(Contact contact: account.Contacts) { System.debug('Contact Object details ' + contact ); } } |
JSONGenerator
This example generates a JSON string in pretty print format by using the methods of the JSONGenerator class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
/* This example generates a JSON string in pretty print format by using the methods of the JSONGenerator class */ // JSON Generate - Start JSONGenerator gen = JSON.createGenerator(true); gen.writeStartArray(); for(Opportunity opt : opty) { gen.writeStartObject(); gen.writeStringField('Id', opt.Id); gen.writeStringField('Type', opt.Type); gen.writeStringField('Name', opt.name); gen.writeStringField('StageName', opt.StageName); gen.writeNumberField('Probability', opt.Probability); gen.writeDateTimeField('LastModifiedDate', opt.LastModifiedDate); gen.writeDateField('CloseDate', opt.CloseDate); gen.writeEndObject(); } gen.writeEndArray(); // JSON Generate - End |