• Justin Kitagawa 6
  • NEWBIE
  • 10 Points
  • Member since 2016

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

I am trying to parse JSON that has an element that can come over as either a string or list... 

"people": [
{
	"jobFunction": "Marketing",
	"jobLevel": "C-Level",
	"industry": "Software"
},{
	"jobFunction": ["Marketing","Sales"],
	"jobLevel": "C-Level",
	"industry": "Software"
}]
I can't figure out how to parse JSON that contains both such as above. 

I had been trying to parse using a custom class (JSON 2 APEX), but it breaks when there are both found in a single return... any ideas? 
I am trying to build a table that shows leads and contacts... so I created a custom obj class personObject and I am able to instantiate them just fine... 

but when I try to but them into a datatable in visualforce I am running into Error: 'OpportunityExt.personObject.Id'    

Visualforce Page: 
<apex:page standardController="Opportunity" extensions="OpportunityExt"  >

 Raw: {!RelatedPeople}
        <apex:dataTable styleClass="list" width="100%" style="height: 10px;" value="{!RelatedPeople}" var="per">
            <apex:column headerValue="Name" styleClass="dataRow">
                <apex:outputLink value="/per.id" target="_parent">{!per.firstName} {!per.lastName}</apex:outputLink> 
            </apex:column>  
            <apex:column value="{!per.email}" headerValue="Email"/>
            <apex:column value="{!per.Title}" headerValue="Title"/>
            <apex:column value="{!per.Company}" headerValue="Company"/>
            <apex:column value="{!per.Status}" headerValue="Lead Status"/>
        </apex:dataTable>
   

    
    <!-- for soql call -->
<apex:outputField rendered="FALSE" value="{!opportunity.account.website}" />
<apex:outputField rendered="FALSE" value="{!opportunity.account.name}" />

</apex:page>



I can display the raw output just fine: 
[personObject:[Id=0031700000NtXdEAAV, company=McLaren, email=null, firstName=Kevin, lastName=Magnussen, status=Contact Record, title=Chairman and Chief Executive Officer], personObject:[ Id=0031700000NtXRHAA3, company=McLaren, email=ron@mclaren.com, firstName=Ron, lastName=Dennis, status=Contact Record, title=CEO], personObject:Id=0031700000NtXWRAA3, company=McLaren, email=eric@mclaren.com, firstName=Eric, lastName=Boullier, status=Contact Record, title=Racing Director]]




Class: 
public class OpportunityExt {

    private final Opportunity opp;
    
    public OpportunityExt(ApexPages.StandardController stdController) {
        this.opp = (opportunity)stdController.getRecord();
    }
    
    public class personObject {
    // custom constructor
        string firstName; 
        string lastName;
        string email;
        string title;
        string company;
        string Id; 
        string status;
    }    
        

    public List<personObject> getRelatedPeople(){ 
        list<personObject> relatedPeople = new List<personObject>();
        List<Lead> relatedLeads = [SELECT Id, Name, status, email, Title, Company, Website  FROM Lead WHERE  (website = :opp.account.website AND website != null AND isConverted = FALSE)OR (Company LIKE  :opp.account.Name AND isConverted = FALSE)   ORDER BY HG_Focus_User__c DESC, Name ASC LIMIT 1000];
        for(lead ld :relatedLeads){
            personObject person = new personObject();
            person.firstname = ld.firstName;
            person.lastName = ld.lastName;
            person.email = ld.email; 
            person.title = ld.title;
            person.company = ld.company; 
            person.status = ld.status;
            person.Id = ld.id;
            relatedPeople.add(person);
        }
        
        List<Contact> relatedContacts = [SELECT Id, firstName, lastName, email, Title, account.name, account.website, HG_Focus_User__c, HG_Focus_Sign_Up_Date__c FROM Contact WHERE account.id = :opp.account.id];
        for(contact ctc :relatedContacts){
            personObject person = new personObject();
            person.firstname = ctc.firstName;
            person.lastName = ctc.lastName;
            person.email = ctc.email; 
            person.title = ctc.title;
            person.company = ctc.account.name; 
            person.status = 'Contact Record';
            person.Id = ctc.id;
            relatedPeople.add(person);
        }
        
        
        return relatedPeople;
    }

    
}

 
I am working on a project where I am hoping to do the following: 

On Lead Insert --> Trigger to call @future callout method to get append information on the lead. 
Query Lead database to find if other leads exist for that company (using email domain)
    --> If New Company 
          --> call @future callout method to search for additional leads and bring them in as leads. 
                --> call @future callout method to append information to these leads. 

