• Stefano Amenta
  • NEWBIE
  • 114 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 28
    Questions
  • 34
    Replies
I have built a visual flow and embedded it in a Visualforce page, then hosted in a force site.
We also have our own custom font which we would like to display on the flow. However, it doesn't work, the final result looks more like a Times New Roman rather than our font.
The font is zipped and uploaded into a static resource:
User-added image


Then I called the font in the VF page, CSS section, making sure the filename is correct:
 
@font-face {
        font-family: 'EF Circular';
        src: url("{!URLFOR($Resource.efcircular, '/efcircular/EFCircularTT-Light.ttf')}");
        font-weight: 400;
        font-style: normal;
    }


And then I added the font name in the CSS wherever it should apply:
 
html { 
       <!--background: url('{!$Resource.TKTbg}') no-repeat center center fixed;-->
       font-family: 'EF Circular';            
       background-color: #0d426c;
       -webkit-background-size: cover;
       -moz-background-size: cover;
       -o-background-size: cover;
       background-size: cover;
       height: 100%;
       overflow: hidden;
     }

    .flow {
        font-family: 'EF Circular'; 
        width: 700px;
        height: auto;
        max-height: 100%;
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        opacity: 0.9;
        overflow: auto;
        -webkit-box-shadow: 5px 5px 16px -6px rgba(0,0,0,0.77); 
        box-shadow: 5px 5px 16px -6px rgba(0,0,0,0.77);
    }

    input {         
        /*height: 9px !important;*/
        font-family: 'EF Circular';
        padding: 6px 6px !important;
        margin-bottom: 5px;
        /*display: block !important; */
        font-size: 12px !important;
        line-height: 16px !important;
        color: #191919 !important;
        background-color: #efefef !important;
        border: 1px solid #009ee8 !important;
        border-radius: 4px  !important;
        width: 9cm;
  }

Is there anything I might be doing wrong?
Hi,

I created a custom component that shows a knowledge article in Community (English as default language).

I would like to add in the component a language picklist that shows up only if a translated article exists. For example, if the article is translated in Chinese, I would like the picklist to show Chinese as an option.

Is it such functionality doable? Do you have any suggestions on how I could implement it?

my component:
 
<aura:component implements="forceCommunity:availableForAllPageTypes,force:hasRecordId" access="global" controller="ArticleContentView_Controller">
    <aura:attribute name="recordId" type="Id" />
    <aura:attribute name="Article" type="Knowledge__kav" />

    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

    <div class="title"><h2><aura:unescapedHtml value="{!v.Article.Title}" /> </h2></div>   
    <div class="article-content"><aura:unescapedHtml value="{!v.Article.Article_Content__c}" /></div>
    
</aura:component>
JS
({
    doInit : function(component, event, helper) 
    {
        var actionArticle = component.get("c.getArticle");        

        actionArticle.setParams({
            recordId : component.get("v.recordId")
        });

        actionArticle.setCallback(this, function(response) {
            component.set("v.Article", response.getReturnValue());
        })

        console.log('>> ' + component.get("v.recordId"));
        $A.enqueueAction(actionArticle);


    }
})

Class
 
public with sharing class ArticleContentView_Controller 
{
    //public String articleId {get; set;}

    @AuraEnabled
    public static Knowledge__kav getArticle(ID recordId)
    {
        Knowledge__kav article = [SELECT Id, Title, Article_Content__c FROM Knowledge__kav WHERE Id = :recordId LIMIT 1]; 
        return article;
    }
}



 
Hi,

Recently I have been using this formula to calculate business hours for 5 days a week, for 9 hours, from 9am to 6pm China time.

The problem is that now the team will also start to work on Saturday and Sunday, but on a slightly different time: from 10am to 9pm China (11 hours).

How could I incorporate the new time inside the below formula? So the formula should consider two different timeframes: 9am to 6pm (weekdays) and 10am to 9pm (Saturday and Sunday).

How could I achieve that?
 
