• Jerry Clifft
  • NEWBIE
  • 105 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 1
    Likes Given
  • 28
    Questions
  • 40
    Replies
I need to use a string list to update multiple records, but only a single record is updating.

I have this to deserialize my incomng json:

public class person {
    public String serviceID;
    public String responseStatus;
    public cls_equipmentList[] equipmentList;
}
class cls_equipmentList {
    public String action;
    public String receiverID;
    public String location;
    public String smartCardID;
    public String leaseInd;
}

I can see my data with:

        System.debug('DEBUG 3 ======== obj.equipmentList: ' + obj.equipmentList);

Which returns:

(cls_equipmentList:[
action=ADD, leaseInd=false, location=C, receiverID=R1270000274, smartCardID=S1270000274
],
cls_equipmentList:[
action=ADD, leaseInd=false, location=C, receiverID=R1270000264, smartCardID=S1270000264
])


Then I want to update each record in the equipmentList based on receiverID, but only the first record is updating.

I tired this:

    if(obj.equipmentList[0].receiverID != null){
        List<Equipment__c> allEQ = [SELECT Id, Name FROM Equipment__c WHERE Name = :obj.equipmentList[0].receiverID ];
        for (Equipment__C currentEQ : allEQ) {
            currentEQ.Action__c = 'Active';
        }
        update allEQ;
    }

All help is appreciated.
The visualforce and contoller class seem to work fine, but I am having a hard time increasing the test class cod coverage from 9%.
 
Visual Force Page
<apex:page Controller="SLMFGRaExt" sidebar="False" showHeader="False" docType="html-5.0">  
<apex:panelGrid columns="1"  cellpadding="2" width="800" >
</apex:panelGrid>

<apex:panelGrid columns="1"  cellpadding="2" width="650">
<apex:form >
    <apex:pageBlock >
        <apex:pageBlockTable value="{!sbx}" var="s" width="400px" columns="4" columnsWidth="75px, 75px, 75px, 100px">
            
            <apex:column >
                <apex:facet name="header">S/N</apex:facet>
                <apex:outputText label="S/N" value="{!s.Serial_Number__c}"/>
            </apex:column>

            <apex:column >
                <apex:facet name="header">RA #</apex:facet>
                <apex:inputText label="RA #" value="{!s.RA_Number__c}"/>            
            </apex:column>
            


        </apex:pageBlockTable>
	<apex:commandButton value="Save" action="{!onsave}" />
</apex:pageBlock>
</apex:form>
</apex:panelGrid>
</apex:page>
Controller

public class SLMFGRaExt {

    public SLMFGRaExt() {

    }
    public SLMFGRaExt(ApexPages.StandardController controller) {
    }
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null && ApexPages.currentPage().getParameters().get('cid') != null) {
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT ID, Name, RA_Number__c, Serial_Number__c, CASEID__c FROM Sbx__c WHERE CASEID__c = :ApexPages.currentPage().getParameters().get('cid') AND AND RA_Number__c = NULL ORDER BY Sbx__c.Name ]));
                }
            return setCon;
        }set;
		}
    public List<Sbx__c> getSbx() {
         return (List<Sbx__c>) setCon.getRecords();
    }


    public PageReference onsave() {
        update (List<Sbx__c>) setCon.getRecords();

        return new PageReference('http://the.force.com/sbx/Sbx_ThankYou');
    }
}
Test Class

@isTest (seeAllData=true)
Public class SLMFGRaExt_test{

    public static testMethod void SbxExt_1(){
        Account a = new Account();
        a.Name = 'Test Account';
        a.phone = '(303) 555-5555';
              
        insert a;
        
    Opportunity o = new Opportunity();
       o.Name='Tet Opp';
       o.AccountId=a.Id;
       o.RecordTypeId='0126000000053vu';
       o.CloseDate=system.Today();
       o.StageName='Closed Won';
       
       insert o;
       
    Case c1 = new Case();
        c1.Opportunity__c=o.Id;
        c1.Account_Name__c=a.Id;
        c1.Status='Form Sumitted';
        
        insert c1;


      Sbx__c sb = new Sbx__c();
          sb.Serial_Number__c='L98765';
          sb.RA_Number__c='R12345';
          sb.CaseID__c=c1.id;
          sb.Opportunity__c=o.id;
          
          Insert sb;    
    
    PageReference pageRef = Page.SbxLMFG_RAEntry;
		Test.setCurrentPage(pageRef);
    system.test.setCurrentPage(pageRef);
    
    ApexPages.StandardController setCon = new ApexPages.standardController(sb);
    SbxLMFGRaExt ext = new SbxLMFGRaExt(setCon);

    System.currentPagereference().getParameters().put('cid',c1.Id);


  }
  
  }



 
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
Can somebody help me with this testmethod for an API REST callout.
Here is my callout it, it works just fine when used from a trigger.

public class My_CalloutClass_Stuff {
   @future(callout=true)
    public static void makeCalloutStuff() {

JSONGenerator jsonObj = JSON.createGenerator(true);
    jsonObj.writeStartObject();
    jsonObj.writeFieldName('devices');
    jsonObj.writeStartArray();
        jsonObj.writeStartObject();
        jsonObj.writeFieldName('deviceIds');
        jsonObj.writeStartArray();
            jsonObj.writeStartObject();
                jsonObj.writeStringField('id', 'blah');
                jsonObj.writeStringField('kind', 'blah');
            jsonObj.writeEndObject();
        jsonObj.writeEndArray();            
        jsonObj.writeEndObject();
    jsonObj.writeEndArray();            
    jsonObj.writeEndObject();
String finalJSON = jsonObj.getAsString();
        
    HttpRequest request = new HttpRequest();
        String endpoint = 'http://putsreq.com/YRoCBRnRvcUJ8SD2Rhq0';
        request.setEndPoint(endpoint);
        request.setBody(jsonObj.getAsString());
        request.setHeader('Content-Type', 'application/json');
        request.setMethod('POST');
        String authorizationHeader = 'Bearer ' + 'blah' ;
        String VZHeader = 'blah' ;
        request.setHeader('VZ-M2M-Token', VZHeader);   
        request.setHeader('Authorization', authorizationHeader);    

        // Send the HTTP request and get the response.
        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());
           
        // If the request is successful, parse the JSON response.
        if (response.getStatusCode() == 200) {
            // Deserialize the JSON string into collections of primitive data types.
        Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
            System.debug('=== all keys in the map: ' + results.keySet());
            System.debug('=== all values in the map (as a List): ' + results.values());
            System.debug('=== all values in the map (as a List): ' + results.size());
            
         // Cast the values in the 'blades' key as a list
        List<String> vztoken = new List<String>();
            vztoken.addAll(results.keySet());     

        System.debug('Received the following vztoken info: ' +vztoken);
           for (Object Verizon: vztoken) {
           System.debug(vztoken);
           Verizon__c sbc = new Verizon__c();
           sbc.name=String.valueOf(results.values());
           sbc.vid__c='id';
           sbc.Smartbox__c='id;
           sbc.response_code__c=String.valueOf(results.values());
           sbc.Action__c='Suspend';

           insert sbc;
            
         System.debug('sbc'+sbc);
        }
    }        
}
}


I have a static resource for use with the mocktest

{'sessionresults', 'resultvalue'}



Here is my current, not working testmethod.

@isTest
private class My_CalloutClass_StuffTest {