But I am running into an issue as my Update call is triggering my insert call, which is then triggering the update call again and I am getting an error as a future method cannot be invoked by another future method... 

I am thinking of either: 
  1. Making the second API call append data to the newly created additional leads included in the method to insert them in the first place 
  2. Making the call to get additional leads scheduled instead. 
Im sure there is a way around this... has anybody done something similar in the past? 

Any help would be greatly appreciated 

I am trying to parse JSON that has an element that can come over as either a string or list... 

"people": [
{
	"jobFunction": "Marketing",
	"jobLevel": "C-Level",
	"industry": "Software"
},{
	"jobFunction": ["Marketing","Sales"],
	"jobLevel": "C-Level",
	"industry": "Software"
}]
I can't figure out how to parse JSON that contains both such as above. 

I had been trying to parse using a custom class (JSON 2 APEX), but it breaks when there are both found in a single return... any ideas? 
I am trying to build a table that shows leads and contacts... so I created a custom obj class personObject and I am able to instantiate them just fine... 

but when I try to but them into a datatable in visualforce I am running into Error: 'OpportunityExt.personObject.Id'    

Visualforce Page: 
<apex:page standardController="Opportunity" extensions="OpportunityExt"  >

 Raw: {!RelatedPeople}
        <apex:dataTable styleClass="list" width="100%" style="height: 10px;" value="{!RelatedPeople}" var="per">
            <apex:column headerValue="Name" styleClass="dataRow">
                <apex:outputLink value="/per.id" target="_parent">{!per.firstName} {!per.lastName}</apex:outputLink> 
            </apex:column>  
            <apex:column value="{!per.email}" headerValue="Email"/>
            <apex:column value="{!per.Title}" headerValue="Title"/>
            <apex:column value="{!per.Company}" headerValue="Company"/>
            <apex:column value="{!per.Status}" headerValue="Lead Status"/>
        </apex:dataTable>
   

    
    <!-- for soql call -->
<apex:outputField rendered="FALSE" value="{!opportunity.account.website}" />
<apex:outputField rendered="FALSE" value="{!opportunity.account.name}" />

</apex:page>



I can display the raw output just fine: 
[personObject:[Id=0031700000NtXdEAAV, company=McLaren, email=null, firstName=Kevin, lastName=Magnussen, status=Contact Record, title=Chairman and Chief Executive Officer], personObject:[ Id=0031700000NtXRHAA3, company=McLaren, email=ron@mclaren.com, firstName=Ron, lastName=Dennis, status=Contact Record, title=CEO], personObject:Id=0031700000NtXWRAA3, company=McLaren, email=eric@mclaren.com, firstName=Eric, lastName=Boullier, status=Contact Record, title=Racing Director]]




Class: 
public class OpportunityExt {

    private final Opportunity opp;
    
    public OpportunityExt(ApexPages.StandardController stdController) {
        this.opp = (opportunity)stdController.getRecord();
    }
    
    public class personObject {
    // custom constructor
        string firstName; 
        string lastName;
        string email;
        string title;
        string company;
        string Id; 
        string status;
    }    
        

    public List<personObject> getRelatedPeople(){ 
        list<personObject> relatedPeople = new List<personObject>();
        List<Lead> relatedLeads = [SELECT Id, Name, status, email, Title, Company, Website  FROM Lead WHERE  (website = :opp.account.website AND website != null AND isConverted = FALSE)OR (Company LIKE  :opp.account.Name AND isConverted = FALSE)   ORDER BY HG_Focus_User__c DESC, Name ASC LIMIT 1000];
        for(lead ld :relatedLeads){
            personObject person = new personObject();
            person.firstname = ld.firstName;
            person.lastName = ld.lastName;
            person.email = ld.email; 
            person.title = ld.title;
            person.company = ld.company; 
            person.status = ld.status;
            person.Id = ld.id;
            relatedPeople.add(person);
        }
        
        List<Contact> relatedContacts = [SELECT Id, firstName, lastName, email, Title, account.name, account.website, HG_Focus_User__c, HG_Focus_Sign_Up_Date__c FROM Contact WHERE account.id = :opp.account.id];
        for(contact ctc :relatedContacts){
            personObject person = new personObject();
            person.firstname = ctc.firstName;
            person.lastName = ctc.lastName;
            person.email = ctc.email; 
            person.title = ctc.title;
            person.company = ctc.account.name; 
            person.status = 'Contact Record';
            person.Id = ctc.id;
            relatedPeople.add(person);
        }
        
        
        return relatedPeople;
    }

    
}