9 * (
   ( 5 * FLOOR( ( DATEVALUE(Now()) - DATE( 1900, 1, 8) ) / 7) +
    MIN(5, 
     MOD( DATEVALUE(Now()) - DATE( 1900, 1, 8), 7) +
     MIN( 1, 24 / 8 * ( MOD(Now() - DATETIMEVALUE( '1900-01-08 01:00:00' ), 1 ) ) )
    ) 
   )
 -
   ( 5 * FLOOR( ( DATEVALUE([Case].New_status_time_track_ALL__c) - DATE( 1900, 1, 8) ) / 7) +
     MIN( 5,
      MOD( DATEVALUE([Case].New_status_time_track_ALL__c) - DATE( 1996, 1, 1), 7 ) +
      MIN( 1, 24 / 8 * ( MOD([Case].New_status_time_track_ALL__c - DATETIMEVALUE( '1900-01-08 01:00:00' ), 1) ) )
    )
   ) 
  )
Hi,

I have put together a class that should change the From Address in the case feed based on some criteria.

In the debug logs, I can see the class is returning the correct value when the criteria are met, but in the case feed the From Address is always set to my email address.

Do you know why the case feed doesn't take into consideration the criteria in my class?
 
global class DefaultEmailLoader implements QuickAction.QuickActionDefaultsHandler {
    
    global DefaultEmailLoader() {
    }    
    
    global void onInitDefaults(QuickAction.QuickActionDefaults[] defaults) {
        QuickAction.SendEmailQuickActionDefaults sendEmailDefaults = null;
    
    System.debug(LoggingLevel.INFO, '*** : ' + defaults[0]);

        for (Integer j = 0; j < defaults.size(); j++) {
            if (defaults.get(j) instanceof QuickAction.SendEmailQuickActionDefaults && 
               defaults.get(j).getTargetSObject().getSObjectType() == 
                   EmailMessage.sObjectType && 
               defaults.get(j).getActionName().equals('Case.E_Mail_to_User_IT') && 
               defaults.get(j).getActionType().equals('SendEmail')) {
                   sendEmailDefaults = 
                       (QuickAction.SendEmailQuickActionDefaults)defaults.get(j);
                   break;
            }
        }
        
        if (sendEmailDefaults != null) {
            Case c = [SELECT Status, RecordTypeId, Creator_Office__c FROM Case 
                      WHERE Id=:sendEmailDefaults.getContextId()];
        
            EmailMessage emailMessage = (EmailMessage)sendEmailDefaults.getTargetSObject();  
            emailMessage.FromAddress = getFromAddress(c.RecordTypeId, c.Creator_Office__c);
            system.debug('Record type= ' + c.RecordTypeId);
            system.debug('Office= ' + c.Creator_Office__c);

            System.debug(LoggingLevel.INFO, '*** emailMessage.FromAddress: ' + emailMessage.FromAddress);
            

            if (sendEmailDefaults.getInReplyToId() == null) {
                Integer emailCount = [SELECT count() FROM EmailMessage 
                                      WHERE ParentId=:sendEmailDefaults.getContextId()];
                if (emailCount!= null && emailCount > 0) {
                    sendEmailDefaults.setTemplateId(
                        getTemplateIdHelper('GIT_Send_e_mail_with_case_description_2')); 
                } else {
                    sendEmailDefaults.setTemplateId(
                        getTemplateIdHelper('GIT_Send_e_mail_with_case_description_1st'));
                }
                sendEmailDefaults.setInsertTemplateBody(false);
                sendEmailDefaults.setIgnoreTemplateSubject(false);
            } else {
                sendEmailDefaults.setTemplateId(
                    getTemplateIdHelper('E1_Case_escalation_notification_unassigned'));
                sendEmailDefaults.setInsertTemplateBody(false);
                sendEmailDefaults.setIgnoreTemplateSubject(true);
            }
        }
    }
    
    private Id getTemplateIdHelper(String templateApiName) {
        Id templateId = null;
        try {
            templateId = [select id, name from EmailTemplate 
                          where developername = : templateApiName].id;   
        } catch (Exception e) {
            system.debug('Unble to locate EmailTemplate using name: ' + 
                templateApiName);
        }
        return templateId;
    }
private String getFromAddress(Id recordType, String office) {
    System.debug(LoggingLevel.INFO, '*** : ' + recordType.equals('0120I0000019cdyQAA') + ' ' + office.contains('CN'));
    system.debug('Record type= ' + recordType);
    system.debug('Office= ' + office);
        if (recordType.equals('0120I0000019cdyQAA') && office.contains('CN')) 
            { return 'email1@example.com'; } 
        else if (recordType.equals('0120I0000019cdyQAA') && office.contains('RU')) 
            { return 'email2@example.com'; } 
        else if (recordType.equals('0120I0000019cdyQAA') && office.contains('ID')) 
            { return 'email3@example.com'; }
            else { return 'email4@example.com'; }
       
    }
}