    @isTest static  void testPUTCallout() {
        // Create the mock response based on a static resource
        StaticResourceCalloutMock mock = new StaticResourceCalloutMock();
        mock.setStaticResource('GetAnimalResource');
        mock.setStatusCode(200);
        mock.setHeader('Content-Type', 'application/json;charset=UTF-8');
        // Associate the callout with a mock response
        Test.setMock(HttpCalloutMock.class, mock);
        // Call method to test
        HttpResponse resA = My_CalloutClass_Stuff.makeCalloutStuff();
        // Verify mock response is not null
        System.assertNotEquals(null,resA,
            'The callout returned a null response.');
        // Verify status code
        System.assertEquals(200,resA.getStatusCode(),
          'The status code is not 200.');
        // Verify content type   
        System.assertEquals('application/json;charset=UTF-8',
          result.getHeader('Content-Type'),
          'The content type value is not expected.');  
        // Verify the array contains 3 items     
        Map<String, Object> results = (Map<String, Object>)
            JSON.deserializeUntyped(resA.getBody());
        List<Object> animals = (List<Object>) results.get('animals');
        System.assertEquals(3, animals.size(),
          'The array should only contain 3 items.');          
    }   

}

Error: Compile Error: Illegal assignment from void to System.HttpResponse at line 13 column 22
I am working on my first outbound message api integration and it seems I need some apex to assist with this. I have the following class:

//Methods Included: GoToState, GetStateAndServicesList
// Primary Port Class Name: BasicHttpBinding_IStateService  
public class nphaseComUnifiedwebserviceV2 {
    public class BasicHttpBinding_IStateService {
        public String endpoint_x = 'https://uws.apps.nphase.com/api/v2/StateService.svc?wsdl';
        public Map<String,String> inputHttpHeaders_x;
        public Map<String,String> outputHttpHeaders_x;
        public String clientCertName_x;
        public String clientCert_x;
        public String clientCertPasswd_x;
        public Integer timeout_x;
        private String[] ns_map_type_info = new String[]{'http://nphase.com/unifiedwebservice/v2','nphaseComUnifiedwebserviceV2','http://schemas.microsoft.com/2003/10/Serialization/','schemasMicrosoftCom200310Serializat','http://schemas.datacontract.org/2004/07/NPhase.UnifiedWebService.APIs.v2.Contract.StateService','schemasDatacontractOrg200407NphaseU','http://schemas.datacontract.org/2004/07/NPhase.UnifiedWebService.APIs.v2.Contract.Common','schemasDatacontractOrg200407NphaseU1','http://schemas.microsoft.com/2003/10/Serialization/Arrays','schemasMicrosoftCom200310Serializat1'};

        public nphaseComUnifiedwebserviceV2.GetStateAndServicesListResponse_element GetStateAndServicesList(schemasDatacontractOrg200407NphaseU.GetStateAndServicesListRequest Input) {
            nphaseComUnifiedwebserviceV2.GetStateAndServicesList_element request_x = new nphaseComUnifiedwebserviceV2.GetStateAndServicesList_element();
            nphaseComUnifiedwebserviceV2.GetStateAndServicesListResponse response_x;
            request_x.Input = Input;
            Map<String, nphaseComUnifiedwebserviceV2.GetStateAndServicesListResponse> response_map_x = new Map<String, nphaseComUnifiedwebserviceV2.GetStateAndServicesListResponse>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
                this,
                request_x,
                response_map_x,
                new String[]{endpoint_x,
                'http://nphase.com/unifiedwebservice/v2/IStateService/GetStateAndServicesList',
                'http://nphase.com/unifiedwebservice/v2',
                'GetStateAndServicesList',
                'http://nphase.com/unifiedwebservice/v2',
                'GetStateAndServicesListResponse',
                'nphaseComUnifiedwebserviceV2.GetStateAndServicesListResponse'}
            );
            response_x = response_map_x.get('response_x');
            return response_x;
        }

        public nphaseComUnifiedwebserviceV2.GoToStateResponse_element GoToState(schemasDatacontractOrg200407NphaseU.GoToStateRequest Input) {
            nphaseComUnifiedwebserviceV2.GoToState_element request_x = new nphaseComUnifiedwebserviceV2.GoToState_element();
            nphaseComUnifiedwebserviceV2.GoToStateResponse response_x;
            request_x.Input = Input;
            Map<String, nphaseComUnifiedwebserviceV2.GoToStateResponse> response_map_x = new Map<String, nphaseComUnifiedwebserviceV2.GoToStateResponse>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
                this,
                request_x,
                response_map_x,
                new String[]{endpoint_x,
                'http://nphase.com/unifiedwebservice/v2/IStateService/GoToState',
                'http://nphase.com/unifiedwebservice/v2',
                'GoToState',
                'http://nphase.com/unifiedwebservice/v2',
                'GoToStateResponse',
                'nphaseComUnifiedwebserviceV2.GoToStateResponse'}
            );
            response_x = response_map_x.get('response_x');
            return response_x;
        }
    }
    public class GetStateAndServicesList_element {
        public schemasDatacontractOrg200407NphaseU.GetStateAndServicesListRequest Input;
        private String[] Input_type_info = new String[]{'Input','http://nphase.com/unifiedwebservice/v2','GetStateAndServicesListRequest','0','1','true'};
        private String[] apex_schema_type_info = new String[]{'http://nphase.com/unifiedwebservice/v2','true','false'};
        private String[] field_order_type_info = new String[]{'Input'};
    }
    public class GetStateAndServicesListResponse_element {
        public nphaseComUnifiedwebserviceV2.GetStateAndServicesListResponse Output;
        private String[] Output_type_info = new String[]{'Output','http://nphase.com/unifiedwebservice/v2','GetStateAndServicesListResponse','0','1','true'};
        private String[] apex_schema_type_info = new String[]{'http://nphase.com/unifiedwebservice/v2','true','false'};
        private String[] field_order_type_info = new String[]{'Output'};
    }
    public class GoToState_element {
        public schemasDatacontractOrg200407NphaseU.GoToStateRequest Input;
        private String[] Input_type_info = new String[]{'Input','http://nphase.com/unifiedwebservice/v2','GoToStateRequest','0','1','true'};
        private String[] apex_schema_type_info = new String[]{'http://nphase.com/unifiedwebservice/v2','true','false'};
        private String[] field_order_type_info = new String[]{'Input'};
    }
    public class GoToStateResponse_element {
        public nphaseComUnifiedwebserviceV2.GoToStateResponse Output;
        private String[] Output_type_info = new String[]{'Output','http://nphase.com/unifiedwebservice/v2','GoToStateResponse','0','1','true'};
        private String[] apex_schema_type_info = new String[]{'http://nphase.com/unifiedwebservice/v2','true','false'};
        private String[] field_order_type_info = new String[]{'Output'};
    }
}


And I am receiving the following error:
Error: Compile Error: Invalid type: nphaseComUnifiedwebserviceV2.GetStateAndServicesListResponse at line 16 column 13

Anyone have any solutions or suggestions?

Thanks
Jerry
 
I am new to API Integration and I have a question. I did the trailhead for API Integration, but I did not learn the final part of what I needed.

