• RPal
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies
I have requirement to clear out the fields not included in the page layout when I switch from on record type to other. So lets say a record is created for record type 'A' and has 10 fields and when I change the record to record type 'B' which has 6 fields (all these 6 fields are subset of fields in RT 'A') then remaining 4 fields should 'null' out. I know I can do that with a trigger or process builder but in that case I would have to mention each and every field and its relative value. It would be a very long process so I was wondering if there is a simple funtion to do this?
  • March 27, 2018
  • Like
  • 1
Can someone please tell me how should I generate JSON for standard fields. I get error When i do it for standard or lookup fields:

Opportunity Opp = Trigger.new[0] ; 
JSONGenerator gen = JSON.createGenerator(true);    
    gen.writeStartObject();      
    gen.writeStringField('Agency Code', Opp.Agency_Code__c);
    gen.writeStringField('Account',Opp.Account);
    gen.writeStringField('Implementation Contact',Opp.Implementation_Contact__c);
    gen.writeStringField('Implementation Contact Email',Opp.Implementation_Contact__c.Email);
    gen.writeStringField('Implementation Contact ID',Opp.Implementation_Contact__c.Record_ID_full__c);
    gen.writeStringField('Opportunity Owner',Opp.Owner);
    gen.writeStringField('Opportunity Owner Email',Opp.Owner.Email;
    gen.writeStringField('Last Modified By Name',Opp.LastModifiedBy);
    gen.writeStringField('Opportunity ID',Opp.Record_ID_Full__c);
    gen.writeStringField('Account',Opp.Account);
    gen.writeStringField('Account',Opp.Account);
    gen.writeEndObject();    
    String jsonS = gen.getAsString();
System.debug('jsonMaterials'+jsonS);
String endpoint = 'http://www.example.com/service';
HttpRequest req = new HttpRequest();
req.setEndpoint(endpoint);
req.setMethod('POST');
req.setbody(jsonS);
Http http = new Http();
HTTPResponse response = http.send(req);

All the custom fields on opprtunity are working just fine but the lookup fields and standard field shows syntax error.

User-added image
Can anyone please suggest?
  • February 20, 2018
  • Like
  • 0
I have requirement to clear out the fields not included in the page layout when I switch from on record type to other. So lets say a record is created for record type 'A' and has 10 fields and when I change the record to record type 'B' which has 6 fields (all these 6 fields are subset of fields in RT 'A') then remaining 4 fields should 'null' out. I know I can do that with a trigger or process builder but in that case I would have to mention each and every field and its relative value. It would be a very long process so I was wondering if there is a simple funtion to do this?
  • March 27, 2018
  • Like
  • 1
I have requirement to clear out the fields not included in the page layout when I switch from on record type to other. So lets say a record is created for record type 'A' and has 10 fields and when I change the record to record type 'B' which has 6 fields (all these 6 fields are subset of fields in RT 'A') then remaining 4 fields should 'null' out. I know I can do that with a trigger or process builder but in that case I would have to mention each and every field and its relative value. It would be a very long process so I was wondering if there is a simple funtion to do this?
  • March 27, 2018
  • Like
  • 1
Can someone please tell me how should I generate JSON for standard fields. I get error When i do it for standard or lookup fields:

Opportunity Opp = Trigger.new[0] ; 
JSONGenerator gen = JSON.createGenerator(true);    
    gen.writeStartObject();      
    gen.writeStringField('Agency Code', Opp.Agency_Code__c);
    gen.writeStringField('Account',Opp.Account);
    gen.writeStringField('Implementation Contact',Opp.Implementation_Contact__c);
    gen.writeStringField('Implementation Contact Email',Opp.Implementation_Contact__c.Email);
    gen.writeStringField('Implementation Contact ID',Opp.Implementation_Contact__c.Record_ID_full__c);
    gen.writeStringField('Opportunity Owner',Opp.Owner);
    gen.writeStringField('Opportunity Owner Email',Opp.Owner.Email;
    gen.writeStringField('Last Modified By Name',Opp.LastModifiedBy);
    gen.writeStringField('Opportunity ID',Opp.Record_ID_Full__c);
    gen.writeStringField('Account',Opp.Account);
    gen.writeStringField('Account',Opp.Account);
    gen.writeEndObject();    
    String jsonS = gen.getAsString();
System.debug('jsonMaterials'+jsonS);
String endpoint = 'http://www.example.com/service';
HttpRequest req = new HttpRequest();
req.setEndpoint(endpoint);
req.setMethod('POST');
req.setbody(jsonS);
Http http = new Http();
HTTPResponse response = http.send(req);

All the custom fields on opprtunity are working just fine but the lookup fields and standard field shows syntax error.

User-added image
Can anyone please suggest?
  • February 20, 2018
  • Like
  • 0
Thanks to the Trailhead module regarding APEX Rest callout I know how to post "mighty moose" to an endpoint ;-)

I am wondering how I can create and send a JSON string based on Salesforce fields. For example I want to send a case to an external system via a REST Post method with the following field mapping:
Ticket Number = CaseNumber
Ticket Status = Status
Ticket Priority = Priority

How would I change the request.setBody('{"name":"mighty moose"}'); line to succesfully generate the required JSON code for the external system?

I'm trying to create a formula which calculates the business hours (8am - 5pm) between a task being created and closed.

 

I created a custom "ClosedDate" field on the task object.

 

I found an example online: http://help.salesforce.com/apex/HTViewSolution?id=000089863&language=en_US

 

I tested creating a task today (Oct. 28) and closing it with a date of Oct. 30th.  The number of hours shown the formula field displayed 36 hours.  It should only show the business hours between 8am and 5pm and exclude weekends.  Is there a way to adjust the formula in the link above to accommodate those requirements?

 

Thanks for any help!