• Omar Rajab 94
  • NEWBIE
  • 280 Points
  • Member since 2018


  • Chatter
    Feed
  • 7
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 59
    Replies
Hi!

I want to upload an audio file to Salesforce's voice call standard object. I created the voice call record but now I can not figure out how to upload the audio properly. I keep getting the "Missing audio file".

Thank you in advance :)

User-added image
Gentelmen I know you have more than free time for challenges like this
I have downloaded all metadata for reports and rep types
I have found one specific fields that is in there 
Now I need to get all creators/modifiers of these reports 
Doesn't matter that I hit SOQL character limit 20,000 which is really 4000 for WHERE CLAUSE I have more than 2000 lines and ~70000 - doesn't matter. 
All I need is to get emails from creator or last modified but if I ran this query
select CreatedBy.Email, COUNT(CreatedById), LastModifiedById 
from Report
where DeveloperName IN
(LOTS OF REPORTS BY DEV NAME,
LOTS OF REPORTS BY DEV NAME)
group by CreatedBy.Email, LastModifiedById
Above code works but if I want both emails fields I am interested in then I get
 
select CreatedBy.Email, COUNT(CreatedById), LastModifiedBy.Email
from Report
where DeveloperName IN
(LOTS OF REPORTS BY DEV NAME,
LOTS OF REPORTS BY DEV NAME)
group by CreatedBy.Email, LastModifiedBy.Email

I will get an MALFORMED_QUERY: duplicate alias: Email

I have went through ALIAS keywordk in SOQL & SOSL guide but without success.

Hi everyone,

I'm completely new to Apex and invocable methods so any help would be greatly appreciated.

I'm trying to create an invocable method that uses the Business Hours class. I'd like to pass the Created Date of a record in a record-triggered flow into Apex and check if the Created Date is within Business Hours. I would then like to return a boolean as the output variable that I can then use in a decision element to trigger a record creation.

Here's what I have pasted together from what I could find via help articles and a previous post:

global class CreatedDateWithinBusinessHours {
        @InvocableMethod(label = 'Check if within BH' description = 'Check if record Created Date is within business hours')
            public static List<Results> execute(List<Requests> requestList) {
            List<SObject> inputCollection = requestList[0].inputCollection;
            // Get the default business hours
            BusinessHours bh = [SELECT Id FROM BusinessHours WHERE IsDefault = true];
            
            // Is this where I would use my Created Date input variable I'm passing from the flow?
            Datetime targetTime = Datetime();

            // Find whether the time is within the default business hours. Is this the boolean I would use as the output variable to use in my flow?
            Boolean isWithin = BusinessHours.isWithin(bh.id, targetTime);

            //Create a Results object to hold the return values
            Results response = new Results();

            //Add the return values to the Results object
            response.outputMember = isWithin;

            //Wrap the Results object in a List container 
            //(an extra step added to allow this interface to also support bulkification)
            List<Results> responseWrapper = new List<Results> ();
            responseWrapper.add(response);
            return responseWrapper;
    }

    //
    global class Requests {
        @InvocableVariable(label = '' description = 'Test Description' required = false)
        public List<SObject> inputCollection;
        
    }
    //
    global class Results {
        @InvocableVariable(label = 'Within Business Hours' description = '' required = true)
        public Boolean outputMember;
    }
}

 

Hi
Would someone be able to help me please?
i have a trigger which inserts child records when a field is populated, it works fine but have 2 issues 

1. The Month field (crd.name) is starting from 0 ideally would like it to start from 1
2. I want to add a month to each record (crd.mrr date__c) 

Idea is it would create 10 records if Opp.Contract_period_months__c) = 10

Here is my code

Trigger CreatingAutoRecords on Opportunity (After Insert, After Update)
{
    
    List<MRR__c> MRRRecordsFinalListToInsert = New List<MRR__c>();
    
    If(Trigger.IsInsert || Trigger.IsUpdate)
    {
        For(Opportunity opp : Trigger.New)
        {
            If(Opportunity.Contract_Period_Months__c != null)
            {
                List<MRR__c> fetchingAlreadyExixtsedRecords = [Select Id FROM MRR__c WHERE Opportunity__c =:opp.Id];
                
                If(fetchingAlreadyExixtsedRecords.IsEmpty())
                {
                    // We are only creating a records when there is no MRR__c records exixts.
                    For(Integer I = 0; I < opp.Contract_Period_Months__c;I++)
                    
                        {
                        MRR__c crd = New MRR__c();
                        
                        crd.Opportunity__c = opp.Id;
                        crd.Name       = 'Month' + I;
                        crd.MRR_Amount__c = opp.MRR_Amount__c;
                        crd.MRR_Date__c = opp.Contract_Start_Date__c ;
                        
                        MRRRecordsFinalListToInsert.add(crd);
                    }
                }
                
            }
            
            try{
                If(!MRRRecordsFinalListToInsert.IsEmpty()){
                    insert MRRRecordsFinalListToInsert;
                }
            }
            Catch(Exception e){
                System.debug('The thrown exception for CreatingAutoRecords is:: ' + e.getMessage());
            }
        }
    }
    
    
}