The following code works just fine the developer console.
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals');
request.setMethod('GET');
HttpResponse response = http.send(request);
// If the request is successful, parse the JSON response.
if (response.getStatusCode() == 200) {
    // Deserialize the JSON string into collections of primitive data types.
    Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
    // Cast the values in the 'animals' key as a list
    List<Object> animals = (List<Object>) results.get('animals');
    System.debug('Received the following animals:');
    for (Object animal: animals) {
        System.debug(animal);
    }
}
I can use the debug screen to see all the "animals" that returned.
Debug Screen

But what I really want to do is write (Create records, one per debug line) of this data to a new Salesforce Object call Animals in a field name TypeOfAnimal. Can someone please provide an example of how to do this please.

Thanks
Jerry
I have this trigger, when an opportunity product line item "status" is "Add Requested" or "Remove Requested" it generates a text string that copied to the Opportunity. Also, if the Opportunity is updated, it checks to see if the any OLI's have this status, if they do, it will also copy the string to the Opportunity. Both of these work fine.

HOWEVER, if the data loader or other such tool is used to we encounter problems. For example, a batch of 200 in the data loader, a single Opportunity has OLI's with the status to activate the trigger, all 200 opportunties in the batch will have the string written them...all.

I guess, what I need, is why to limit this update to a single Opprtunity. Is there such as thing on the trigger as LIMIT 1 or simiar, if so, I have been unable to locate, please advise.


Here is my trigger.
trigger OpportunityProuctCopytoHiddenFieldUpdate on Opportunity (before insert, before update) 
    {
        Opportunity op1 = trigger.new[0];
            Set<Id> opIds = new Set<Id>();

            for (Opportunity o: Trigger.New){

                opIds.add(op1.Id);
    }
    list<opportunityLineItem> OpLine = [SELECT Status__c, Submitted__c, CreatedBy.Name, Quantity, TotalPrice, LastModifiedDate, LastModifiedBy.Name, PriceBookEntry.Name, UnitPrice, ID FROM OpportunityLineItem WHERE OpportunityId =:op1.Id AND (Status__c ='Add Requested' OR Status__c ='Remove Requested') AND Submitted__c != TRUE ] ;

     if(OpLine.size() > 0 )    
        {
            for(Opportunity t:trigger.new)
                  {
                    List<String> NewList= new List<String>();
            
                    if (t.HasOpportunityLineItem == true) 
                    {
                         for(OpportunityLineItem XOpLine: OpLine ) 
                        {
                            NewList.add(XOpLine.Status__c);
                            NewList.add(', ');
                            NewList.add(XOpLine.PriceBookEntry.Name);
                            NewList.add(', @ ');
                            String str = '' + XOpLine.Quantity;
                            NewList.add(str);
                            NewList.add(', Units, ');
                            NewList.add(' @ ');
                            String str2 = '$' + XOpLine.UnitPrice;
                            NewList.add(str2);
                            NewList.add(', Per Unit/Month  ');
                            NewList.add(XOpLine.LastModifiedBy.Name);
                            NewList.add(', on ');
                            String str1 = '' + XOpLine.lastModifiedDate;
                            NewList.add(str1);
                            NewList.add(' GMT 0');
                            NewList.add(' <br />');
                           }
                                
            
                                String s = '';
                        for(String c : NewList){
                            s = s + c;
                            system.debug('********' +  t.Hidden_Products__c);
                        }
                    {    t.Hidden_Products__c = s; t.Hidden_Case_History__c = True;}
                    }
                }
             }}
So, it has been a while and can't seem to remeber quite who to do this. I am making a custom Visual Force button for the case object that when pushed, changes the status of the case.

Here is my VF:
<apex:page standardController="Case" extensions="CaseRecallButton">
    <apex:form >
        <apex:commandButton value="Com - Recall Case" action="{!ReCallCase}" />
    </apex:form>
</apex:page>


Here is my extension:
public with sharing class CaseRecallButton {

Case CA;

    public CaseRecallButton(ApexPages.StandardController controller) {
        this.CA = (Case)Controller.getRecord();
   
    }
        public PageReference ReCallCase(){
        CA.Status='New RECALL';
        Update CA; }
}

And here is my error message:
Error: CaseRecallButton Compile Error: Non-void method might not return a value or might have statement after a return statement. at line 11 column 9

Thanks in advance for the help :)
Ok, I find this weird, hoping for some help with the matter.  Here are the basics:

Trigger on account, when the Account field Flags__c does not contain "Delinquent", and the Case owner is 'xxx' (Delinquent) it should replace the owner with a new owner. It works fine, each time I save the account, 1 case record is being updated. What I need, is for all the cases with the owner of delinquent to be updated at the same time, I thought the for loop would do this, but it is not. Here is my trigger:



trigger AccountDelinquentHoldRelesed on Account (After Update) {

Account AC = Trigger.New[0];

    Set<Id> ACIds = new Set<Id>();
            ACIds.add(AC.Id);

       list<account> ACS = [select id, Flags__c from account where Id in :ACIds AND Flags__c EXCLUDES ('Delinquent') ];
       list<case> CAS = [select id, OwnerID from case where Case.AccountID in :ACS AND Case.OwnerID = '00G60000002Ia7P'];
   
       if(CAS.size() > 0 && ACS.size() > 0 ){
           for (Case CAS2: CAS) {  
               { CAS[0].OwnerID= '00G60000001Na1r';}
           }
       }
 }
This is stumping me, I am pretty sure I am close, just can't seem to get this right today.

So, render this output, if Case.Requested Action = "This" and the Case.CreateDate <= 8/4/2014. Seems simple....

<td class="Table"><apex:outputLabel value="Chewbacca " rendered="{!IF(CONTAINS(Case.RequestedAction__c, "blah blah") & !IF(Case.Requested_Actvation_Date_Time__c <= DATE(2014,8,5)TRUE,False),False)}"/></td>

Currently getting:
Error: Syntax error. Missing ')'

Any suggestions?
I have a visualforce page and controller, part us which grabs "oppid" from the url and inserts it as part of the record.

a.Opportunity__c = ApexPages.currentPage().getParameters().get('oppId');
This works fine, if I have a URL such as:
salesforce.com/oppid=000013456789123

But sometimes, I get a URL such as:
salesforce.com/oppid=000013456789123?srPos=0

I would like to strip off everything after oppid=(first 15 chars). I was thinking about using something like LEFT,15 to do it. I have yet to get the formating right. Any suggestions?
Issue I am trying to reslove:
I have a case or two open, it / they are sitting in a queue called "Delinquency Hold".

The first part of the process, this works fine.
The account has a multipick select list called Flags__c, one of the values is Delinquent. When a new case is created, or an open case is edited, the case check's this field on the account, and if the Flags__c includes "Delinquent" it moves the case ownership to Delinquency Hold and displays a large red note across the top of the page.

Here is where I am drawing a blank.
If the account field Flags__c has the value ""Delinquent" removed, I need to have all cases that are Status = Open and Owner = Queue/Delinquency Hold re-visit the the case assignment rules so the case can re-routed/worked.

Idea's, Suggestions?
The below trigger works fine as long I update/insert between 1 and 50 records at a time. Anything above that I get System.LimitException: Too many SOQL queries: 101

I have my SOQL outside of th for loop, so I am not sure what else I can do to make this operate properly?