Case Feed view: the FromAddress is always set to my name.

User-added image 
Hi,

I created an email action in the case feed and an apex class to show the default email template, but it doesn't work yet, the template doesn't load.

I have activated the default template checkbox in Support Settings as well, and the template is available for use.

Does anyone know why it doesn't work?

Thanks.

User-added image

User-added image
This is the class:
 
global class E1DefaultTemplateEmail implements Support.EmailTemplateSelector {

    global E1DefaultTemplateEmail() {    }

    global ID getDefaultEmailTemplateId(ID caseId) {

        Case c = [SELECT Subject, Description FROM Case WHERE Id=:caseId];

        EmailTemplate et;

        if (c.subject != null) {
            et = [SELECT id FROM EmailTemplate WHERE DeveloperName = 'E1HC_Send_e_mail_with_case_description'];
        }         

        return et.id;
    }
}

 
Hi,
Since I changed to a new laptop (Win 10 machine) I'm unable to login to the Data Loader.

I always get this error message with any of my usernames.

Do you know how I could fix it?
Thanks.

User-added image
Hi,

I wrote a simple batch that deletes old reports by using the endpoint /services/data/v44.0/analytics/reports/ (which I stored in a custom label).

Now I'm struggling to write the test class code for the batch below.

Which code could I use to test my batch?

Thanks in advance.
 
global class DeleteOldReportsBatch implements Database.Batchable<sObject>, Database.AllowsCallouts {

    //Get the records to be deleted
    global Database.QueryLocator start(Database.BatchableContext BC) {
        String query = 'select id, FolderName from Report where LastRunDate <= LAST_N_DAYS:60 and FolderName = \'Public Reports\' ';
        return Database.getQueryLocator(query);        
    }

    //Executes the deletion logic for reports records
    global void execute(Database.BatchableContext BC, List<Report> scope) {
    String url;

    for(Report r : scope) {                
            Http h = new Http();
            url = System.Label.ReportsApi + r.Id;
            System.debug(LoggingLevel.INFO, '*** url: ' + url);          

            HttpRequest req = new HttpRequest();

            req.setHeader('Authorization', 'Bearer '+ UserInfo.getSessionId());
            req.setMethod('DELETE');
            req.setEndpoint(url);

            HttpResponse res = h.send(req);
            System.debug(LoggingLevel.INFO, '*** rest: ' + res.getBody());        
        } 
    }

    global void finish(Database.BatchableContext BC) {}
}

 
Hi,

does anyone know where to change, in the code, the width of the thank you message box (survey force)?

I tried a few things but it didn't work.

User-added image
Hi,
I wrote an apex batch which helps to delete reports in the Public Folder that haven't been run for more than 60 days.

When I test it in the Dev Console, I get an error such as "Too many callouts: 101".

How can I improve the code to overcome this issue?

Thanks for the help.
 
global class DeleteOldReportsBatch implements Database.Batchable<sObject>, Database.AllowsCallouts {

    //Get the records to be deleted
    global Database.QueryLocator start(Database.BatchableContext BC) {
        String query = 'select id, FolderName from Report where LastRunDate <= LAST_N_DAYS:60';
        return Database.getQueryLocator(query);        
    }

    //Executes the deletion logic for reports records
    global void execute(Database.BatchableContext BC, List<Report> scope) {
    String url;

    for(Report r : scope) {
        if (r.FolderName == 'Public Reports'){        
            Http h = new Http();
            url = '/services/data/v44.0/analytics/reports/' + r.Id;
            System.debug(LoggingLevel.INFO, '*** url: ' + url);          

            HttpRequest req = new HttpRequest();

            req.setHeader('Authorization', 'Bearer '+ UserInfo.getSessionId());
            req.setMethod('DELETE');
            req.setEndpoint(url);

            HttpResponse res = h.send(req);
            System.debug(LoggingLevel.INFO, '*** rest: ' + res.getBody());
        }
        } 
    }

    global void finish(Database.BatchableContext BC) {}
}

 
Hi,
Currently, I have been using the formula below to calculate the business hours between two dates.

