• Steve Cairney
  • NEWBIE
  • 114 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 42
    Questions
  • 116
    Replies
Hi, I have a use case where I'd like to create multiple opportunity records based on the amount of records from a related list.

Example. An Opportunity has 2 custom objects (service__c) related to it. When this Opportuniy hits a certain criteria (as yet I haven't worked out what) a process should kick in and create 2 Opportunity records each with 1 of the custom objects attached.

I think I have to use a loop in the flow that will be invoked by the process builder but I'm unsure. 

Does anyone have any experiance of doing something similar that they could share?
Hi, I have a articular use case for Process Builder and flows but I can't get it to work.

There are two obects involved, Opportunity and a custom object MC

I have created a process that when triggered creates the MC object on the Opp that triggered the flow

The next step is to create a new Opp based on the first Opp. I can do this in Process fine. But what I need to do is create a new MC object on the newly created Opp.

I can't do this with Process as all it does is add two MC objects to the original Opp.

I've tried to create the new Opp with a flow nd put that in the Process but I can't get that to work yet and I'm still not sure I'll be able to add a new MC object to that created Opp.

Does anyone have any advice?
Hi all, I'm not sure if this is the right section for process builder but....

I have successfully created a process that creates a custom object (commission__c) when an opportunity closes. The flow gives the new object the same owner as the opportunuty and is related to that opportunity. (there is a lookup relationship for the opp on the commissions object)

However, I would like to run the same logic but with Team selling enabled.

Example, the same opportunity closes but this time there are 2 team member, user A, user B. When the opp closes, two commission objects should be created in the name of user A and user B.

This doesn't seem to be possible initially, but I'm hoping someone might be able to shed some light. I thought perhaps I'd need to create a relationshop on the custom object between split or teams but there's no option.

 
Hi all, I'm writing a formula for quite a complex scoring matrix.

BACKGROUND: I have 8 picklists, the results of which hold a score number (4-1). One of the picklist values is NA and is counted separatley
These numbers are tallied WFR into two fields WFR_Score and WFR_NA.

If NA = 0 the results are 

If the Score >=24, Excellent
>= 13 and < 23, Needs Improvement
<=12, Poor

Code is below. The problem is I can't get the Poor result to show as I think there is some conflict in the scoring less and greater than. Also I will have 8 iterations of this to do WRF_NA_Count__c=1, =2, =3 etc and I think my code is a little bloated. Can I streamline it down in line count?
 
IF(
AND(
WFR_NA_Count__c = 0,
OR(
WFR_Score__c  >= 24)), "Excellent/Competent",
IF(
AND(
WFR_NA_Count__c = 0,
OR(
WFR_Score__c  >= 13,
WFR_Score__c  <= 23)), "Needs Improvement",
IF(
AND(
WFR_NA_Count__c = 0,
OR(
WFR_Score__c  < 12)), "Poor",
"ERROR"
)))

 
Hi I have a datetime field called 'Last Contact'

This field shows the latest datetime from two other fields. Here's the code
 
NOW()- 
MIN( 
NOW()- MMERP__LastDatetimeSent__c , 
NOW()- Last_Call_Made__c 
)

It works fine, but if one of the fields is blank, the resulting field is blank.

How can I edit the formula above to post the datetime value from the filed that has a value out of the two?
I have a simple button that when clicked, cheanged the record type of the Opportunity in order to fire an email alert.
 
{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")} 

var oppObj = new sforce.SObject("Opportunity"); 
oppObj.Id = '{!Opportunity.Id}'; 
oppObj.RecordTypeId = '01220000000ML20'; 
var result = sforce.connection.update([oppObj]); 

if (result[0].success=='false') { 
alert(result[0].errors.message); 
} else { 
alert("Success, Admin have been notified."); 
location.reload(true); 
}

However, I'd like to add a query so that if the button has already been clicked, another alert will show to the user.

Would it be possible for the button to check the RecordTypeID and if the record has alredy been changed to 01220000000ML20, the alternative alert is shown.

Here's what I've tried, but the syntax isn't correct. Any tips?
 
{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")}
 
var oppObj = new sforce.SObject("Opportunity"); 
oppObj.Id = '{!Opportunity.Id}'; 
oppObj.RecordTypeId = '01220000000ML20'; 
var result = sforce.connection.update([oppObj]); 
 
if ({oppObj.RecordTypeId = '01220000000ML20'; )}
{alert("This has already been approved."); 
     location.reload(true);}
){ else if (result[0].success=='false') {
     alert(result[0].errors.message);
} else {
alert("Success, Admin have been notified."); 
     location.reload(true);
}

 
Hi all,

I have to create a formula that I am unsure on the the syntax for.

This is for a formula field on the Opportunuty record. It will reference one of 12 fields that are populated on the User record.

What I need to do is have the formula check what Month the CloseDate is and then use one of the correllating fields on the User record to work out a percentage

So if the CloseDate is April, the formula will use the April field in the User record, if it's March, it will use the March field in the User record.

To throw more complexity in I am using ranges and different percentages based on user and profile ID.

The below formula works but it only references one field (the current month)
 
IF( 
OR(Owner.Profile.Id = "00e20000001V4Xd",Owner.UserRoleId = "00E2000000151Hy"), 
Margin__c * 0.15, 



IF( 
AND(Users_Total_Margin__c <= 10000,Users_Total_Margin__c >= 1, 
OR(Owner.Profile.Id <> "00e20000001V4Xd", Owner.UserRoleId <> "00E2000000151Hy")), 
Margin__c * 0.06, 



IF( 
AND(Users_Total_Margin__c >= 10001,Users_Total_Margin__c <=20000, 
OR(Owner.Profile.Id <> "00e20000001V4Xd", Owner.UserRoleId <> "00E2000000151Hy")), 
Margin__c * 0.11, 



IF( 
AND(Users_Total_Margin__c >= 20001,Owner.UserRoleId <> "00E2000000151ID"), 
Margin__c * 0.15,0 
))))

The fields on the users record are March__c, April__c, May__c etc and are rollups.

Any ideas?
Hi all, you may or may not know that there is a bug when you use percentages in a custom formula within a report. For some reason the grand total never adds up.

The bug has been around for some years and still isn't fixed. Has anyone ever come up with a workaround they could share?

My example uses percentages to work out commission. The report is a summary report. My custom formula is as follows:
 
IF(Opportunity.Margin__c:SUM <= 10000, Opportunity.Margin__c:SUM * 0.06,

IF(AND(Opportunity.Margin__c:SUM >= 10001,Opportunity.Margin__c:SUM <= 20000),
Opportunity.Margin__c:SUM * 0.11,

IF(Opportunity.Margin__c:SUM >= 20001, Opportunity.Margin__c:SUM * 0.15,0
)))

That works fine, the problem is adding the totals up manaully comes to 27,100.56 but the Grand Total on the report (which would be essential when it comes to the Dashboard I'll create) adds the total up to 33,540.53.

Not ideal!

The bug is reported here https://success.salesforce.com/ideaview?id=08730000000Bq9DAAS

Has anyone any suggestions about battling this?
Hi, I've created a formula in a summery report to calculate user commision. it's works but I need to add certain caveates into the formula.

Here's what I've got
IF(Opportunity.Margin__c:SUM <= 10000, Opportunity.Margin__c:SUM * 0.06,

IF(AND(Opportunity.Margin__c:SUM >= 10001,Opportunity.Margin__c:SUM <= 20000),
Opportunity.Margin__c:SUM * 0.11,

IF(Opportunity.Margin__c:SUM >= 20001, Opportunity.Margin__c:SUM * 0.15,0
)))

This works out the commsions based on the critera fine. However I need to add in record ID (if record ID = x, don't calculate) and also Profile. IF profile = X, use this calculation.

Does anyone know if this is possible in a summary report?
Hi, I am working with another developer so we can push sObjects to their service. I have successfully written a class that sends the data over.

We are now at stage 2, which is working on how to allow thier service to update fields on our existing sObjects. Currently the fields on the sObject are NULL, but when thier counterparts in the eternal system are populated, the external system is to contact our SF Org and update the fields if needed.

Now right now we are trying to work out how exactly to do this. It's my job to ensure that any classes we need are created in Salesforce.

What do we need to do in order to achieve this? Do I need to write a class (and testclass) that envokes the update of fields?

I have listed the class I created below, these are invoked when a button is pressed on one of the sObjects. Do I need to do something similar again?
 
global with sharing class ItsApprovedWebServices {
    
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // Description : Web Service to login to ItsApproved
    // Called From : "Test Submit Booking" botton on ItsApproved Booking Page
    // Returns     : Authorization Token (for use in subsequent web service calls to Its Approved)
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    webservice static String Login(String userName) {
        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http();
        
        req.setEndpoint('http://site.net/api/values/login?username=username');
        
        
        req.setMethod('GET');
        req.setTimeout(60000);
        
        res = http.send(req);
        
        
        return res.getHeader('Authorization-Token');
    }
    
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // Description : Web Service to create representation of Booking in JSON format
    // Called From : "Test Submit Booking" botton on ItsApproved Booking Page
    // Returns     : Complete Booking as a JSON object
    //             : 08.03.16 KJF Was returning "ID" field in CustomerBookingId (now returns "Name")
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    webservice static String GetBookingDetails(Id idIn) {
        JSONGenerator jsonGenerator = JSON.createGenerator(true);
        
        ItsApproved_Booking__c booking = [SELECT Id, Name, Booking_Title__c, Customer_Reference__c, Incharge_Date__c FROM ItsApproved_Booking__c WHERE Id = :idIn];
        
        jsonGenerator.writeStartObject(); // Booking      
        
        jsonGenerator.writeStringField('CompanyId', '042D7C6D-00E4-4C81-901A-BC8F8B545441'); // Live Company Id
        jsonGenerator.writeNumberField('UserId', 96); // Live User Id
        jsonGenerator.writeStringField('BookingTitle', booking.Booking_Title__c);
        jsonGenerator.writeStringField('CustomerReference', booking.Customer_Reference__c);
        jsonGenerator.writeStringField('CustomerBookingId', booking.Name);
        jsonGenerator.writeDateTimeField('InchargeDate', booking.Incharge_Date__c);
        
        List<ItsApproved_Product__c> products = [SELECT Id, IAProduct__c, Booking_Reference__c FROM ItsApproved_Product__c WHERE Booking_Reference__c = :idIn];
        
        jsonGenerator.writeFieldName('Products');
        jsonGenerator.writeStartArray(); // Products
        for(ItsApproved_Product__c p: products)
        {
            List<IA_Product__c> IAProducts = [SELECT Id, Code__c FROM IA_Product__c WHERE Id = :p.IAProduct__c];
            
            jsonGenerator.writeStartObject(); // Products
            jsonGenerator.writeStringField('ProductionCode', IAProducts[0].Code__c);           
            jsonGenerator.writeStringField('CustomerProductReference', IAProducts[0].Code__c);           
            
            List<ItsApproved_Design__c> designs = [SELECT Id, Artwork_Title__c FROM ItsApproved_Design__c WHERE Product_Reference__c = :p.Id];
            
            jsonGenerator.writeFieldName('Designs');
            jsonGenerator.writeStartArray(); // Designs
            for(ItsApproved_Design__c d: designs)
            {
                jsonGenerator.writeStartObject();
                jsonGenerator.writeStringField('CustomerDesignId', d.Id);           
                jsonGenerator.writeStringField('DesignName', d.Artwork_Title__c);  
                
                List<ItsApproved_Delivery__c> deliveries = [SELECT Id, IADepot__c, Quantity__c FROM ItsApproved_Delivery__c WHERE ItsApproved_Design__c = :d.Id];
                
                jsonGenerator.writeFieldName('Deliveries');
                jsonGenerator.writeStartArray(); // Deliveries
                for(ItsApproved_Delivery__c del: deliveries)
                {
                    List<IADepot__c> IADepots = [SELECT Id, Depot_Code__c FROM IADepot__c WHERE Id = :del.IADepot__c];
                    
                    jsonGenerator.writeStartObject(); // Deliveries
                    jsonGenerator.writeStringField('DeliveryId', del.Id);           
                    jsonGenerator.writeStringField('DepotCode', IADepots[0].Depot_Code__c);
                    jsonGenerator.writeNumberField('Quantity', del.Quantity__c);
                    jsonGenerator.writeEndObject(); // Deliveries
                }
                jsonGenerator.writeEndArray();  // Deliveries
                
                jsonGenerator.writeEndObject(); // Designs
            }
            jsonGenerator.writeEndArray(); // Designs
            
            jsonGenerator.writeEndObject(); // Products
        }
        jsonGenerator.writeEndArray(); // Products
        
        jsonGenerator.writeEndObject(); // Booking
        
        return jsonGenerator.getAsString();        
    }
    
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // Description : Web Service to send complete Booking Details to Its Approved
    // Called From : "Test Submit Booking" botton on ItsApproved Booking Page
    // Returns     : 
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    webservice static String PostBooking(String json, String authorizationToken)
    {   
        // Now send the data to Its Approved
        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http();
        
        
        req.setEndpoint('http://site.net/api/values/PostBooking');
        
        
        req.setMethod('POST');
        req.setHeader('Content-Type','application/json');
        req.setHeader('Authorization-Token', authorizationToken);
        req.setBody(json);
        req.setTimeout(60000);
        
        
        res = http.send(req);
        
        
        return res.getBody();
        
    }
}

 
Hi all, I've have created a complex 'app' in my Sandbox and I want to use a Package to deploy to Production. However, the Package makes use of a few custom fields that already exist in my production org. I don't want to rename these on install as it will effect current workings.

It looks like I can't remove these few custom feilds from the package so am I reduced to using a change set?

In your experiences, what do you suggest?
Hi, I'm trying to load test data into a @isTest but I need to account for Lists and I can't find the right solution, the error is always that the list is out of bounds. I need to load test data for deployment into my org (in the sandbox I was using seeAllData)

The webservice class looks like this (jsut the GET section here)
 
webservice static String GetBookingDetails(ID id) {
    JSONGenerator jsonGenerator = JSON.createGenerator(true);
          
      ItsApproved_Booking__c booking = [SELECT Id, Name, Booking_Title__c, Customer_Reference__c, Incharge_Date__c FROM ItsApproved_Booking__c WHERE Id = :id];

      jsonGenerator.writeStartObject(); // Booking      
      //jsonGenerator.writeStringField('CompanyId', '798365d8-4278-4b16-a330-c4a3a9e1f91f'); // Staging Company Id
      //jsonGenerator.writeNumberField('UserId', 84); // Staging Company Id
      jsonGenerator.writeStringField('CompanyId', '042D7C6D-00E4-4C81-901A-BC8F8B545441'); // Live Company Id
      jsonGenerator.writeNumberField('UserId', 96); // Live User Id
      jsonGenerator.writeStringField('BookingTitle', booking.Booking_Title__c);
      jsonGenerator.writeStringField('CustomerReference', booking.Customer_Reference__c);
      jsonGenerator.writeStringField('CustomerBookingId', booking.Name);
      jsonGenerator.writeDateTimeField('InchargeDate', booking.Incharge_Date__c);

      List<ItsApproved_Product__c> products = [SELECT Id, IAProduct__c, Booking_Reference__c FROM ItsApproved_Product__c WHERE Booking_Reference__c = :Id];

      jsonGenerator.writeFieldName('Products');
      jsonGenerator.writeStartArray(); // Products
      for(ItsApproved_Product__c p: products)
      {
        List<IA_Product__c> IAProducts = [SELECT Id, Code__c FROM IA_Product__c WHERE Id = :p.IAProduct__c];

        jsonGenerator.writeStartObject(); // Products
        jsonGenerator.writeStringField('ProductionCode', IAProducts[0].Code__c);           
        jsonGenerator.writeStringField('CustomerProductReference', IAProducts[0].Code__c);           

        List<ItsApproved_Design__c> designs = [SELECT Id, Artwork_Title__c FROM ItsApproved_Design__c WHERE Product_Reference__c = :p.Id];

        jsonGenerator.writeFieldName('Designs');
        jsonGenerator.writeStartArray(); // Designs
        for(ItsApproved_Design__c d: designs)
        {
          jsonGenerator.writeStartObject();
          jsonGenerator.writeStringField('CustomerDesignId', d.Id);           
          jsonGenerator.writeStringField('DesignName', d.Artwork_Title__c);           

          List<ItsApproved_Delivery__c> deliveries = [SELECT Id, IADepot__c, Quantity__c FROM ItsApproved_Delivery__c WHERE ItsApproved_Design__c = :d.Id];

          jsonGenerator.writeFieldName('Deliveries');
          jsonGenerator.writeStartArray(); // Deliveries
          for(ItsApproved_Delivery__c del: deliveries)
          {
            List<IADepot__c> IADepots = [SELECT Id, Depot_Code__c FROM IADepot__c WHERE Id = :del.IADepot__c];

            jsonGenerator.writeStartObject(); // Deliveries
            jsonGenerator.writeStringField('DeliveryId', del.Id);           
            jsonGenerator.writeStringField('DepotCode', IADepots[0].Depot_Code__c);
            jsonGenerator.writeNumberField('Quantity', del.Quantity__c);
            jsonGenerator.writeEndObject(); // Deliveries
          }
          jsonGenerator.writeEndArray();  // Deliveries

          jsonGenerator.writeEndObject(); // Designs
        }
        jsonGenerator.writeEndArray(); // Designs

        jsonGenerator.writeEndObject(); // Products
      }
      jsonGenerator.writeEndArray(); // Products

      jsonGenerator.writeEndObject(); // Booking
        
      return jsonGenerator.getAsString();        
    }

And here's my test class, as you can see I've not faciliated any List data yet as I can't work out the best approach. If we use the first List as an example
 
List<ItsApproved_Product__c> products = [SELECT Id, IAProduct__c, Booking_Reference__c FROM ItsApproved_Product__c WHERE Booking_Reference__c = :Id];

How do I load test data with at least 1 record in the list?

@isTest here
 
@isTest
public class Testing_ItsApprovedWebServices {

	@isTest public static  void ItsApprovedWebServicesTest(){
        ItsApproved_Booking__c bookingdetails = new ItsApproved_Booking__c(Booking_Title__c = 'Test', Customer_Reference__c = 'Test',Incharge_Date__c = System.today() );
    	insert bookingdetails;
        
        ItsApproved_Product__c productdetails = new ItsApproved_Product__c(Booking_Reference__c = bookingdetails.Id);
        insert productdetails;

        IA_Product__c iaproduct = new IA_Product__c(Code__c = '606');
        insert iaproduct;

        ItsApproved_Design__c designdetails = new ItsApproved_Design__c(Product_Reference__c = productdetails.Id);
        insert designdetails;
        
        ItsApproved_Delivery__c deliverydetails = new ItsApproved_Delivery__c(Product__c = productdetails.Id, ItsApproved_Design__c = designdetails.Id);
        insert deliverydetails;
        
        Test.startTest();
        Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator()); 

        String username = ItsApprovedWebServices.Login('test');
        String details = ItsApprovedWebservices.GetBookingDetails(bookingdetails.Id);
		
        Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator2()); 
        String postbooking = ItsApprovedWebServices.PostBooking('{"test" : "test"}','authorization_id');
		
        Test.stopTest();
    }		
}



 
Hi all, when you have a test class in your sandbox that references the ID of a record of a custom object within the sandbox, how to do get round the fact that this object and record won't exist in your production org when you come to test the changeset?
Hi, I've created a few classes and in order to make life easy, I've decided to create a package for ease of pushing the change over to my production org.

I've never tried this approach before, so I may be missing something.

I can confirm that all the classes and controllers pass with over 75% when testing in the developer console. However, when I try to upload the package, the average test coverage is only 57%

Why could that be happening?

I'd really rather not create a change set as the are are 6 custom objects at least...
Hi, I have a very simple button that sends infomation to a webservice.

What I'm trying to do is have an if / else statement that will display an alert with whether the submission was a success or failure.

The code is really quite simple, but it's displaying the wrong alert on a record that I know is a success and a record that I know fails.

Here's the code (note the first alert is just so I can see the inital response from the webservice

If it's a Success, it will return 

User-added image

If it fails, it will return

User-added image
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}

var json = sforce.apex.execute("ItsApprovedWebServices","GetBookingDetails",{id:"{!ItsApproved_Booking__c.Id}"});

var authorizationToken = sforce.apex.execute("ItsApprovedWebServices","Login",{userName: 'xxxx'});

var result = sforce.apex.execute("ItsApprovedWebServices","PostBooking",{json: json, authorizationToken: authorizationToken});

alert(result); //if correct returns "Success", if incorrect, returns a long error message

if (result == "Success") {
alert("OK, Booking sent to ItsApproved - http:www.google.com");
}
else { 
alert("Error! Call Cestrian and quote '{!ItsApproved_Booking__c.Name}'");
}
I'm getting the second alert for both scenarios.

What could be wrong in the code?
 
Hi, I'm in the the perculiar position where I have to try and write a test class for a web service class that was written by someone else.

I seem to be finding conflicting opinions on whether a test class will actually give the code coverage needed.

So my question is this, given the following code (which I didn't write) what's the best way to get the web service class ready and covered to send to our production org?
 
global with sharing class ItsApprovedWebServices {

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // Description : Web Service to login to ItsApproved
    // Called From : "Test Submit Booking" botton on ItsApproved Booking Page
    // Returns     : Authorization Token (for use in subsequent web service calls to Its Approved)
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    webservice static String Login(String userName) {
      HttpRequest req = new HttpRequest();
      HttpResponse res = new HttpResponse();
      Http http = new Http();

      req.setEndpoint('http://stagingv4ws.itsapproved.net/api/values/login?username=cestrianMAG');
      req.setMethod('GET');
      req.setTimeout(60000);
      //req.setHeader('Content-Type','application/json');
      //req.setBody('username'+EncodingUtil.urlEncode(userName, 'UTF-8'));
      //req.setBody(username);

  //    try {
          res = http.send(req);
                    
  //    } catch(System.CalloutException e) {
   //       System.debug('Callout error: '+ e);
   //       System.debug(res.toString());
   //   }
   
      return res.getHeader('Authorization-Token');
    }
    
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // Description : Web Service to create representation of Booking in JSON format
    // Called From : "Test Submit Booking" botton on ItsApproved Booking Page
    // Returns     : Complete Booking as a JSON object
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    webservice static String GetBookingDetails(ID id) {
    JSONGenerator jsonGenerator = JSON.createGenerator(true);
          
      ItsApproved_Booking__c booking = [SELECT Id, Booking_Title__c, Customer_Reference__c, Incharge_Date__c FROM ItsApproved_Booking__c WHERE Id = :id];
    
      jsonGenerator.writeStartObject(); // Booking
      jsonGenerator.writeStringField('CompanyId', '798365d8-4278-4b16-a330-c4a3a9e1f91f');
      jsonGenerator.writeNumberField('UserId', 84);

      //jsonGenerator.writeStringField('BookingId', booking.Id);
      jsonGenerator.writeStringField('BookingTitle', booking.Booking_Title__c);
      jsonGenerator.writeStringField('CustomerReference', booking.Customer_Reference__c);
      jsonGenerator.writeStringField('CustomerBookingId', booking.Id);
      jsonGenerator.writeDateTimeField('InchargeDate', booking.Incharge_Date__c);
      
      List<ItsApproved_Product__c> products = [SELECT Id, Product_Code__c, Booking_Reference__c FROM ItsApproved_Product__c WHERE Booking_Reference__c = :Id];

      jsonGenerator.writeFieldName('Products');
      jsonGenerator.writeStartArray(); // Products
      for(ItsApproved_Product__c p: products)
      {
        jsonGenerator.writeStartObject(); // Products
        //jsonGenerator.writeStringField('ProductId', p.Id);           
        jsonGenerator.writeStringField('ProductionCode', p.Product_Code__c);           
        jsonGenerator.writeStringField('CustomerProductReference', p.Product_Code__c);           
        //jsonGenerator.writeStringField('CustomerProductReference', p.Booking_Reference__c);           

        List<ItsApproved_Design__c> designs = [SELECT Id, Artwork_Title__c FROM ItsApproved_Design__c WHERE Product_Reference__c = :p.Id];

        jsonGenerator.writeFieldName('Designs');
        jsonGenerator.writeStartArray(); // Designs
        for(ItsApproved_Design__c d: designs)
        {
          jsonGenerator.writeStartObject();
          jsonGenerator.writeStringField('CustomerDesignId', d.Id);           
          jsonGenerator.writeStringField('DesignName', d.Artwork_Title__c);           

          List<ItsApproved_Delivery__c> deliveries = [SELECT Depot_Code__c, Quantity__c FROM ItsApproved_Delivery__c WHERE ItsApproved_Design__c = :d.Id];

          jsonGenerator.writeFieldName('Deliveries');
          jsonGenerator.writeStartArray(); // Deliveries
          for(ItsApproved_Delivery__c del: deliveries)
          {
            jsonGenerator.writeStartObject(); // Deliveries
            jsonGenerator.writeStringField('DeliveryId', del.Id);           
            jsonGenerator.writeNumberField('DepotCode', del.Depot_Code__c);
            jsonGenerator.writeNumberField('Quantity', del.Quantity__c);
            jsonGenerator.writeEndObject(); // Deliveries
          }
          jsonGenerator.writeEndArray();  // Deliveries

          jsonGenerator.writeEndObject(); // Designs
        }
        jsonGenerator.writeEndArray(); // Designs

        jsonGenerator.writeEndObject(); // Products
      }
      jsonGenerator.writeEndArray(); // Products

      jsonGenerator.writeEndObject(); // Booking
        
      return jsonGenerator.getAsString();        
    }
    
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // Description : Web Service to send complete Booking Details to Its Approved
    // Called From : "Test Submit Booking" botton on ItsApproved Booking Page
    // Returns     : from Web Service
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    webservice static String PostBooking(String json, String authorizationToken)
    {   
      // Now send the data to Its Approved
      HttpRequest req = new HttpRequest();
      HttpResponse res = new HttpResponse();
      Http http = new Http();

      req.setEndpoint('http://stagingv4ws.itsapproved.net/api/values/PostBooking');
      req.setMethod('POST');
      req.setHeader('Content-Type','application/json');
      req.setHeader('Authorization-Token', authorizationToken);
      req.setBody(json);
      req.setTimeout(60000);

  //    try {
          res = http.send(req);
                    
  //    } catch(System.CalloutException e) {
   //       System.debug('Callout error: '+ e);
   //       System.debug(res.toString());
   //   }
      
      //return res.toString();  
      return res.getBody();  
    }
    
    @future (callout=true)
    public static void TestReceiveNoLogonGet(String value) {
    
        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http();

        req.setEndpoint('http://stagingv4ws.itsapproved.net/api/values/TestReceiveNoLogonGet');
        req.setMethod('GET');
        //req.setBody('name='+EncodingUtil.urlEncode(value, 'UTF-8'));
        req.setCompressed(true); // otherwise we hit a limit of 32000

        try {
            res = http.send(req);
        } catch(System.CalloutException e) {
            System.debug('Callout error: '+ e);
            System.debug(res.toString());
        }
    }
    
    @future (callout=true)
    public static void TestReceiveNoLogonPost(String productNames) {

        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http();

        req.setEndpoint('http://stagingv4ws.itsapproved.net/api/values/TestReceiveNoLogonGet');
        req.setMethod('POST');
        req.setBody('model='+EncodingUtil.urlEncode(productNames, 'UTF-8'));
        req.setCompressed(true); // otherwise we hit a limit of 32000

        try {
            res = http.send(req);
                    
        } catch(System.CalloutException e) {
            System.debug('Callout error: '+ e);
            System.debug(res.toString());
        }
    }
    
    webservice static String TestReturnBookingTitle(String value) {    
        return value;        
    }
}

 
HI, I'm working on the follwoing controller class test for a VF page. I've no idea if it works yet but when I run a test I get the following error.
 
TestMethod do not support Web service callouts

I belive this is because there is another trigger on the system that first when one of the objects  in the below test class is created. I don't want to remove this trigger, but I'd like somehow to edit my code below so that it doesn't throw up the error. I've read about mock calls but I'm not sure where the code would sit in my class. Any help would be appreiciated
 
@isTest
public class CreateIABookingControllerTest{
    public static testMethod void myTest() {
    PageReference pageRef = Page.CreateIABookingPage;
    Test.setCurrentPage (pageRef);
    CreateIABookingController controller = new CreateIABookingController();
    
    	//Set up test Account
        Account testaccount = new Account (Name='test account');
        insert testaccount;
        
        //Set up test Opp
        Opportunity testopp = new Opportunity(AccountId=testaccount.Id, Name = 'test opp', StageName = 'Closed Won', CloseDate = System.today());
        insert testopp;
        
        //Set up test IABooking
        ItsApproved_Booking__c testiabooking = new ItsApproved_Booking__c(Opportunity__c=testopp.Id);
        insert testiabooking;
        
        //Set up test IAProduct
        ItsApproved_Product__c testiaproduct = new ItsApproved_Product__c(Booking_Reference__c=testiabooking.Id,Opp__c=testopp.Id);
        insert testiaproduct;
        
        //Set up test IADesign
        ItsApproved_Design__c testiadesign = new ItsApproved_Design__c(Product_Reference__c=testiaproduct.Id,Opportunity__c=testopp.Id);
        insert testiadesign;
        
        //Set up test IADelivery
        ItsApproved_Delivery__c testiadelv = new ItsApproved_Delivery__c(ItsApproved_Design__c=testiadesign.Id,Opportunity__c=testopp.Id,Product__c=testiaproduct.Id);
        insert testiadelv;
    
    	controller = new CreateIABookingController();
    
    	//start test - Create Booking
    	controller.ItsApprovedBooking.Opportunity__c = testopp.Id;//related Opp
        controller.ItsApprovedBooking.Booking_Title__c = 'Booking Title';
        controller.ItsApprovedBooking.Customer_Reference__c = 'Customer Ref';
    	insert controller.ItsApprovedBooking;
        //Add Product to Booking
        controller.ItsApprovedProduct.Booking_Reference__c = testiabooking.Id;//related Booking
        controller.ItsApprovedProduct.Opp__c = testopp.Id;//related Opp
        controller.ItsApprovedProduct.Product_Code__c = 'Static 6s';
        insert controller.ItsApprovedProduct;
        //Add Design to Product
        controller.ItsApprovedDesign.Product_Reference__c = testiaproduct.Id; //related Product
        controller.ItsApprovedDesign.Opportunity__c = testopp.Id; //related Opp
        controller.ItsApprovedDesign.Artwork_Title__c = 'Artwork Title';
        insert controller.ItsApprovedDesign;
        //Add Delivery to Design
        controller.ItsApprovedDelivery.ItsApproved_Design__c = testiadesign.Id; //related Design
        controller.ItsApprovedDelivery.Product__c = testiaproduct.Id; //related Product
        controller.ItsApprovedDelivery.Opportunity__c = testopp.Id; //related Opp
        controller.ItsApprovedDelivery.Depot_Code__c = integer.valueOf(123);
        controller.ItsApprovedDelivery.Quantity__c = integer.valueOf(10);
        insert controller.ItsApprovedDelivery;

    }
}

 
Hi I have to achive something that I'm struggling with at the moment (I've posted a few threads recently sorry)

I have a requirement as follows. I have a custom controller as follows
 
public with sharing class CreateIABookingController{
    public ItsApproved_Booking__c ItsApprovedBooking {get; set;} //Name the objects as a variables
    public ItsApproved_Product__c ItsApprovedProduct {get; set;}    
    public ItsApproved_Design__c ItsApprovedDesign {get; set;}
    public ItsApproved_Delivery__c ItsApprovedDelivery {get; set;}
    private string OpportunityId;
    public CreateIABookingController()
    
    {
        opportunityId = ApexPages.currentPage().getParameters().get('oppId');
        ItsApprovedBooking = new ItsApproved_Booking__c();
        ItsApprovedProduct = new ItsApproved_Product__c();
        ItsApprovedDesign = new ItsApproved_Design__c();
        ItsApprovedDelivery = new ItsApproved_Delivery__c();
    }
    
    public PageReference Save()
    {
        ItsApprovedBooking.Opportunity__c = opportunityId;
        insert ItsApprovedBooking;
        ItsApprovedProduct.Booking_Reference__c = ItsApprovedBooking.Id; //insert the reference field for the parent and declare variable id
        ItsApprovedProduct.Opp__c = opportunityId; //relate the Opp to the Product
        insert ItsApprovedProduct;            
        ItsApprovedDesign.Opportunity__c = opportunityId; //relate the Opp to the Design
        ItsApprovedDesign.Product_Reference__c  = ItsApprovedProduct.Id;
        ItsApprovedDelivery.Product__c = ItsApprovedProduct.Id;
        insert ItsApprovedDesign;
        ItsApprovedDelivery.ItsApproved_Design__c  = ItsApprovedDesign.Id;
        ItsApprovedDelivery.Opportunity__c = opportunityId; //relate the Opp to the Delivery
        insert ItsApprovedDelivery;
        
        return new PageReference ('/' + opportunityId);
    }
        
}
This allows the user to add a new Record (the Booking) with one related Product, Design and Delivery object on one page. This page is accessed via a button on the Opp record so that the Booking object is related to that OppID

Heres the VF page code
 
<apex:page controller="CreateIABookingController">
    <apex:form >
        <apex:pageBlock title="Booking Wizard">
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Save" action="{!Save}"/>
                </apex:pageBlockButtons>
            
            <apex:pageBlockSection columns="1" title="ItsApproved Booking Details">
                <apex:inputField value="{!ItsApprovedBooking.Booking_Title__c}" label="Booking Title: "/>
                <apex:inputField value="{!ItsApprovedBooking.Customer_Reference__c}" label="Customer Reference: "/>
                <apex:inputField value="{!ItsApprovedBooking.Incharge_Date__c}" label="In-Charge Date: "/>
            </apex:pageBlockSection>
                        
            <apex:pageBlockSection columns="3" title="Product Details">
                <apex:inputField value="{!ItsApprovedProduct.Product_Code__c}" label="Product Code: "/>
            </apex:pageBlockSection>
            
            <apex:pageBlockSection columns="1" title="Design Details">
                <apex:inputField value="{!ItsApprovedDesign.Artwork_Title__c}" label="Artwork Title: "/>
            </apex:pageBlockSection>
            
            <apex:pageBlockSection columns="1" title="Delivery Details">
                <apex:inputField value="{!ItsApprovedDelivery.Quantity__c}" label="Quantity: "/>
                <apex:inputField value="{!ItsApprovedDelivery.Depot_Code__c}" label="Depot Code: "/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

What I need to do is achieve the following

1. Add row functionaility
I would like the user to be able to add additional Designs and Delivery rows related to the Product (Products can have multiple designs and multiple deliveries

2. I'd also like the user to be able to add a full row of related objects, IE. Another row with a new Product selected, along with Design and Deliveries (but that row to also have the option of adding additional Designs and Deliveries.

I've experimented with PageBlockTable, but I can't work out the List since until the VF save is pressed, nothing exisits.

I've got loads of code examples from around the web but the classes are so different to mine that I don't know where to start. I'm floundering and could really use some help.
 
Hi, I'm working on creating records using a visualforce page.

I would like the option of creating more than one record (of the same type) if neccessary by adding variables to the class and having declaring them in different columns on the page. It works well, in fact too well! Even if the field is NULL it will create the record.

Here's the class code
public class CreateIABookingController{
    public ItsApproved_Booking__c ItsApprovedBooking {get; set;} //Name the objects as a variables
    public ItsApproved_Product__c ItsApprovedProduct {get; set;}
        //test variables for columns
            public ItsApproved_Product__c ItsApprovedProduct2 {get; set;}
            public ItsApproved_Product__c ItsApprovedProduct3 {get; set;}
        //end of test variables
    
    public ItsApproved_Design__c ItsApprovedDesign {get; set;}
    public ItsApproved_Delivery__c ItsApprovedDelivery {get; set;}
    private string OpportunityId;
    public CreateIABookingController()
    {
        opportunityId = ApexPages.currentPage().getParameters().get('oppId');
        ItsApprovedBooking = new ItsApproved_Booking__c();
        ItsApprovedProduct = new ItsApproved_Product__c();
            //test variables for columns
                ItsApprovedProduct2 = new ItsApproved_Product__c();
                ItsApprovedProduct3 = new ItsApproved_Product__c();
            //end test variables for columns
        ItsApprovedDesign = new ItsApproved_Design__c();
        ItsApprovedDelivery = new ItsApproved_Delivery__c();
    }
    
    public PageReference Save()
    {
        ItsApprovedBooking.Opportunity__c = opportunityId;
        insert ItsApprovedBooking;
        ItsApprovedProduct.Booking_Reference__c = ItsApprovedBooking.Id; //insert the reference field for the parent and declare variable id
        ItsApprovedProduct.Opp__c = opportunityId; //relate the Opp to the Product
        insert ItsApprovedProduct;
            //test for columns
                ItsApprovedProduct2.Booking_Reference__c = ItsApprovedBooking.Id;
                ItsApprovedProduct2.Opp__c = opportunityId;
                insert ItsApprovedProduct2;
                    ItsApprovedProduct3.Booking_Reference__c = ItsApprovedBooking.Id;
                    ItsApprovedProduct3.Opp__c = opportunityId;
                    insert ItsApprovedProduct3;
            //end test for columns
            
        ItsApprovedDesign.Opportunity__c = opportunityId; //relate the Opp to the Design
        ItsApprovedDesign.Product_Reference__c  = ItsApprovedProduct.Id;
        ItsApprovedDelivery.Product__c = ItsApprovedProduct.Id;
        insert ItsApprovedDesign;
        ItsApprovedDelivery.ItsApproved_Design__c  = ItsApprovedDesign.Id;
        ItsApprovedDelivery.Opportunity__c = opportunityId; //relate the Opp to the Delivery
        insert ItsApprovedDelivery;
        
        return new PageReference ('/' + opportunityId);
    }
}

What I'd like to do is add something to the class that will ignore the insert of ItsApprovedProduct2, ItsApprovedProduct3 if they are NULL. I'm guessing that might be an IF isNotEmpty statement around the {get;set;} of the variables? I'm not too sure on the syntax though...
 
Hi, I'm creating something that makes use of four custom objects.

The objects are related to the Opp object and are as follows
-Booking object
-Product (not SF native product, it's just names the same)
-Design
-Delivery

What I'm discovering is that to add a booking to the Opp with products, designs and deliveries is extremely unweildy for the user and requeries a great deal of clicks and I want to design the process to be as easy as possible.

Is it possible to create a visual force page all the fields neccessary for each object are visible? I fear this may require trigger writing, but if that's the case I'll post the question elswhere but I thought I'd ask here first.
 
Hi, does anyone know how I can replicate revenue scheduling but without having to use Price and Products?

An arm of our business deals services that are booking in 3, 6 and 12 month contracts (NOT SF Contracts btw) and the costs are repeated on a monthly basis for the duration of the contract.

These opportunities are added and worked on until they are marked as closed won. We have a custom field that shows the margin of this particular job. This figure is added to the departments figures. (We don't use Amount, only this custom feild)

I'm trying to find a way of ensuring that this margin is added to figures each month for the duration of the contract.

For example a client signs off on a £1000 per month campaign for 12 months and the margin to the team on that is 15% so thier margin is £150.

I'd like £150 adding to the salespersons figures automatically every month until this ends. It looks like revenue scheduling does this, but we wouldn't be able to use products and price lists. Each job is a service and therefore vastly different from client to client.

Does anyone have any ideas on how this could be achieved reletively simply?
Hi, I have a articular use case for Process Builder and flows but I can't get it to work.

There are two obects involved, Opportunity and a custom object MC

I have created a process that when triggered creates the MC object on the Opp that triggered the flow

The next step is to create a new Opp based on the first Opp. I can do this in Process fine. But what I need to do is create a new MC object on the newly created Opp.

I can't do this with Process as all it does is add two MC objects to the original Opp.

I've tried to create the new Opp with a flow nd put that in the Process but I can't get that to work yet and I'm still not sure I'll be able to add a new MC object to that created Opp.

Does anyone have any advice?
Hi all, I'm writing a formula for quite a complex scoring matrix.

BACKGROUND: I have 8 picklists, the results of which hold a score number (4-1). One of the picklist values is NA and is counted separatley
These numbers are tallied WFR into two fields WFR_Score and WFR_NA.

If NA = 0 the results are 

If the Score >=24, Excellent
>= 13 and < 23, Needs Improvement
<=12, Poor

Code is below. The problem is I can't get the Poor result to show as I think there is some conflict in the scoring less and greater than. Also I will have 8 iterations of this to do WRF_NA_Count__c=1, =2, =3 etc and I think my code is a little bloated. Can I streamline it down in line count?
 
IF(
AND(
WFR_NA_Count__c = 0,
OR(
WFR_Score__c  >= 24)), "Excellent/Competent",
IF(
AND(
WFR_NA_Count__c = 0,
OR(
WFR_Score__c  >= 13,
WFR_Score__c  <= 23)), "Needs Improvement",
IF(
AND(
WFR_NA_Count__c = 0,
OR(
WFR_Score__c  < 12)), "Poor",
"ERROR"
)))

 
Hi I have a datetime field called 'Last Contact'

This field shows the latest datetime from two other fields. Here's the code
 
NOW()- 
MIN( 
NOW()- MMERP__LastDatetimeSent__c , 
NOW()- Last_Call_Made__c 
)

It works fine, but if one of the fields is blank, the resulting field is blank.

How can I edit the formula above to post the datetime value from the filed that has a value out of the two?
I have a simple button that when clicked, cheanged the record type of the Opportunity in order to fire an email alert.
 
{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")} 

var oppObj = new sforce.SObject("Opportunity"); 
oppObj.Id = '{!Opportunity.Id}'; 
oppObj.RecordTypeId = '01220000000ML20'; 
var result = sforce.connection.update([oppObj]); 

if (result[0].success=='false') { 
alert(result[0].errors.message); 
} else { 
alert("Success, Admin have been notified."); 
location.reload(true); 
}

However, I'd like to add a query so that if the button has already been clicked, another alert will show to the user.

Would it be possible for the button to check the RecordTypeID and if the record has alredy been changed to 01220000000ML20, the alternative alert is shown.

Here's what I've tried, but the syntax isn't correct. Any tips?
 
{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")}
 
var oppObj = new sforce.SObject("Opportunity"); 
oppObj.Id = '{!Opportunity.Id}'; 
oppObj.RecordTypeId = '01220000000ML20'; 
var result = sforce.connection.update([oppObj]); 
 
if ({oppObj.RecordTypeId = '01220000000ML20'; )}
{alert("This has already been approved."); 
     location.reload(true);}
){ else if (result[0].success=='false') {
     alert(result[0].errors.message);
} else {
alert("Success, Admin have been notified."); 
     location.reload(true);
}

 
Hi all,

I have to create a formula that I am unsure on the the syntax for.

This is for a formula field on the Opportunuty record. It will reference one of 12 fields that are populated on the User record.

What I need to do is have the formula check what Month the CloseDate is and then use one of the correllating fields on the User record to work out a percentage

So if the CloseDate is April, the formula will use the April field in the User record, if it's March, it will use the March field in the User record.

To throw more complexity in I am using ranges and different percentages based on user and profile ID.

The below formula works but it only references one field (the current month)
 
IF( 
OR(Owner.Profile.Id = "00e20000001V4Xd",Owner.UserRoleId = "00E2000000151Hy"), 
Margin__c * 0.15, 



IF( 
AND(Users_Total_Margin__c <= 10000,Users_Total_Margin__c >= 1, 
OR(Owner.Profile.Id <> "00e20000001V4Xd", Owner.UserRoleId <> "00E2000000151Hy")), 
Margin__c * 0.06, 



IF( 
AND(Users_Total_Margin__c >= 10001,Users_Total_Margin__c <=20000, 
OR(Owner.Profile.Id <> "00e20000001V4Xd", Owner.UserRoleId <> "00E2000000151Hy")), 
Margin__c * 0.11, 



IF( 
AND(Users_Total_Margin__c >= 20001,Owner.UserRoleId <> "00E2000000151ID"), 
Margin__c * 0.15,0 
))))

The fields on the users record are March__c, April__c, May__c etc and are rollups.

Any ideas?
Hi, I've created a formula in a summery report to calculate user commision. it's works but I need to add certain caveates into the formula.

Here's what I've got
IF(Opportunity.Margin__c:SUM <= 10000, Opportunity.Margin__c:SUM * 0.06,

IF(AND(Opportunity.Margin__c:SUM >= 10001,Opportunity.Margin__c:SUM <= 20000),
Opportunity.Margin__c:SUM * 0.11,

IF(Opportunity.Margin__c:SUM >= 20001, Opportunity.Margin__c:SUM * 0.15,0
)))

This works out the commsions based on the critera fine. However I need to add in record ID (if record ID = x, don't calculate) and also Profile. IF profile = X, use this calculation.

Does anyone know if this is possible in a summary report?
Hi all, I've have created a complex 'app' in my Sandbox and I want to use a Package to deploy to Production. However, the Package makes use of a few custom fields that already exist in my production org. I don't want to rename these on install as it will effect current workings.

It looks like I can't remove these few custom feilds from the package so am I reduced to using a change set?

In your experiences, what do you suggest?
Hi, I'm trying to load test data into a @isTest but I need to account for Lists and I can't find the right solution, the error is always that the list is out of bounds. I need to load test data for deployment into my org (in the sandbox I was using seeAllData)

The webservice class looks like this (jsut the GET section here)
 
webservice static String GetBookingDetails(ID id) {
    JSONGenerator jsonGenerator = JSON.createGenerator(true);
          
      ItsApproved_Booking__c booking = [SELECT Id, Name, Booking_Title__c, Customer_Reference__c, Incharge_Date__c FROM ItsApproved_Booking__c WHERE Id = :id];

      jsonGenerator.writeStartObject(); // Booking      
      //jsonGenerator.writeStringField('CompanyId', '798365d8-4278-4b16-a330-c4a3a9e1f91f'); // Staging Company Id
      //jsonGenerator.writeNumberField('UserId', 84); // Staging Company Id
      jsonGenerator.writeStringField('CompanyId', '042D7C6D-00E4-4C81-901A-BC8F8B545441'); // Live Company Id
      jsonGenerator.writeNumberField('UserId', 96); // Live User Id
      jsonGenerator.writeStringField('BookingTitle', booking.Booking_Title__c);
      jsonGenerator.writeStringField('CustomerReference', booking.Customer_Reference__c);
      jsonGenerator.writeStringField('CustomerBookingId', booking.Name);
      jsonGenerator.writeDateTimeField('InchargeDate', booking.Incharge_Date__c);

      List<ItsApproved_Product__c> products = [SELECT Id, IAProduct__c, Booking_Reference__c FROM ItsApproved_Product__c WHERE Booking_Reference__c = :Id];

      jsonGenerator.writeFieldName('Products');
      jsonGenerator.writeStartArray(); // Products
      for(ItsApproved_Product__c p: products)
      {
        List<IA_Product__c> IAProducts = [SELECT Id, Code__c FROM IA_Product__c WHERE Id = :p.IAProduct__c];

        jsonGenerator.writeStartObject(); // Products
        jsonGenerator.writeStringField('ProductionCode', IAProducts[0].Code__c);           
        jsonGenerator.writeStringField('CustomerProductReference', IAProducts[0].Code__c);           

        List<ItsApproved_Design__c> designs = [SELECT Id, Artwork_Title__c FROM ItsApproved_Design__c WHERE Product_Reference__c = :p.Id];

        jsonGenerator.writeFieldName('Designs');
        jsonGenerator.writeStartArray(); // Designs
        for(ItsApproved_Design__c d: designs)
        {
          jsonGenerator.writeStartObject();
          jsonGenerator.writeStringField('CustomerDesignId', d.Id);           
          jsonGenerator.writeStringField('DesignName', d.Artwork_Title__c);           

          List<ItsApproved_Delivery__c> deliveries = [SELECT Id, IADepot__c, Quantity__c FROM ItsApproved_Delivery__c WHERE ItsApproved_Design__c = :d.Id];

          jsonGenerator.writeFieldName('Deliveries');
          jsonGenerator.writeStartArray(); // Deliveries
          for(ItsApproved_Delivery__c del: deliveries)
          {
            List<IADepot__c> IADepots = [SELECT Id, Depot_Code__c FROM IADepot__c WHERE Id = :del.IADepot__c];

            jsonGenerator.writeStartObject(); // Deliveries
            jsonGenerator.writeStringField('DeliveryId', del.Id);           
            jsonGenerator.writeStringField('DepotCode', IADepots[0].Depot_Code__c);
            jsonGenerator.writeNumberField('Quantity', del.Quantity__c);
            jsonGenerator.writeEndObject(); // Deliveries
          }
          jsonGenerator.writeEndArray();  // Deliveries

          jsonGenerator.writeEndObject(); // Designs
        }
        jsonGenerator.writeEndArray(); // Designs

        jsonGenerator.writeEndObject(); // Products
      }
      jsonGenerator.writeEndArray(); // Products

      jsonGenerator.writeEndObject(); // Booking
        
      return jsonGenerator.getAsString();        
    }

And here's my test class, as you can see I've not faciliated any List data yet as I can't work out the best approach. If we use the first List as an example
 
List<ItsApproved_Product__c> products = [SELECT Id, IAProduct__c, Booking_Reference__c FROM ItsApproved_Product__c WHERE Booking_Reference__c = :Id];

How do I load test data with at least 1 record in the list?

@isTest here
 
@isTest
public class Testing_ItsApprovedWebServices {

	@isTest public static  void ItsApprovedWebServicesTest(){
        ItsApproved_Booking__c bookingdetails = new ItsApproved_Booking__c(Booking_Title__c = 'Test', Customer_Reference__c = 'Test',Incharge_Date__c = System.today() );
    	insert bookingdetails;
        
        ItsApproved_Product__c productdetails = new ItsApproved_Product__c(Booking_Reference__c = bookingdetails.Id);
        insert productdetails;

        IA_Product__c iaproduct = new IA_Product__c(Code__c = '606');
        insert iaproduct;

        ItsApproved_Design__c designdetails = new ItsApproved_Design__c(Product_Reference__c = productdetails.Id);
        insert designdetails;
        
        ItsApproved_Delivery__c deliverydetails = new ItsApproved_Delivery__c(Product__c = productdetails.Id, ItsApproved_Design__c = designdetails.Id);
        insert deliverydetails;
        
        Test.startTest();
        Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator()); 

        String username = ItsApprovedWebServices.Login('test');
        String details = ItsApprovedWebservices.GetBookingDetails(bookingdetails.Id);
		
        Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator2()); 
        String postbooking = ItsApprovedWebServices.PostBooking('{"test" : "test"}','authorization_id');
		
        Test.stopTest();
    }		
}



 
Hi all, when you have a test class in your sandbox that references the ID of a record of a custom object within the sandbox, how to do get round the fact that this object and record won't exist in your production org when you come to test the changeset?

Hi

 

I am experiencing a strange situation where the Grand Total of a report is wrong.

I have a report on opporutnity with three groupings and total revenue field is summarized for each grouping. After applying some fiters, I hidden the details of the report and did a printable view.

 

In the excel when I take the totals from the first grouping and count them, the total is different than the one showing in report. And that difference is huge in terms of revenue( more than 15 million) I am not able to figure what is the issue here, can any one please help.

 

Thanks,

Jagan

  • August 22, 2013
  • Like
  • 0