trigger xEquipment_HiddenFieldOpportunity on Equipment__c (After Insert, After Update) {  

    Set<Id> oppId=new Set<Id>();
    Set<Id> eqId=new Set<Id>();
    for(equipment__c CA1:Trigger.New)    {
        oppId.add(CA1.Opportunity__c);
        eqId.add(CA1.Id);
        if(oppId.size()>0){           


List<Opportunity> oppupdatelist = new List<Opportunity>();
System.debug('=== contents of List Opp: ' +oppupdatelist );

List<Opportunity> oppswitheqs = [select Id, (select id, Name, statis__c, Opportunity__c, lastModifiedDate, LastModifiedBy.Name from equipment__r where (statis__c = 'Activation Requested' OR statis__c = 'Drop Requested' )) from Opportunity where Id in :oppId ];
System.debug('=== contents of List Opp with EQ: ' +oppswitheqs );

                 
for(Opportunity Opp :oppswitheqs){
             List<String> NewList= new List<String>();
                   for (equipment__c eq2: Opp.equipment__r )    {
                       NewList.add(eq2.Statis__c);
                       NewList.add(' - ');
                       NewList.add(eq2.Name);
                       NewList.add(' - ');
                       NewList.add(eq2.LastModifiedBy.Name);
                       NewList.add(' on ');
                       String str1 = '' + eq2.lastModifiedDate;
                       NewList.add(str1);
                       NewList.add(' GMT 0');
                       NewList.add(' <br />');
                       System.debug('=== contents of NewList: ' +NewList);
                   }
                 
                  String s = '';

                   for(String c : NewList)    {
                       s = s + c;
                       system.debug('This data should go into the Opp' +  c);
                     }
                   Opp.Hidden_Bulk_Equipment__c = s;


oppupdatelist.add(Opp);
//System.debug('=== contents of oppupdatelist: ' +oppupdatelist );
                }
if(oppupdatelist.size()>0){
  //      update oppupdatelist;
Database.update(oppswitheqs);

}
}
}
}
Ok, I think this should be an easy one, but I am overlooking something I fear. This trigger should copy a string of data into a field on the Opportunity from a custom object called equipment__c. When I run the debug, everything looks fine, until the last line, where the data is written tot he Opp. For some reason, the Opp is not being updated.

trigger xEquipment_HiddenFieldOpportunity on Equipment__c (After Insert, After Update) {  

    Set<Id> oppId=new Set<Id>();
    Set<Id> eqId=new Set<Id>();
    for(equipment__c CA1:Trigger.New)    {
        oppId.add(CA1.Opportunity__c);
        eqId.add(CA1.Id);

        Map<Id,Opportunity> opptyMap=new  Map<Id,Opportunity> ([select Id,  Hidden_Bulk_Equipment__c from Opportunity where Id in :oppId ]);
            System.debug('Map Opportunity Size '+opptymap.size());
            System.debug('=== contents of opptymap: ' +opptymap);
           
        Map<Id,Equipment__c> equipMap=new  Map<Id,Equipment__c> ([select Id, Name, Statis__c, CaseID__c from Equipment__c where Opportunity__c in :oppId]);
            System.debug('Map Equipment Size '+equipmap.size());
            System.debug('=== contents of equipmap: ' +equipmap);
           
       if(opptyMap.size() > 0 && equipMap.size() > 0)    {
      
           list<Opportunity> opeq = [select id, Hidden_Bulk_Equipment__c from Opportunity where Id in :oppId];
               System.debug('List Opportunity Size '+opeq.size());
               System.debug('=== contents of Opp List: ' +opeq);
                     
           list<equipment__c> eq = [select id, Name, statis__c, Opportunity__c, lastModifiedDate, LastModifiedBy.Name from equipment__c where Opportunity__c in :oppId AND (statis__c = 'Activation Requested' OR statis__c = 'Drop Requested' )];    {
               System.debug('List Equipment Size '+opeq.size());
               System.debug('=== contents of Eq List: ' +eq);
              
               if(opptyMap.size() > 0 && equipMap.size() > 0)    {
                   List<String> NewList= new List<String>();
                   for (equipment__c eq2: eq )    {
                       NewList.add(eq2.Statis__c);
                       NewList.add(' - ');
                       NewList.add(eq2.Name);
                       NewList.add(' - ');
                       NewList.add(eq2.LastModifiedBy.Name);
                       NewList.add(' on ');
                       String str1 = '' + eq2.lastModifiedDate;
                       NewList.add(str1);
                       NewList.add(' GMT 0');
                       NewList.add(' <br />');
                       System.debug('=== contents of NewList: ' +NewList);
                                                }
                   String s = '';

                   for(String c : NewList)    {
                       s = s + c;
                       system.debug('This data should go into the Opp' +  c);
                                              }
                   opeq[0].Hidden_Bulk_Equipment__c = s;

                }
            }
        }
    }
}
I have a controller on a visualpage, this controller has a few "hidden" fields that submit. I need to capture another "hidden" field where the value varies according to kewords in the URL.

Here is my controller:

public PageReference createSFLCase(){
     if(SFLC.Contact_Name__c==null){error='Error: Please Enter Contact Name'; return null;}
     if(SFLC.Contact_Phone__c==null){error='Error: Please Enter Contact Phone'; return null;}
     SFLC.Status='Form Submitted';
     SFLC.Origin='Salesforce Lite';
     SFLC.RecordTypeId='0126000000017LQ';
     SFLC.Bulk_Load__c=True;
     SFLC.Accepted_Term__c = IF($CurrentPage.parameters.type='Service Call',SFLC.Accepted_Term__c = 'Term 1',SFLC.Accepted_Term__c = 'Term 1');
    
Needless to say, that line causes an error. How do I correctly write this line?
I have this trigger, it seems simple enough. On the case object is a lookup to Opportunity. Opportunity has a rich text field I want to copy to the case. However, this does not copy the value from the Opp field to the case field. Any suggestion / help?

trigger CaseHiddenProductCopyToCase_Testingsomething on Case (Before Insert, Before Update)
   {
         Case ca = trigger.new[0];
             { ca.Product_Change_Request_s__c = ca.Opportunity__r.Hidden_Products__c;}
    }
Ok, this is giving me head ache, I have so far been unable to get it correct. The below code works, but I really need to get the SOQL outside of the FOR loop, due to apex govenor limits. Can you assist please?

trigger CaseEquipmentStatus on Case (After Update) {
Set<Id> caseIds = new Set<Id>();
Set<Id> EquipIds = new Set<Id>();
       for (Case c: Trigger.New){
         if (c.Opportunity__c != null && c.Status == 'Request Completed' && c.Origin == 'PRM' )
         caseIds.add(c.Opportunity__c);
         }
         for (Equipment__c Eq: [select id, Opportunity__c, Statis__c from
         Equipment__c where Opportunity__c in :caseIds]) {
         if(eq.Statis__c == 'Programming Change Requested'){
         eq.Statis__c = 'Active';    }
         Update eq;
        } }
I am trying to create a field on a custom obkect that behaves like the field sort order does on the lead/case assignment rules page.

Example
Record 1, Sort Order 1
Record 2, Sort Order 2
Record 3, Sort Order 3

Then if I change:
Record 1, Sort Order 1
to
Record 1, Sort Order  2

Salesforce will then change:
Record 1, Sort Order 1 to Sort Order 2
Record 2, Sort Order 2 to Sorf Order 3

Ok, so trying to print a table from one (1) list, normally this in a single column, but I am trying to get it in three (3) columns that are (3) three rows deep. I am not getting an error, but I am not getting any values either.

 

VF

<apex:page controller="MyController" >
  <head>
  </head>
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!MyWrappers}" var="wrap">
   <apex:column headerValue="Col 1">
      <apex:outputField value="{!wrap.myAcc1.Name}"/>
   </apex:column>
   <apex:column headerValue="Col 2">
      <apex:outputField value="{!wrap.myAcc2.Name}"/>
   </apex:column>
   <apex:column headerValue="Col 3">
      <apex:outputField value="{!wrap.myAcc3.Name}"/>
   </apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Controller