Any help would be highly appreciated
 

Hi,

 

This is my first question and I'm completely new to Apex.

I'm essentially trying to write am invocable class that I can use in a flow. It should check now() against the default business hours and return a boolean as an output variable that I can then use in a decision element. 

I think I found the piece on writing the query for business hours but I'm not sure how to turn that into an invocable action that I can use in a flow.

Any help would be greatly appreciated!!

Hello,

I would like to retrieve a record using its ID only(not knowing object type) using REST API.
All REST API documentation mentions the method where sobject type is known and added 
Ex:  /services/data/v51.0/sobjects/Customer__x/x01D0000000002RIAQ

I would like to get the object, or even it's object type using its ID only
As this works great without issues via browser "https://cs22.lightning.force.com/x01D0000000002RIAQ"

Is there anyway to achieve it via REST API? if not what could be done to get the sobject type by ID?
Hi ! 

Can anyone tell me how to write trigger for this scenario, please ?

On Order object, I have 2 custom fields : 
   - Net_amount__c : is total amount without shipment cost
   - Shipment_cost__c

I would like to update Net_amount__c field. 


My trigger is bellow, but there are many problems :

1) When an order is created :
Total amount : 0
Net_amount__c : 
Shipment_cost__c : 100

2) When an order is updated :
Total amount : 100
Net_amount__c : -50
Shipment_cost__c : 50



trigger CalculMontantTrigger on Order (before update) {
   
    for (Order o: Trigger.new) {
        o.Net_amount__c = o.TotalAmount - o.Shipment_cost__c;
    }
}
  • March 30, 2021
  • Like
  • 0
I need to write Apex Webservice which will accept Http response and parse the JSON based on Wrapper , and create records. This webservice will be exposed so that it can be accessed outside. do you have any sample class, please help
Hi. I want to use the data query REST endpoint to access ServiceContract data from the context of a Community Cloud user.

Contracts are listed as something that Community Cloud licences have access to, but it looks like they don't have access to ServiceContract data (I originally thought these were the same thing).

For example, the following query works within the developer console in Salesforce, and the REST query works if using an employee auth-token, but when queried on behalf of a Community Cloud user the query fails:

{{url}}/services/data/v51.0/query/?q=SELECT StartDate,EndDate FROM ServiceContract

Error:
[
    {
        "message": "\nSELECT StartDate,EndDate FROM ServiceContract\n                              ^\nERROR at Row:1:Column:31\nsObject type 'ServiceContract' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names.",
        "errorCode": "INVALID_TYPE"
    }
]

I can't find an option to enable access to the ServiceContract object in the CommunityCloud users profile.

So how can I enable this?

Cheers, Aaron.
I have a requirement, where I have a scheduled apex which runs every 5 mins and invokes a future method of an apex class. This future method invokes a managed package method for making the callout. So the current logic is that in a for loop for every record I am forming the request and invoking the Managed package method to perform the callout. The callout gives a response and on the basis of response I have to perform another callout or just move ahead. Now the problem is that there is DML transaction happening in the Managed package method as confirmed by the client. So while performing the 2nd callout or the callout for next record, I get the System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out.

What approach can I take achieve this requirement?

Here is the snippet of how logic is written now

Schedule Class -> invokes Apex class method
processRecords()
{
In this there are 3 SObjects maps which are serialized and sent to the future method
}
futureMethod(){
Deserialize the input
for(every record)
{ create the request invoke the managed package method to perform callout if response success put data in map for DML in the end after for loop if response failure invoke 2nd callout
}
}
In the end perform DML operations.
Getting this below error :
'System.CalloutException: Web service callout failed: Unable to find header type info fortokenRes'
public class HospitalController {
   
    
    
 public Appointment__c appt {get; set;}
    public List<Doctor__c>  doclists{set;get;}
    public String selectedDoctor {get; set;}
    public String selectedPatient {get; set;}
    public Datetime appDate {get; set;}
    public List<Doctor__c> DoctorList {get;set;}
    public List<SelectOption> doctorSelectOptionList {get;set;}
    public List<Patient__c> PatientList {get;set;}
    public List<SelectOption> patientSelectOptionList {get;set;} 
    public Integer duration {get; set;}
    public List<appointment__c> tableAppointments{get; set;}
    public Time TimeStart {get;set;}
    