I have a question, though:
  • If I want to calculate the business hours for a specific timeframe such as from 9am to 6pm (Monday to Friday, China time) would this formula still be valid?

Thanks in advance for the help.
 
CASE(MOD( In_Accept_Stage_Date_Track__c - DATE(1985,6,24),7), 0 , CASE( MOD( Today() - In_Accept_Stage_Date_Track__c ,7),1,2,2,3,3,4,4,5,5,5,6,5,1), 1 , CASE( MOD( Today() - In_Accept_Stage_Date_Track__c ,7),1,2,2,3,3,4,4,4,5,4,6,5,1), 2 , CASE( MOD( Today() - In_Accept_Stage_Date_Track__c ,7),1,2,2,3,3,3,4,3,5,4,6,5,1), 3 , CASE( MOD( Today() - In_Accept_Stage_Date_Track__c ,7),1,2,2,2,3,2,4,3,5,4,6,5,1), 4 , CASE( MOD( Today() - In_Accept_Stage_Date_Track__c ,7),1,1,2,1,3,2,4,3,5,4,6,5,1), 5 , CASE( MOD( Today() - In_Accept_Stage_Date_Track__c ,7),1,0,2,1,3,2,4,3,5,4,6,5,0), 6 , CASE( MOD( Today() - In_Accept_Stage_Date_Track__c ,7),1,1,2,2,3,3,4,4,5,5,6,5,0), 999) + (FLOOR(( Today() - In_Accept_Stage_Date_Track__c )/7)*5)

 
Hi,

I'm working on this trigger but I get an error at this line:

Contact contacts = Trigger.new;

Illegal assignment from List<Contact> to Contact ​​​​​​​

Do you know why?
How should it be done correctly?

​​​​​​​Thanks.
trigger TriggerAmbassadorUpdateCall on Contact (before insert, after insert, before update, after update) {
 
        system.debug('trigger new ***' + Trigger.new);
        system.debug('trigger new ***' + Trigger.old);
        
        //define variable data
        Contact contacts = Trigger.new;
        
        //create a set of contact Ids
        
       List<Id> contactIds = new List<Id>();
       // Map<Id, String> contactMaps = new Map<Id, String>();
        
        //loop through data
        for ( Contact contact : contacts ) {
           if( contact.Teacher_recuritment_status__c == 'Active' && contact.Ambassador__Short_Code__c!=null) {
           
            contactIds.add(contact.Id);
            }
        }
        
        if( Trigger.isUpdate) {
          //instantiate the class or create an object 
           
          //fire method
          ambassador.fireCall(contactIds);  
        }
        
        return;
  
}

 
Hi,

I wrote a class for an API integration.

I'm trying to fire the class via Process Builder, however, I'm unable to find my class in the action section of the Process.

Do you know why?

I followed the documentation about InvocableMethod here: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_InvocableMethod.htm

The class is Active and I also recompiled it, but no effect.

Do you know why I can't find it?
 
global class AmbassadorCommissionUpdate {   
    global Integer isApproved {get;set;}
    
    global AmbassadorCommissionUpdate (){         
            isApproved = 1;             
                
    }
    
  @InvocableMethod (label='Ambassador Commission Update')
  global static void fireCall (List<Id> ContactIds) { 
        String transactionId;
        String userName;
        String token;
        Id contactId = ContactIds[0];
        Contact acc = [SELECT Id FROM Contact WHERE Id=: contactId];
        transactionId = acc.Id;
        if( !String.isBlank(transactionId) ) { 
            system.debug('ambassador firing ***');
            Http h = new Http();
            HttpRequest req = new HttpRequest();            
            req.setEndpoint('https://getambassador.com/api/v2/' + userName + '/' + token + '/json/commission/update/');
            req.setMethod('GET');
            req.setBody(JSON.serialize(new AmbassadorRequest(transactionId, 1)));
            HttpResponse res = h.send(req);
            }           
        }   
        
    global class AmbassadorRequest {
        String transaction_uid;
        Integer is_approved;
        
        global AmbassadorRequest(String tId, Integer isApproved) {
            this.transaction_uid = tId;
            this.is_approved = isApproved;
        }
    }     
}



 
Hi,