public class MyController {
   public List<MyWrapper> myWrappers{get; set;}

   public class MyWrapper
   {
      public Account myAcc1 {get; set;}
      public Account myAcc2 {get; set;}
      public Account myAcc3 {get; set;}

      public Boolean checkbox1 {get; set;}
      public Boolean checkbox2 {get; set;}
      public Boolean checkbox3 {get; set;}
   }

   public MyController()
   {
      myWrappers=new List<MyWrapper>();
      Integer idx=0;
      MyWrapper wrap;
      
      for (Account acc: [select id, Name from Account limit 12])
      {
         if (0==Math.mod(idx, 3))
         {
            wrap=new MyWrapper();
            wrap.myAcc1=acc;
         
         if (1==Math.mod(idx, 3))

         wrap.myAcc2=acc;

         else if (2==Math.mod(idx, 3))

            wrap.myAcc3=acc;
        }
      }
   }
 
}

Having a little difficulty figuring this one out, hopefull you can help. I have a list to print as a PDF, single column / field, data is 100 rows long, BUT I need to display as 5 columns of 20 rows.

 

Right now I have:

Name

blah

blah

blah

blah

.....

 

I want to:

Name       Name      Name    Name      Name

blah           blah        blah        blah          blah

blah           blah        blah        blah          blah

 

 

This is my controller:

public class dataTableCon {

    List<Packages__c> pds;

    public List<Packages__c> getpds() {

  pds = [select Name, Channel_Name__c, Logo__c, Parent_Product_Content__c, Parent_Product_Content__r.Name, Product_del__c, Product_del__r.Name
FROM Packages__c
WHERE Product_del__r.Name = 'Whatever Name'];

        return pds;

    }

}

 

Here is my visualforce:

<apex:page controller="dataTableCon" renderAs="pdf" applyBodyTag="false">
    <head>
    </head>
    <body>
        <h1>Name!</h1>

<div style="height:500px; border:5px; background-color:#FFA500;">
<apex:dataTable value="{!pds}" var="p" id="theTable" rowClasses="odd,even">
    <apex:column >
        <apex:facet name="header">Channel Name</apex:facet>
        <apex:facet name="footer">column footer</apex:facet>
        <apex:outputText value="{!p.Channel_Name__c}"/>
    </apex:column>
</apex:dataTable>
</div>

   </body>
</apex:page>

 

Thanks!

I am trying to create a field on a custom obkect that behaves like the field sort order does on the lead/case assignment rules page.

Example
Record 1, Sort Order 1
Record 2, Sort Order 2
Record 3, Sort Order 3

Then if I change:
Record 1, Sort Order 1
to
Record 1, Sort Order  2

Salesforce will then change:
Record 1, Sort Order 1 to Sort Order 2
Record 2, Sort Order 2 to Sorf Order 3
I need to use a string list to update multiple records, but only a single record is updating.

I have this to deserialize my incomng json:

public class person {
    public String serviceID;
    public String responseStatus;
    public cls_equipmentList[] equipmentList;
}
class cls_equipmentList {
    public String action;
    public String receiverID;
    public String location;
    public String smartCardID;
    public String leaseInd;
}

I can see my data with:

        System.debug('DEBUG 3 ======== obj.equipmentList: ' + obj.equipmentList);

Which returns:

(cls_equipmentList:[
action=ADD, leaseInd=false, location=C, receiverID=R1270000274, smartCardID=S1270000274
],
cls_equipmentList:[
action=ADD, leaseInd=false, location=C, receiverID=R1270000264, smartCardID=S1270000264
])


Then I want to update each record in the equipmentList based on receiverID, but only the first record is updating.

I tired this:

    if(obj.equipmentList[0].receiverID != null){
        List<Equipment__c> allEQ = [SELECT Id, Name FROM Equipment__c WHERE Name = :obj.equipmentList[0].receiverID ];
        for (Equipment__C currentEQ : allEQ) {
            currentEQ.Action__c = 'Active';
        }
        update allEQ;
    }

All help is appreciated.
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
Can somebody help me with this testmethod for an API REST callout.
Here is my callout it, it works just fine when used from a trigger.

public class My_CalloutClass_Stuff {
   @future(callout=true)
    public static void makeCalloutStuff() {

JSONGenerator jsonObj = JSON.createGenerator(true);
    jsonObj.writeStartObject();
    jsonObj.writeFieldName('devices');
    jsonObj.writeStartArray();
        jsonObj.writeStartObject();
        jsonObj.writeFieldName('deviceIds');
        jsonObj.writeStartArray();
            jsonObj.writeStartObject();
                jsonObj.writeStringField('id', 'blah');
                jsonObj.writeStringField('kind', 'blah');
            jsonObj.writeEndObject();
        jsonObj.writeEndArray();            
        jsonObj.writeEndObject();
    jsonObj.writeEndArray();            
    jsonObj.writeEndObject();
String finalJSON = jsonObj.getAsString();
        
    HttpRequest request = new HttpRequest();
        String endpoint = 'http://putsreq.com/YRoCBRnRvcUJ8SD2Rhq0';
        request.setEndPoint(endpoint);
        request.setBody(jsonObj.getAsString());
        request.setHeader('Content-Type', 'application/json');
        request.setMethod('POST');
        String authorizationHeader = 'Bearer ' + 'blah' ;
        String VZHeader = 'blah' ;
        request.setHeader('VZ-M2M-Token', VZHeader);   
        request.setHeader('Authorization', authorizationHeader);    

        // Send the HTTP request and get the response.
        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());
           
        // If the request is successful, parse the JSON response.
        if (response.getStatusCode() == 200) {
            // Deserialize the JSON string into collections of primitive data types.
        Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
            System.debug('=== all keys in the map: ' + results.keySet());
            System.debug('=== all values in the map (as a List): ' + results.values());
            System.debug('=== all values in the map (as a List): ' + results.size());
            
         // Cast the values in the 'blades' key as a list
        List<String> vztoken = new List<String>();
            vztoken.addAll(results.keySet());     

        System.debug('Received the following vztoken info: ' +vztoken);
           for (Object Verizon: vztoken) {
           System.debug(vztoken);
           Verizon__c sbc = new Verizon__c();
           sbc.name=String.valueOf(results.values());
           sbc.vid__c='id';
           sbc.Smartbox__c='id;
           sbc.response_code__c=String.valueOf(results.values());
           sbc.Action__c='Suspend';

           insert sbc;
            
         System.debug('sbc'+sbc);
        }
    }        
}
}


I have a static resource for use with the mocktest

{'sessionresults', 'resultvalue'}



Here is my current, not working testmethod.

@isTest
private class My_CalloutClass_StuffTest {

