• James Boggs
  • NEWBIE
  • 30 Points
  • Member since 2017

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 11
    Replies
Hoping for some help on this one, I think it might be an easy one.

I have an @future REST API callout that just sends some data. (It works just fine)

I have 1 Opportunity with a check box, when checked, the API is called.
Master/Detail to Opportunity is Equipment__c.

I have/will have between 1 and 100 peices of equipment per Opportunity.

The below class works, except for the equipment part, instead of listing the unique equipment, it repeats the same peice of equipment over and over (If there are 3 unique pieces of equipment, it will repeat the same peice of equipment 3x. The debug log indicates the query worked fine and the equipment is there, but this peice is not doing what I want it to do.

    jsonObj.writeStartObject();
        jsonObj.writeFieldName('EquipmentList');
        jsonObj.writeStartArray();
            jsonObj.writeStartObject();
                jsonObj.writeStringField('SiteID', E[0].Id);
            jsonObj.writeEndObject();

        jsonObj.writeEndArray();
             jsonObj.writeEndObject();
            
Reults are:           
        {
          "EquipmentList": [
            {
              "SalesForcEquipmentID": "a0f18000001YetmAAC",
              "SalesForcCAID": "R1234567890",
              "SalesForcSmartCard": "S1234567890"
            }
          ]
        },
        {
          "EquipmentList": [
            {
              "SalesForcEquipmentID": "a0f18000001YetmAAC",
              "SalesForcCAID": "R1234567890",
              "SalesForcSmartCard": "S1234567890"
            }
          ]
        },
        {
          "EquipmentList": [
            {
              "SalesForcEquipmentID": "a0f18000001YetmAAC",
              "SalesForcCAID": "R1234567890",
              "SalesForcSmartCard": "S1234567890"
            }

Instead of:
        {
          "EquipmentList": [
            {
              "SalesForcEquipmentID": "a0f18000001YgrmAAD",
              "SalesForcCAID": "R2345678901",
              "SalesForcSmartCard": "S2345678901"
            }
          ]
        },
        {
          "EquipmentList": [
            {
              "SalesForcEquipmentID": "a0f18000001YlmmAAA",
              "SalesForcCAID": "R3456789012",
              "SalesForcSmartCard": "S3456789012"
            }
          ]
        },
        {
          "EquipmentList": [
            {
              "SalesForcEquipmentID": "a0f18000001YetmAAC",
              "SalesForcCAID": "R1234567890",
              "SalesForcSmartCard": "S1234567890"
            }            

            
Here is the class:
public class AmDocs_CalloutClass_BulkCreate {

    @future(callout=true)

    public static void AmDocsMakeCalloutCreateBulk(String Id) {

 list<Opportunity> O = [select id, Name, AmDocs_Site_Id__c from Opportunity where Id = :id ];
     
 list<Equipment__c> E = [select id, Opportunity__c from Equipment__c where Opportunity__c = :id ];

JSONGenerator jsonObj = JSON.createGenerator(true);
    jsonObj.writeStartObject();
    jsonObj.writeFieldName('CreateBulk');
    jsonObj.writeStartArray();
        jsonObj.writeStartObject();
        jsonObj.writeFieldName('Property / Site');
        jsonObj.writeStartArray();
            jsonObj.writeStartObject();
                jsonObj.writeStringField('SiteID', O[0].AmDocs_Site_Id__c);
                jsonObj.writeStringField('CustomerID', O[0].Name);
                jsonObj.writeStringField('SalesforceID', O[0].Id);
            jsonObj.writeEndObject();
            jsonObj.writeStartObject();
                jsonObj.writeFieldName('EquipmentList');
                jsonObj.writeStartArray();
                    jsonObj.writeStartObject();
                        jsonObj.writeStringField('SiteID', E[0].Id);
                    jsonObj.writeEndObject();
                jsonObj.writeEndArray();
           jsonObj.writeEndObject();
           jsonObj.writeEndArray();  
    jsonObj.writeEndObject();
    String finalJSON = jsonObj.getAsString();
   
        HttpRequest request = new HttpRequest();
            String endpoint = 'http://putsreq.com/KZ2kmwfUvrIf5ARJE05h';
                 request.setEndPoint(endpoint);        
                 request.setBody(jsonObj.getAsString());  
                 request.setHeader('Content-Type', 'application/json');
                 request.setMethod('POST');

         HttpResponse response = new HTTP().send(request);
                 System.debug(response.toString());
                 System.debug('STATUS:'+response.getStatus());
                 System.debug('STATUS_CODE:'+response.getStatusCode());
                 System.debug(response.getBody());
}
}

Thanks for your help.
Jerry
Hi All,
I'm trying optimize my code, so I need help.
Let me explain first how works my code.

I have a table in my page that brings a list of accounts with your fields.
Each of these fields is a field of type Choice List, and when I select an option the account are updated.
Here is the image of my table:
User-added image

The only way I could update the field is creating for each column a function in Javascript and a Method in APEX.
Javascrit:
function gravar(id, status){
     var id_conta = id;
     var nome = document.getElementById(status).value;
     executar(id_conta, nome);
    }

Apex:
        public pageReference Save(){
            System.debug('Executou ');
            id_conta = System.currentPageReference().getParameters().get('id_contas');
            status_conta = System.currentPageReference().getParameters().get('suporte_status');
            
            for(Account conta : [SELECT Id, Name, ServiceNow_Status__c, Suporte_Status__c, Adm_Status__c, BS_BH_Status__c FROM Account                                             WHERE Id =: id_conta]){
                conta.Suporte_Status__c = status_conta;
                update conta;
            }

           return null;
        }

The problems is, if I have 45 columns I must create 45 funcions and Apex Methods.
I want create only 1 Function and only 1 Method that Allow to me update the field.
The process will update each field at a time.

Can someone help me to optimize my code?

Thanks
Rafael.
 
Hoping for some help on this one, I think it might be an easy one.

I have an @future REST API callout that just sends some data. (It works just fine)

I have 1 Opportunity with a check box, when checked, the API is called.
Master/Detail to Opportunity is Equipment__c.

I have/will have between 1 and 100 peices of equipment per Opportunity.

The below class works, except for the equipment part, instead of listing the unique equipment, it repeats the same peice of equipment over and over (If there are 3 unique pieces of equipment, it will repeat the same peice of equipment 3x. The debug log indicates the query worked fine and the equipment is there, but this peice is not doing what I want it to do.

    jsonObj.writeStartObject();
        jsonObj.writeFieldName('EquipmentList');
        jsonObj.writeStartArray();
            jsonObj.writeStartObject();
                jsonObj.writeStringField('SiteID', E[0].Id);
            jsonObj.writeEndObject();

        jsonObj.writeEndArray();
             jsonObj.writeEndObject();
            
Reults are:           
        {
          "EquipmentList": [
            {
              "SalesForcEquipmentID": "a0f18000001YetmAAC",
              "SalesForcCAID": "R1234567890",
              "SalesForcSmartCard": "S1234567890"
            }
          ]
        },
        {
          "EquipmentList": [
            {
              "SalesForcEquipmentID": "a0f18000001YetmAAC",
              "SalesForcCAID": "R1234567890",
              "SalesForcSmartCard": "S1234567890"
            }
          ]
        },
        {
          "EquipmentList": [
            {
              "SalesForcEquipmentID": "a0f18000001YetmAAC",
              "SalesForcCAID": "R1234567890",
              "SalesForcSmartCard": "S1234567890"
            }

Instead of:
        {
          "EquipmentList": [
            {
              "SalesForcEquipmentID": "a0f18000001YgrmAAD",
              "SalesForcCAID": "R2345678901",
              "SalesForcSmartCard": "S2345678901"
            }
          ]
        },
        {
          "EquipmentList": [
            {
              "SalesForcEquipmentID": "a0f18000001YlmmAAA",
              "SalesForcCAID": "R3456789012",
              "SalesForcSmartCard": "S3456789012"
            }
          ]
        },
        {
          "EquipmentList": [
            {
              "SalesForcEquipmentID": "a0f18000001YetmAAC",
              "SalesForcCAID": "R1234567890",
              "SalesForcSmartCard": "S1234567890"
            }            

            
Here is the class:
public class AmDocs_CalloutClass_BulkCreate {

    @future(callout=true)

    public static void AmDocsMakeCalloutCreateBulk(String Id) {

 list<Opportunity> O = [select id, Name, AmDocs_Site_Id__c from Opportunity where Id = :id ];
     
 list<Equipment__c> E = [select id, Opportunity__c from Equipment__c where Opportunity__c = :id ];

JSONGenerator jsonObj = JSON.createGenerator(true);
    jsonObj.writeStartObject();
    jsonObj.writeFieldName('CreateBulk');
    jsonObj.writeStartArray();
        jsonObj.writeStartObject();
        jsonObj.writeFieldName('Property / Site');
        jsonObj.writeStartArray();
            jsonObj.writeStartObject();
                jsonObj.writeStringField('SiteID', O[0].AmDocs_Site_Id__c);
                jsonObj.writeStringField('CustomerID', O[0].Name);
                jsonObj.writeStringField('SalesforceID', O[0].Id);
            jsonObj.writeEndObject();
            jsonObj.writeStartObject();
                jsonObj.writeFieldName('EquipmentList');
                jsonObj.writeStartArray();
                    jsonObj.writeStartObject();
                        jsonObj.writeStringField('SiteID', E[0].Id);
                    jsonObj.writeEndObject();
                jsonObj.writeEndArray();
           jsonObj.writeEndObject();
           jsonObj.writeEndArray();  
    jsonObj.writeEndObject();
    String finalJSON = jsonObj.getAsString();
   
        HttpRequest request = new HttpRequest();
            String endpoint = 'http://putsreq.com/KZ2kmwfUvrIf5ARJE05h';
                 request.setEndPoint(endpoint);        
                 request.setBody(jsonObj.getAsString());  
                 request.setHeader('Content-Type', 'application/json');
                 request.setMethod('POST');

         HttpResponse response = new HTTP().send(request);
                 System.debug(response.toString());
                 System.debug('STATUS:'+response.getStatus());
                 System.debug('STATUS_CODE:'+response.getStatusCode());
                 System.debug(response.getBody());
}
}

Thanks for your help.
Jerry
Hi Dev's,

How to execute below WSDL2 Apex class in Execute anonymous window.
Class :
-----------
public class ParkLocator {
    public static String[] country(String country){
        ParkService.ParksImplPort park = new ParkService.ParksImplPort();
        String[] parkname= park.byCountry(country);
        return parkname;
    }

}


Thanks in Advance.
User-added image


This is my visual force page:
<apex:page standardcontroller="Program_Member_MVN__c" extensions="SkipMilestone" showHeader="false" sidebar="false"> 
   <!-- <script language="JavaScript" type="text/javascript">
        function CloseAndRefresh(){
            window.opener.location.href="/{!$CurrentPage.parameters.id}";
              window.close();
                  }
     </script>-->
      <apex:includeScript value="/support/console/40.0/integration.js"/>
     <script type="text/javascript">
     function Window(){
                confirm("You are about to skip this patient to the.  All open milestones previous to this one will be closed.  Do you want to continue?");
}
        function closeWindow(){
        <!--var tabId = $CurrentPage.parameters.id;-->
           var url = parent.location.href; 
            window.self.close();
            }
            <!--sforce.console.refreshPrimaryTabById(url,false);-->
            </script>
        <apex:form >
        <apex:pageBlock title="Skip Milestone">
            <apex:pageblocktable value="{!lst}" var="a">
                <!--<apex:column ><apex:inputCheckbox value="{!a.selected}" /></apex:column>-->
                <apex:column headervalue="MileStone" value="{!a.Pmm.Parent_Program_Stage__c}"/>
                <apex:column headervalue="Stage" value="{!a.Pmm.Program_Stage_MVN__c}"/>
                <!--<apex:column headervalue="Name" value="{!a.Pmm.Name}"/>
                    <apex:column headervalue="Status" value="{!a.Pmm.Status_MVN__c}"/>
                <apex:column headervalue="Activity Sequence" value="{!a.Pmm.Activity_Sequence_Number_CTS__c }"/>
                <apex:column headervalue="Id" value="{!a.Pmm.Id}"/>-->
                <apex:column headerValue="Action">
                    <apex:commandLink value="Start" action="{!savemethid}" onclick="Window()" oncomplete="closeWindow()" styleClass="btn" style="text-decoration:none;padding:1px;"> 
                        <apex:param name="{!a.Pmm.Id}" value="{!a.Pmm.Id}" assignTo="{!paramValue}"/> 
                    </apex:commandLink>
                </apex:column>
            </apex:pageblocktable>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Is it possible to pass current stage name which i click into the confirm dialog?
Hi Guys,

I am new bee to use angularjs in salesforce. Below is my code which is working fine when i put the below snippet in script tag in the same page.
var app = angular.module('myApp', []);
 app.controller('myctrl', function ($scope) {   
     <!--$scope.contacts = {!contacts} -->
     $scope.fname = 'Test1';
     $scope.lname = 'Test2';
 });

But when i put the above code in app.js static resource and refrenced <apex:includeScript value="{!$Resource.app}"/> it is throwing the error.
angular is not defined.

Could anybody tell me what is the wrong i am doing.

Thanks,
Bujji.
  • March 16, 2017
  • Like
  • 0
Hi guys,

So here is the problem.

Im been requested to set the comment box on the tasks to be sort of a log. Meaning that if User1 goes and leaves a comment on a task, His comment will show up with his username and timestamp. he wont be able to go back and edit this comment neither User2, they will just be able to make NEW comments and so on. 


Could you guys please help me on how to do this or let me know which way could that be done?