I have built a process that works in the following way.

Criteria: Product = EF Staff
Immediate Action: Create Opportunity
Scheduled Action (to happen after 1 minute): Create Visa Record

User-added image

The immediate action works fine and the opportunity is created successfully.

However, when it comes to the Visa Record creation, I get the following error:

The flow failed to access the value for myVariable_current.Opportunity__r.AccountId because it hasn't been set or assigned

Considering that the Opportunity is already created, why I get the error above with the scheduled action?

These are the fields values for the Visa creation:

Candidate Email FORMULA [Account].PersonContact.Email 
Visa Name FORMULA [Account].PersonContact.FirstName + " " + [Account].PersonContact.LastName 
Opportunity FIELD REFERENCE [Account].Opportunity__r.AccountID
Owner ID 0050E000003WUqI
Product STRING EF Staff

Thanks in advance for the help.
Stefano
Hi,

I'm trying to embed a summary or tabular report inside a Visualforce page.

Initially, I was using this code but it doesn't work if the report doesn't have a chart.
 
<apex:page standardController="Visa__c">
<apex:sectionHeader title="Visa Cases Assignment"/> 
<apex:form >
    <apex:outputPanel>
        <analytics:reportChart reportId="00O0E000000ecW2" > 
        </analytics:reportChart> 
    </apex:outputPanel>
</apex:form>   
</apex:page>

What's the best way to embed in VF a report without any chart?

Thanks.
Stefano​​​​​​​
Hi,

I'm trying to validate a class but I'm stuck in this error:

System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out 
Stack Trace: Class.TeacherApplyNewController.adBloomRequest: line 153, column 1


This is the block of code causing the error:
@future(callout=true)
    public static void adBloomRequest(String contactId, String transactionId) {
        if( !String.isBlank(transactionId) && !String.isBlank(contactId) ) { 
            Http h = new Http();
            HttpRequest req = new HttpRequest();
            req.setEndpoint('https://trk.adbloom.co/SPMj?transaction_id=' + transactionId + '&adv_sub=' + contactId );
            req.setMethod('GET');
            HttpResponse res = h.send(req);
        }
    }

I'm not familiar with writing classes, so in this scenario how could I modify the code to make sure it doesn't produce the aforementioned error?

Thanks in advance.
Stefano
hi,
I have a page where the user is required to upload 2 attachments.

What's the best approach to disable the Upload button if the user didn't load 2 attachments?

Thanks.

User-added image
 
<apex:page controller="UploadFilesController">
    <apex:sectionHeader title="Upload Work Permit"/>    
    <apex:form enctype="multipart/form-data" id="form">
    <apex:pageBlock title="Document">
        <apex:pageMessages ></apex:pageMessages>
        <apex:pageBlockButtons >
            <apex:commandButton action="{!insertAttachmnet}" value="Upload"/>
            <input type="button" class="btn" value="Cancel" onclick="window.location='/{!CurrentVisaId}'" />
        </apex:pageBlockButtons>
        <apex:pageBlockSection showHeader="false" columns="1" id="block1">
            <apex:pageBlockSectionItem >
                <apex:outputLabel value="Document" for="file1"/>
                <apex:inputFile value="{!Attachment1.body}" filename="{!Attachment1.name}" id="file1"/>                
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                <apex:outputLabel value="Document" for="file2"/>
                <apex:inputFile value="{!Attachment2.body}" filename="{!Attachment2.name}" id="file2"/>                
            </apex:pageBlockSectionItem>           
        </apex:pageBlockSection>
    </apex:pageBlock>    
    <script>
        if({!IsCompleted})
        {
            window.location='/{!CurrentVisaId}';
        }        
    </script>
  </apex:form>
</apex:page>

 
Hi,
I have built a Visualforce page with Apex and html, it's linked to a button in the Visa__c object record and this button prints a contract as pdf.