    public PageReference addNewAppt() {
     return null;
}
    public Integer PageNumber {get; set;}
    Public Integer PageSize {get;set;}
    Public Integer ResultSize {get;set;} 
    

     public list<Doctor__c> getDoc()
    {
       return [Select working_hours_start__c From Doctor__c];
           
    }
    
    public PageReference redirectToMyVF(Id accId) { 
    PageReference myVFPage = new PageReference('/apex/myVFPage');
    myVFPage.setRedirect(true);
    myVFPage.getParameters().put('myId', accId);
    return myVFPage;
}
 
    public HospitalController() {
        this.appt = new Appointment__c();
        this.selectedDoctor = '';
        this.selectedPatient = '';
        this.appDate = System.now();
        this.duration = 30;
        
        
    
        
            
        doctorSelectOptionList = new List<SelectOption>();
        patientSelectOptionList = new List<SelectOption>();
     
        
        DoctorList = [SELECT iD, Name,working_hours_start__c FROM Doctor__c];
        //TimeStart = DoctorList.working_hours_start__c;
        for (Doctor__c doc : DoctorList){ 
            doctorSelectOptionList.add(new SelectOption(doc.Id, doc.Name)); 
        }
             
        PatientList = [SELECT Id, Name FROM Patient__c];
        for (Patient__c patient : PatientList){
            patientSelectOptionList.add(new SelectOption(patient.Id, patient.Name)); 
        }
    }
    }
and visualforce page 
<apex:page docType="html-5.0" controller="HospitalController" showHeader="false" sidebar="false">
<apex:form >
<apex:pageBlock title="Appointmets Table">


<!-- Select a doctor -->
<apex:pageBlockSection>
 Select a doctor:
<apex:selectList size="1" value="{!selectedDoctor}">
<apex:selectOptions value="{!doctorSelectOptionList}"/>
<apex:actionSupport event="onchange" 
reRender="app_list1, app_list2, app_list3"/>
</apex:selectList>
</apex:pageBlockSection>

<!-- Select a patient -->
<apex:pageBlockSection>
Select a patient:
<apex:selectList size="1">
<apex:selectOptions value="{!patientSelectOptionList}"/>
</apex:selectList>
</apex:pageBlockSection>
    

<apex:pageBlock>

  <apex:pageBlockTable value="{!Doc}" var="item">
       <apex:column value="{!item.working_hours_start__c}"/>
  </apex:pageBlockTable> 

</apex:pageBlock>






    
   
    
    <apex:pageBlockSection >
<apex:commandButton immediate="false" reRender="app_list3" action="{!addNewAppt}" value="Add New Appointment" />
</apex:pageBlockSection>
    
    <!-- Appointment date -->
<apex:pageBlockSection >
<apex:inputField label="Appointment date" 
value="{!appt.Appointment_Data__c}"
required="false"/>
</apex:pageBlockSection>
    
     <apex:pageBlockSection >
                <apex:inputField label="Duration in minutes" 
                            value="{!appt.Duration_in_minutes__c}"
                            required="false"/>
            </apex:pageBlockSection>
    
    
<!-- Pagination -->
    
<table style="width: 100%"><tr>
<td>
Page: <apex:outputText 
value="{!PageNumber} of {!CEILING(ResultSize / PageSize)}"/>
</td> 
<td align="center">
<!-- Previous page -->
<!-- active -->


<!-- Next page -->
<!-- active -->
    </td>

<td align="right">
<!-- Records per page -->
Records per page:
<apex:selectList value="{!PageSize}" size="1">
<apex:selectOption itemValue="5" itemLabel="5"/>
<apex:selectOption itemValue="20" itemLabel="20"/>
<apex:actionSupport event="onchange" reRender="contacts_list"/>
</apex:selectList>
</td>
</tr></table>
    
    
    
  
    
    
    
    </apex:pageBlock>
    </apex:form>
</apex:page>


 
I have a flow error that is occasionally firing and I am trying to trouble shoot it to see how the interview began. The record id that is listed to advise where the interview started is not pulling up anything in my org. I just get a page cannot be found message.

Is there another way to see where this flow was used so I can diagnose why the flow is failing?

Thanks!
Neil
Hi!

I want to upload an audio file to Salesforce's voice call standard object. I created the voice call record but now I can not figure out how to upload the audio properly. I keep getting the "Missing audio file".

Thank you in advance :)

User-added image

Hello, I have an API appexchange app that is already published and I wanted to add the option to embed our page inside the lead & contact details page. It would be a small block containing the lead details that we have in our database, so this component needs to send a GET or POST request to our embed url page containing the leadID / contactID somehow.

I never did any visual things on Salesforce, so I don't know if that would be a canvas app, lightining page, visualforce, etc. Some guides would be great!

 

Thank you.