    @isTest static  void testPUTCallout() {
        // Create the mock response based on a static resource
        StaticResourceCalloutMock mock = new StaticResourceCalloutMock();
        mock.setStaticResource('GetAnimalResource');
        mock.setStatusCode(200);
        mock.setHeader('Content-Type', 'application/json;charset=UTF-8');
        // Associate the callout with a mock response
        Test.setMock(HttpCalloutMock.class, mock);
        // Call method to test
        HttpResponse resA = My_CalloutClass_Stuff.makeCalloutStuff();
        // Verify mock response is not null
        System.assertNotEquals(null,resA,
            'The callout returned a null response.');
        // Verify status code
        System.assertEquals(200,resA.getStatusCode(),
          'The status code is not 200.');
        // Verify content type   
        System.assertEquals('application/json;charset=UTF-8',
          result.getHeader('Content-Type'),
          'The content type value is not expected.');  
        // Verify the array contains 3 items     
        Map<String, Object> results = (Map<String, Object>)
            JSON.deserializeUntyped(resA.getBody());
        List<Object> animals = (List<Object>) results.get('animals');
        System.assertEquals(3, animals.size(),
          'The array should only contain 3 items.');          
    }   

}

Error: Compile Error: Illegal assignment from void to System.HttpResponse at line 13 column 22
I am new to API Integration and I have a question. I did the trailhead for API Integration, but I did not learn the final part of what I needed.

The following code works just fine the developer console.
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals');
request.setMethod('GET');
HttpResponse response = http.send(request);
// If the request is successful, parse the JSON response.
if (response.getStatusCode() == 200) {
    // Deserialize the JSON string into collections of primitive data types.
    Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
    // Cast the values in the 'animals' key as a list
    List<Object> animals = (List<Object>) results.get('animals');
    System.debug('Received the following animals:');
    for (Object animal: animals) {
        System.debug(animal);
    }
}
I can use the debug screen to see all the "animals" that returned.
Debug Screen

But what I really want to do is write (Create records, one per debug line) of this data to a new Salesforce Object call Animals in a field name TypeOfAnimal. Can someone please provide an example of how to do this please.

Thanks
Jerry
I have this trigger, when an opportunity product line item "status" is "Add Requested" or "Remove Requested" it generates a text string that copied to the Opportunity. Also, if the Opportunity is updated, it checks to see if the any OLI's have this status, if they do, it will also copy the string to the Opportunity. Both of these work fine.

HOWEVER, if the data loader or other such tool is used to we encounter problems. For example, a batch of 200 in the data loader, a single Opportunity has OLI's with the status to activate the trigger, all 200 opportunties in the batch will have the string written them...all.

I guess, what I need, is why to limit this update to a single Opprtunity. Is there such as thing on the trigger as LIMIT 1 or simiar, if so, I have been unable to locate, please advise.


Here is my trigger.
trigger OpportunityProuctCopytoHiddenFieldUpdate on Opportunity (before insert, before update) 
    {
        Opportunity op1 = trigger.new[0];
            Set<Id> opIds = new Set<Id>();

            for (Opportunity o: Trigger.New){

                opIds.add(op1.Id);
    }
    list<opportunityLineItem> OpLine = [SELECT Status__c, Submitted__c, CreatedBy.Name, Quantity, TotalPrice, LastModifiedDate, LastModifiedBy.Name, PriceBookEntry.Name, UnitPrice, ID FROM OpportunityLineItem WHERE OpportunityId =:op1.Id AND (Status__c ='Add Requested' OR Status__c ='Remove Requested') AND Submitted__c != TRUE ] ;

     if(OpLine.size() > 0 )    
        {
            for(Opportunity t:trigger.new)
                  {
                    List<String> NewList= new List<String>();
            
                    if (t.HasOpportunityLineItem == true) 
                    {
                         for(OpportunityLineItem XOpLine: OpLine ) 
                        {
                            NewList.add(XOpLine.Status__c);
                            NewList.add(', ');
                            NewList.add(XOpLine.PriceBookEntry.Name);
                            NewList.add(', @ ');
                            String str = '' + XOpLine.Quantity;
                            NewList.add(str);
                            NewList.add(', Units, ');
                            NewList.add(' @ ');
                            String str2 = '$' + XOpLine.UnitPrice;
                            NewList.add(str2);
                            NewList.add(', Per Unit/Month  ');
                            NewList.add(XOpLine.LastModifiedBy.Name);
                            NewList.add(', on ');
                            String str1 = '' + XOpLine.lastModifiedDate;
                            NewList.add(str1);
                            NewList.add(' GMT 0');
                            NewList.add(' <br />');
                           }
                                
            
                                String s = '';
                        for(String c : NewList){
                            s = s + c;
                            system.debug('********' +  t.Hidden_Products__c);
                        }
                    {    t.Hidden_Products__c = s; t.Hidden_Case_History__c = True;}
                    }
                }
             }}
So, it has been a while and can't seem to remeber quite who to do this. I am making a custom Visual Force button for the case object that when pushed, changes the status of the case.

Here is my VF:
<apex:page standardController="Case" extensions="CaseRecallButton">
    <apex:form >
        <apex:commandButton value="Com - Recall Case" action="{!ReCallCase}" />
    </apex:form>
</apex:page>


Here is my extension:
public with sharing class CaseRecallButton {

Case CA;

    public CaseRecallButton(ApexPages.StandardController controller) {
        this.CA = (Case)Controller.getRecord();
   
    }
        public PageReference ReCallCase(){
        CA.Status='New RECALL';
        Update CA; }
}

And here is my error message:
Error: CaseRecallButton Compile Error: Non-void method might not return a value or might have statement after a return statement. at line 11 column 9

Thanks in advance for the help :)
Ok, I find this weird, hoping for some help with the matter.  Here are the basics:

Trigger on account, when the Account field Flags__c does not contain "Delinquent", and the Case owner is 'xxx' (Delinquent) it should replace the owner with a new owner. It works fine, each time I save the account, 1 case record is being updated. What I need, is for all the cases with the owner of delinquent to be updated at the same time, I thought the for loop would do this, but it is not. Here is my trigger:



trigger AccountDelinquentHoldRelesed on Account (After Update) {

Account AC = Trigger.New[0];

    Set<Id> ACIds = new Set<Id>();
            ACIds.add(AC.Id);

       list<account> ACS = [select id, Flags__c from account where Id in :ACIds AND Flags__c EXCLUDES ('Delinquent') ];
       list<case> CAS = [select id, OwnerID from case where Case.AccountID in :ACS AND Case.OwnerID = '00G60000002Ia7P'];
   
       if(CAS.size() > 0 && ACS.size() > 0 ){
           for (Case CAS2: CAS) {  
               { CAS[0].OwnerID= '00G60000001Na1r';}
           }
       }
 }
hi all,

I urgently need to edit/delete a post made by me on this discussion forum...But its not allowing me to do so and pops up
saying that 'you cant delete this question as others are interested in it'.
There are no likes and no comments on it still i am unable  to delete it
Any help would be highly appreciated

Its very urgent,
Thanks,

I will be implementing Partner Communities. I am testing in a dev org to confirm functionality. I have a Button on the Contact that executes javascript. It works fine from the internal org but gives this error from the community:

A problem with the OnClick JavaScript for this button or link was encountered:

{faultcode:'UNKNOWN_EXCEPTION', faultstring:'UNKNOWN_EXCEPTION: Site under construction', }