I have a condition that if Opportunity_Region__c = Chengdu, then the <th> tag should not be rendered in the page.

I used this code doesn't work, although in the record I can see Opportunity_Region__c = Chengdu

Do you know what is missing?

Thanks,

 
<br><tr>
                <th style="width:50%; display:{!IF(Visa__c.Opportunity_Region__c = 'Chengdu', 'block','none')}">6. Social Insurance</th>
                <th style="width:50%; padding-left: 20px; display:{!IF(Visa__c.Opportunity_Region__c = 'Chengdu', 'block','none')}">6. 社会保险</th>
            </tr></br>

 
Hi,
I have a simple question but I'm struggling with it as I'm still a beginner in Visualforce.

I created a button called "Print Contract" inside a page that belongs to the custom object Visa__c, and a visualforce page that renders to PDF a contract using html and css.

Here's a piece of code from the Visualforce page as example:
 
<div class="allContainer">
<div class="headerContainer">
    <div class="headerTitle"><label class="labelTitle">Job Contract<br>聘用合同</br></label></div>
    <div class="teacherContainer">    
        <table>
            <tr>
                <th style="width:50%;">1. Personal Info</th>
            </tr>
            <tr>
                <td><label class="labelDetail">Passport Number: </label>
                <apex:outputText styleClass="teacherDetail" value=" {!Visa__c.PassportNumber}"/></td>
            </tr>

However, if the field {!Visa__c.CityName} = Shanghai, when the users click on the Print Contract button I want them to see a different text in the contract, for example, something like this (where Passport is replaced by ID Card).
 
<div class="allContainer">
<div class="headerContainer">
    <div class="headerTitle"><label class="labelTitle">Job Contract<br>聘用合同</br></label></div>
    <div class="teacherContainer">    
        <table>
            <tr>
                <th style="width:50%;">1. Personal Info</th>
            </tr>
            <tr>
                <td><label class="labelDetail">ID Card: </label>
                <apex:outputText styleClass="teacherDetail" value=" {!Visa__c.IDCard}"/></td>
            </tr>

How can I do this by using a IF statement in the Visualforce page? 

Thanks.
Hi,

Currently, I have a landing page where the user inputs the email address.

After he clicks on APPLY, he will be redirected to a Force.com page where the URL looks like this:

https://test.force.com/onlineteacher?e=test@test.com

Is there any code that could help to capture the email address in the URL and store the value into a custom field in Salesforce?
Hi!

I have built a visual flow and hosted it on a public Force site (guest user is called "Teacher Profile").

The guest user has CREATE, READ and EDIT access to the custom object referred by the flow.

The guest user also has read and edit access to any field of the custom object.

When I run the flow, I keep getting the following error and I can't figure out why:

Error element Migrate_form_to_SF (FlowRecordCreate).
This error occurred when the flow tried to create records: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY: insufficient access rights on cross-reference id.


I understand this is about permissions, but again the guest user has permissions to all the fields listed in "Migrate form to SF".

thank for your help.
Stefano
Hi,

I created an email action in the case feed and an apex class to show the default email template, but it doesn't work yet, the template doesn't load.

I have activated the default template checkbox in Support Settings as well, and the template is available for use.

Does anyone know why it doesn't work?

Thanks.

User-added image

User-added image
This is the class:
 
global class E1DefaultTemplateEmail implements Support.EmailTemplateSelector {

    global E1DefaultTemplateEmail() {    }

    global ID getDefaultEmailTemplateId(ID caseId) {

        Case c = [SELECT Subject, Description FROM Case WHERE Id=:caseId];

        EmailTemplate et;

        if (c.subject != null) {
            et = [SELECT id FROM EmailTemplate WHERE DeveloperName = 'E1HC_Send_e_mail_with_case_description'];
        }         

        return et.id;
    }
}

 
Hi,
Since I changed to a new laptop (Win 10 machine) I'm unable to login to the Data Loader.

I always get this error message with any of my usernames.

Do you know how I could fix it?
Thanks.

User-added image
Hi,

does anyone know where to change, in the code, the width of the thank you message box (survey force)?

I tried a few things but it didn't work.