Dear All,
I'm developing a UnitTest class for a legacy Apex class. In the developer console from the full sandbox I get 77% code coverage and no error. When I try to move it to production I get the following error messages:

1. Class Name: UnitTest_MIPLibray, Method Name: testCreateTask:
System.DmlException: Upsert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CLDR.OpportunityModified: execution of AfterInsert caused by: System.QueryException: List has no rows for assignment to SObject Trigger.CLDR.OpportunityModified: line 22, column 1: []
Stack Trace: Class.MIPLibrary.createOpportunity: line 1116, column 1 Class.UnitTest_MIPLibrary.testCreateTask: line 574, column 1


2. ClassName: UnitTest_MIPLibrary, Method: testGetContact:
System.StringException: Invalid id: null
Stack Trace: Class.MIPLibrary.hasContactModified: line 820, column 1 Class.MIPLibrary.hasContactModified: line 689, column 1 Class.UnitTest_MIPLibrary.testGetContact: line 481, column 1

I don't understand how to fix it. To me, it all looks legit. The Outbound changeset (from FULL -> Prod), contains both the MIPLibrary and the UnitTest_MIPLibrary, and I validate the deployment only towards the UnitTest_MIPLibrary.

For the (1), this is the code in the unitTest class:
 
static testMethod void testCreateTask() {
        Account testAccount = null;
            testAccount = new Account();
            testAccount.Name = 'TestAccount';
            testAccount.Business_Unit__c = 'Digital Marketing';
            testAccount.Edition_Setup__c = 'Basic';
            testAccount.Naming_rights__c = 'NO';
            testAccount.Naming_Rights_Type__c = 'Full';
            
            Id userId = UserInfo.getUserId();
            User userObj = MIPLibrary.getUsersInfo(userId);
            
            
            
            /*MIPLibrary.createTask(testAccount, userObj, userObj, null, 'MQL', userId, userId, '', '', 'blah', '', '');
            MIPLibrary.createTask(testAccount, userObj, userObj, null, 'SQL', userId, userId, '', '', 'blah', '', '');*/
            MIPLibrary.createTask(testAccount, userObj, userObj, null, 'SAL', userId, userId, '', '', 'blah', '', '');
            
            Opportunity tmpOp = new Opportunity();
            Contact c1 = new Contact();
             c1.lastname = 'TestSALReleaseLastName1';
        c1.Stage_Once__c = 'Prospect';
        c1.Stage_Video_Cloud__c = 'Name';
        c1.accountId = testAccount.id;
        c1.Stage_Once__c = 'Name'; 
        c1.Stage_Video_Cloud__c = 'Prospect'; 
        Set<String> tmpProd = new Set<String>();
        tmpProd.add(MIPLibrary.VIDEO_CLOUD);
        
            MIPLibrary.createOpportunity(tmpOp, MIPLibrary.getOpportunityExistingBusinessRecordTypeId(), testAccount.id, c1.id, 'new opty', '0 - Prospecting',tmpProd, userId );
            
    }

For (2): 
static testMethod void testGetContact() {
       Contact ContactObj2;
        Id currentLoginUserId = UserInfo.getUserId();
        Account testAccount = UnitTest_MIPLibrary.insertAccount('TestSALReleaseModal');
        
        ContactObj2 = new Contact();
        ContactObj2.lastname = 'TestSALReleaseLastName1';
        ContactObj2.Stage_Once__c = 'Prospect';
        ContactObj2.Stage_Video_Cloud__c = 'Name';
        ContactObj2.accountId = testAccount.id;
        ContactObj2.Stage_Once__c = 'Name'; 
        ContactObj2.Stage_Video_Cloud__c = 'Prospect';   
        ContactObj2.MailingStreet = 'Street1';
        ContactObj2.MailingCity = 'City1';
        ContactObj2.MailingState = 'CA';
        ContactObj2.MailingPostalCode = '94588';
        ContactObj2.MailingCountry = 'USA';    
    
        MIPLibrary.getContact(ContactObj2.id, true); 
               
        MIPLibrary.getContact(ContactObj2.id, false); 
        MIPLibrary.hasContactModified(ContactObj2, ContactObj2 );
        
        ContactObj2.Stage_Video_Cloud__c = 'SAL'; 
        
        MIPLibrary.hasContactModified(ContactObj2.id, 'MQL', 'SAL', '');
        
        MIPLibrary.submitQualifying(ContactObj2.id);
        Id tempId = ContactObj2.id;
        MIPLibrary.updateContactRolesStr(tempId);
        
        MIPLibrary.checkContactEligibility(ContactObj2.id,'MQL');
         
    }

Thank you for any help.
GC


 
Hi,
I have a requirement where i want to call Custom button from Apex class. kindly suggest. 
I shall be grateful to you for your kind cooperation.
Thanks and regards