The button code is
{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")};
var dob = '{!Contact.Birthdate}';
var sal = '{!Contact.Annual_Income__c}';
var plandate = '{!Contact.Date_Entered_Plan__c}';
var inflation = '{!Contact.Expected_Raise_Per_Year__c}';

if( dob == '' || sal == '' ||inflation == '' || plandate == '')
{
alert('Please Validate Birthdate/Annual Income/Date Entered Plan/Expected Raise Per Year/ Spouse DOB');
}
else
{

sforce.apex.execute("GeneratePensionReport","attachReport", {id:"{!Contact.Id}"});
window.alert("Pension Report has been Generated and Attached." );
}

I think this issue has to do with the context - since it is running from the community it thinks it has a different domain.  Not sure how to address this.
Any help would be appreciiated.
Issue I am trying to reslove:
I have a case or two open, it / they are sitting in a queue called "Delinquency Hold".

The first part of the process, this works fine.
The account has a multipick select list called Flags__c, one of the values is Delinquent. When a new case is created, or an open case is edited, the case check's this field on the account, and if the Flags__c includes "Delinquent" it moves the case ownership to Delinquency Hold and displays a large red note across the top of the page.

Here is where I am drawing a blank.
If the account field Flags__c has the value ""Delinquent" removed, I need to have all cases that are Status = Open and Owner = Queue/Delinquency Hold re-visit the the case assignment rules so the case can re-routed/worked.

Idea's, Suggestions?
The below trigger works fine as long I update/insert between 1 and 50 records at a time. Anything above that I get System.LimitException: Too many SOQL queries: 101

I have my SOQL outside of th for loop, so I am not sure what else I can do to make this operate properly?


trigger xEquipment_HiddenFieldOpportunity on Equipment__c (After Insert, After Update) {  

    Set<Id> oppId=new Set<Id>();
    Set<Id> eqId=new Set<Id>();
    for(equipment__c CA1:Trigger.New)    {
        oppId.add(CA1.Opportunity__c);
        eqId.add(CA1.Id);
        if(oppId.size()>0){           


List<Opportunity> oppupdatelist = new List<Opportunity>();
System.debug('=== contents of List Opp: ' +oppupdatelist );

List<Opportunity> oppswitheqs = [select Id, (select id, Name, statis__c, Opportunity__c, lastModifiedDate, LastModifiedBy.Name from equipment__r where (statis__c = 'Activation Requested' OR statis__c = 'Drop Requested' )) from Opportunity where Id in :oppId ];
System.debug('=== contents of List Opp with EQ: ' +oppswitheqs );

                 
for(Opportunity Opp :oppswitheqs){
             List<String> NewList= new List<String>();
                   for (equipment__c eq2: Opp.equipment__r )    {
                       NewList.add(eq2.Statis__c);
                       NewList.add(' - ');
                       NewList.add(eq2.Name);
                       NewList.add(' - ');
                       NewList.add(eq2.LastModifiedBy.Name);
                       NewList.add(' on ');
                       String str1 = '' + eq2.lastModifiedDate;
                       NewList.add(str1);
                       NewList.add(' GMT 0');
                       NewList.add(' <br />');
                       System.debug('=== contents of NewList: ' +NewList);
                   }
                 
                  String s = '';

                   for(String c : NewList)    {
                       s = s + c;
                       system.debug('This data should go into the Opp' +  c);
                     }
                   Opp.Hidden_Bulk_Equipment__c = s;


oppupdatelist.add(Opp);
//System.debug('=== contents of oppupdatelist: ' +oppupdatelist );
                }
if(oppupdatelist.size()>0){
  //      update oppupdatelist;
Database.update(oppswitheqs);

}
}
}
}
Ok, I think this should be an easy one, but I am overlooking something I fear. This trigger should copy a string of data into a field on the Opportunity from a custom object called equipment__c. When I run the debug, everything looks fine, until the last line, where the data is written tot he Opp. For some reason, the Opp is not being updated.

trigger xEquipment_HiddenFieldOpportunity on Equipment__c (After Insert, After Update) {  

    Set<Id> oppId=new Set<Id>();
    Set<Id> eqId=new Set<Id>();
    for(equipment__c CA1:Trigger.New)    {
        oppId.add(CA1.Opportunity__c);
        eqId.add(CA1.Id);

        Map<Id,Opportunity> opptyMap=new  Map<Id,Opportunity> ([select Id,  Hidden_Bulk_Equipment__c from Opportunity where Id in :oppId ]);
            System.debug('Map Opportunity Size '+opptymap.size());
            System.debug('=== contents of opptymap: ' +opptymap);
           
        Map<Id,Equipment__c> equipMap=new  Map<Id,Equipment__c> ([select Id, Name, Statis__c, CaseID__c from Equipment__c where Opportunity__c in :oppId]);
            System.debug('Map Equipment Size '+equipmap.size());
            System.debug('=== contents of equipmap: ' +equipmap);
           
       if(opptyMap.size() > 0 && equipMap.size() > 0)    {
      
           list<Opportunity> opeq = [select id, Hidden_Bulk_Equipment__c from Opportunity where Id in :oppId];
               System.debug('List Opportunity Size '+opeq.size());
               System.debug('=== contents of Opp List: ' +opeq);
                     
           list<equipment__c> eq = [select id, Name, statis__c, Opportunity__c, lastModifiedDate, LastModifiedBy.Name from equipment__c where Opportunity__c in :oppId AND (statis__c = 'Activation Requested' OR statis__c = 'Drop Requested' )];    {
               System.debug('List Equipment Size '+opeq.size());
               System.debug('=== contents of Eq List: ' +eq);
              
               if(opptyMap.size() > 0 && equipMap.size() > 0)    {
                   List<String> NewList= new List<String>();
                   for (equipment__c eq2: eq )    {
                       NewList.add(eq2.Statis__c);
                       NewList.add(' - ');
                       NewList.add(eq2.Name);
                       NewList.add(' - ');
                       NewList.add(eq2.LastModifiedBy.Name);
                       NewList.add(' on ');
                       String str1 = '' + eq2.lastModifiedDate;
                       NewList.add(str1);
                       NewList.add(' GMT 0');
                       NewList.add(' <br />');
                       System.debug('=== contents of NewList: ' +NewList);
                                                }
                   String s = '';

                   for(String c : NewList)    {
                       s = s + c;
                       system.debug('This data should go into the Opp' +  c);
                                              }
                   opeq[0].Hidden_Bulk_Equipment__c = s;

                }
            }
        }
    }
}

I'm trying to do an HTTP callout for this REST webservice; everything seems to be working except that I'm getting an empty body for the response when I know there should be something there.  If I paste the exact endpoint URL into my browser, I see xml returned.  What could possibly make force.com see an empty response?

 

Code is below.  The webservice is MapAbc's reverse geocode service.  I've left off the last section of the URL which represents our org's key.

 

 

	Http h = new Http();
	HttpRequest req = new HttpRequest();
	
	string url = 'http://search1.mapabc.com/sisserver?highLight=false&config=SPAS&ver=2.0';
	url = url + '&resType=xml';	//Response type
	url = url + '&enc=utf-8&spatialXml=<spatial_request method=\'searchPoint\'>';
	url = url + '<x>106.66423034667969</x>';	//Latitude
	url = url + '<y>26.61029052734375</y>';		//Longitude
	url = url + '<xs></xs><ys></ys>';
	url = url + '<poiNumber>0</poiNumber>';
	url = url + '<range>NaN</range><pattern>0</pattern><roadLevel>0</roadLevel><exkey></exkey></spatial_request>';
	url = url + '&a_k=***OurKey****';	//Key
	url = url + '&a_nocache=615704261174';
	
	req.setEndpoint(url);
    	req.setMethod('GET');    
	HttpResponse res  = new HttpResponse(); 
	res = h.send(req);
	string resBody=res.getBody();
        system.debug('Response Body is: ' + resBody);   //Why is this null???	   

 

Debug logs:

 

08:34:49.056 (56000000)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
08:34:49.056 (56802000)|METHOD_ENTRY|[1]|01pK00000000Nrc|MapAbcTest.MapAbcTest()
08:34:49.056 (56859000)|SYSTEM_MODE_ENTER|false
08:34:49.056 (56909000)|SYSTEM_MODE_EXIT|false
08:34:49.056 (56942000)|METHOD_EXIT|[1]|MapAbcTest
08:34:49.056 (56988000)|CONSTRUCTOR_ENTRY|[1]|01pK00000000Nrc|<init>()
08:34:49.057 (57059000)|SYSTEM_MODE_ENTER|false
08:34:49.057 (57107000)|SYSTEM_MODE_EXIT|false
08:34:49.057 (57166000)|CONSTRUCTOR_EXIT|[1]|01pK00000000Nrc|<init>()
08:34:49.057 (57297000)|METHOD_ENTRY|[2]|01pK00000000Nrc|MapAbcTest.testing()
08:34:49.058 (58417000)|SYSTEM_MODE_ENTER|false
08:34:49.058 (58943000)|SYSTEM_METHOD_ENTRY|[26]|System.HttpRequest.setEndpoint(String)
08:34:49.059 (59003000)|SYSTEM_METHOD_EXIT|[26]|System.HttpRequest.setEndpoint(String)
08:34:49.059 (59081000)|SYSTEM_METHOD_ENTRY|[28]|System.HttpRequest.setMethod(String)
08:34:49.059 (59133000)|SYSTEM_METHOD_EXIT|[28]|System.HttpRequest.setMethod(String)
08:34:49.059 (59240000)|SYSTEM_METHOD_ENTRY|[30]|System.Http.send(APEX_OBJECT)
08:34:49.059 (59350000)|CALLOUT_REQUEST|[30]|System.HttpRequest[Endpoint=http://search1.mapabc.com/sisserver?highLight=false&config=SPAS&ver=2.0&resType=xml&enc=utf-8&spatialXml=<spatial_request method='searchPoint'><x>106.66423034667969</x><y>26.61029052734375</y><xs></xs><ys></ys><poiNumber>0</poiNumber><range>NaN</range><pattern>0</pattern><roadLevel>0</roadLevel><exkey></exkey></spatial_request>&a_k=***OurKey***&a_nocache=615704261174, Method=GET]
08:34:49.287 (287725000)|CALLOUT_RESPONSE|[30]|System.HttpResponse[Status=OK, StatusCode=200]
08:34:49.287 (287820000)|SYSTEM_METHOD_EXIT|[30]|System.Http.send(APEX_OBJECT)
08:34:49.287 (287933000)|SYSTEM_METHOD_ENTRY|[31]|System.HttpResponse.getBody()
08:34:49.287 (287986000)|SYSTEM_METHOD_EXIT|[31]|System.HttpResponse.getBody()
08:34:49.288 (288079000)|SYSTEM_METHOD_ENTRY|[32]|System.debug(ANY)
08:34:49.288 (288154000)|USER_DEBUG|[32]|DEBUG|Response Body is: null
08:34:49.288 (288199000)|SYSTEM_METHOD_EXIT|[32]|System.debug(ANY)
08:34:49.288 (288275000)|SYSTEM_MODE_EXIT|false

 

And finally - this is what I get when I copy and paste that exact endpoint into a browser window:

 

<spatial_response type="SpatialBean" servername="mSIS03" versionname="1.0.9">
<SpatialBean ver="1.0">
<Province ver="1.0">
<name>贵州省</name>
<code>520000</code>
</Province>
<City ver="1.0">
<name>贵阳市</name>
<code>520100</code>
<telnum>0851</telnum>
</City>
<District ver="1.0">
<name/>
<code/>
<x/>
<y/>
<bounds/>
</District>
<roadList type="list">
<Road ver="1.0">
<id>08511789</id>
<name>贵遵高速</name>
<direction>EastNorth</direction>
<distance>38.340862</distance>
<width>12</width>
<ename>Guizun Expressway</ename>
<level>41000</level>
</Road>
<Road ver="1.0">
<id>0851804</id>
<name>服务区</name>
<direction>EastNorth</direction>
<distance>73.932838</distance>
<width>4</width>
<ename>Service area</ename>
<level>43000</level>
</Road>
<Road ver="1.0">
<id>08512255</id>
<name>贵遵高速出口</name>
<direction>WestSouth</direction>
<distance>339.452545</distance>
<width>8</width>
<ename>Guizun Expressway Exit</ename>
<level>44000</level>
</Road>
<Road ver="1.0">
<id>08512254</id>
<name>贵遵高速入口</name>
<direction>WestSouth</direction>
<distance>339.452545</distance>
<width>8</width>
<ename>Guizun Expressway Entrance</ename>
<level>44000</level>
</Road>
<Road ver="1.0">
<id>08511942</id>
<name>兴筑东路</name>
<direction>WestSouth</direction>
<distance>364.536499</distance>
<width>20</width>
<ename>(unnamed road)</ename>
<level>44000</level>
</Road>
</roadList>
<poiList type="list"/>
<crossPoiList type="list">
<cross>
<name>贵遵高速-服务区</name>
<x>106.663529</x>
<y>26.599138</y>
</cross>
</crossPoiList>
</SpatialBean>
</spatial_response>

 

 

  • September 08, 2011
  • Like
  • 0
Hi, I have Create REST API class by hitting rest API class using an anonymous window, I am getting response JSON result.
Currently, I am using anonymous window for sending the Input Question, Now I want to map Case object field for Sending Question.

Could anyone guide on this?
This is the class which I have Written, I want to Send data Input data using Case object to this class.
public class SendQuestion{
   public SendQuestion(){}
    
    public void SendQuestionMethod(String inputQue,String dialogId,String accessToken ) {
        HttpResponse res=new HttpResponse();
        HttpRequest req = new HttpRequest(); 

        String jsonsString = '{'+
        '    \"input\" :' +'\"'+inputQue+'\",'+
        '    \"conversation-id\" : null, '+
        '    \"dialog-id\":' +'\"'+dialogId+'\",'+
        '    \"channel\": \"web\",'+
        '    \"access-token\":'+ '\"'+accessToken+'\"'+
        '}';
        System.debug('jsonsString'+jsonsString);
         
        req.setBody(jsonsString);
        req.setMethod('POST');
        req.setEndpoint('https://dialog-----------------');
        req.setHeader('Content-Type', 'application/json');
        req.setTimeout(120000);     
          
        try {
        Http h = new Http();  
        res= h.send(req);
        System.debug('res::>'+res.getBody());      
        } catch(System.CalloutException e) {
            if (res.getStatus()=='OK') {
            system.debug(res.toString());
            } else {
            System.debug('ERROR: '+ e);
            system.debug(res.toString());
            }     
        }
    }
}

Thanks, Sumit