User-added image
Hi,
I wrote an apex batch which helps to delete reports in the Public Folder that haven't been run for more than 60 days.

When I test it in the Dev Console, I get an error such as "Too many callouts: 101".

How can I improve the code to overcome this issue?

Thanks for the help.
 
global class DeleteOldReportsBatch implements Database.Batchable<sObject>, Database.AllowsCallouts {

    //Get the records to be deleted
    global Database.QueryLocator start(Database.BatchableContext BC) {
        String query = 'select id, FolderName from Report where LastRunDate <= LAST_N_DAYS:60';
        return Database.getQueryLocator(query);        
    }

    //Executes the deletion logic for reports records
    global void execute(Database.BatchableContext BC, List<Report> scope) {
    String url;

    for(Report r : scope) {
        if (r.FolderName == 'Public Reports'){        
            Http h = new Http();
            url = '/services/data/v44.0/analytics/reports/' + r.Id;
            System.debug(LoggingLevel.INFO, '*** url: ' + url);          

            HttpRequest req = new HttpRequest();

            req.setHeader('Authorization', 'Bearer '+ UserInfo.getSessionId());
            req.setMethod('DELETE');
            req.setEndpoint(url);

            HttpResponse res = h.send(req);
            System.debug(LoggingLevel.INFO, '*** rest: ' + res.getBody());
        }
        } 
    }

    global void finish(Database.BatchableContext BC) {}
}

 
Hi,

I'm working on this trigger but I get an error at this line:

Contact contacts = Trigger.new;

Illegal assignment from List<Contact> to Contact ​​​​​​​

Do you know why?
How should it be done correctly?

​​​​​​​Thanks.
trigger TriggerAmbassadorUpdateCall on Contact (before insert, after insert, before update, after update) {
 
        system.debug('trigger new ***' + Trigger.new);
        system.debug('trigger new ***' + Trigger.old);
        
        //define variable data
        Contact contacts = Trigger.new;
        
        //create a set of contact Ids
        
       List<Id> contactIds = new List<Id>();
       // Map<Id, String> contactMaps = new Map<Id, String>();
        
        //loop through data
        for ( Contact contact : contacts ) {
           if( contact.Teacher_recuritment_status__c == 'Active' && contact.Ambassador__Short_Code__c!=null) {
           
            contactIds.add(contact.Id);
            }
        }
        
        if( Trigger.isUpdate) {
          //instantiate the class or create an object 
           
          //fire method
          ambassador.fireCall(contactIds);  
        }
        
        return;
  
}

 
Hi,

I wrote a class for an API integration.

I'm trying to fire the class via Process Builder, however, I'm unable to find my class in the action section of the Process.

Do you know why?

I followed the documentation about InvocableMethod here: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_InvocableMethod.htm

The class is Active and I also recompiled it, but no effect.

Do you know why I can't find it?
 
global class AmbassadorCommissionUpdate {   
    global Integer isApproved {get;set;}
    
    global AmbassadorCommissionUpdate (){         
            isApproved = 1;             
                
    }
    
  @InvocableMethod (label='Ambassador Commission Update')
  global static void fireCall (List<Id> ContactIds) { 
        String transactionId;
        String userName;
        String token;
        Id contactId = ContactIds[0];
        Contact acc = [SELECT Id FROM Contact WHERE Id=: contactId];
        transactionId = acc.Id;
        if( !String.isBlank(transactionId) ) { 
            system.debug('ambassador firing ***');
            Http h = new Http();
            HttpRequest req = new HttpRequest();            
            req.setEndpoint('https://getambassador.com/api/v2/' + userName + '/' + token + '/json/commission/update/');
            req.setMethod('GET');
            req.setBody(JSON.serialize(new AmbassadorRequest(transactionId, 1)));
            HttpResponse res = h.send(req);
            }           
        }   
        
    global class AmbassadorRequest {
        String transaction_uid;
        Integer is_approved;
        
        global AmbassadorRequest(String tId, Integer isApproved) {
            this.transaction_uid = tId;
            this.is_approved = isApproved;
        }
    }     
}



 
Hi,

I'm trying to embed a summary or tabular report inside a Visualforce page.

Initially, I was using this code but it doesn't work if the report doesn't have a chart.
 
<apex:page standardController="Visa__c">
<apex:sectionHeader title="Visa Cases Assignment"/> 
<apex:form >
    <apex:outputPanel>
        <analytics:reportChart reportId="00O0E000000ecW2" > 
        </analytics:reportChart> 
    </apex:outputPanel>
</apex:form>   
</apex:page>

What's the best way to embed in VF a report without any chart?

Thanks.
Stefano​​​​​​​
hi,
I have a page where the user is required to upload 2 attachments.

What's the best approach to disable the Upload button if the user didn't load 2 attachments?

Thanks.

User-added image
 
<apex:page controller="UploadFilesController">
    <apex:sectionHeader title="Upload Work Permit"/>    
    <apex:form enctype="multipart/form-data" id="form">
    <apex:pageBlock title="Document">
        <apex:pageMessages ></apex:pageMessages>
        <apex:pageBlockButtons >
            <apex:commandButton action="{!insertAttachmnet}" value="Upload"/>
            <input type="button" class="btn" value="Cancel" onclick="window.location='/{!CurrentVisaId}'" />
        </apex:pageBlockButtons>
        <apex:pageBlockSection showHeader="false" columns="1" id="block1">
            <apex:pageBlockSectionItem >
                <apex:outputLabel value="Document" for="file1"/>
                <apex:inputFile value="{!Attachment1.body}" filename="{!Attachment1.name}" id="file1"/>                
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                <apex:outputLabel value="Document" for="file2"/>
                <apex:inputFile value="{!Attachment2.body}" filename="{!Attachment2.name}" id="file2"/>                
            </apex:pageBlockSectionItem>           
        </apex:pageBlockSection>
    </apex:pageBlock>    
    <script>
        if({!IsCompleted})
        {
            window.location='/{!CurrentVisaId}';
        }        
    </script>
  </apex:form>
</apex:page>

 
Hi,
I have built a Visualforce page with Apex and html, it's linked to a button in the Visa__c object record and this button prints a contract as pdf.

I have a condition that if Opportunity_Region__c = Chengdu, then the <th> tag should not be rendered in the page.

I used this code doesn't work, although in the record I can see Opportunity_Region__c = Chengdu

Do you know what is missing?

Thanks,

 
<br><tr>
                <th style="width:50%; display:{!IF(Visa__c.Opportunity_Region__c = 'Chengdu', 'block','none')}">6. Social Insurance</th>
                <th style="width:50%; padding-left: 20px; display:{!IF(Visa__c.Opportunity_Region__c = 'Chengdu', 'block','none')}">6. 社会保险</th>
            </tr></br>

 
Hi,
I have a simple question but I'm struggling with it as I'm still a beginner in Visualforce.

I created a button called "Print Contract" inside a page that belongs to the custom object Visa__c, and a visualforce page that renders to PDF a contract using html and css.

Here's a piece of code from the Visualforce page as example:
 
<div class="allContainer">
<div class="headerContainer">
    <div class="headerTitle"><label class="labelTitle">Job Contract<br>聘用合同</br></label></div>
    <div class="teacherContainer">    
        <table>
            <tr>
                <th style="width:50%;">1. Personal Info</th>
            </tr>
            <tr>
                <td><label class="labelDetail">Passport Number: </label>
                <apex:outputText styleClass="teacherDetail" value=" {!Visa__c.PassportNumber}"/></td>
            </tr>

However, if the field {!Visa__c.CityName} = Shanghai, when the users click on the Print Contract button I want them to see a different text in the contract, for example, something like this (where Passport is replaced by ID Card).
 
<div class="allContainer">
<div class="headerContainer">
    <div class="headerTitle"><label class="labelTitle">Job Contract<br>聘用合同</br></label></div>
    <div class="teacherContainer">    
        <table>
            <tr>
                <th style="width:50%;">1. Personal Info</th>
            </tr>
            <tr>
                <td><label class="labelDetail">ID Card: </label>
                <apex:outputText styleClass="teacherDetail" value=" {!Visa__c.IDCard}"/></td>
            </tr>

How can I do this by using a IF statement in the Visualforce page? 

Thanks.