• ZurMiles
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 17
    Replies

Hello all, 

 

I was wondering if anyone knows where I can find out which are the visualforce components that support apex:facet.

Thanks in advanced. 

 

Regards.

Hello, 

 

I have a script that works together with a visualforce page, it is a form. 

The script will take the language in the current page and based on that it will send an email to the a specify service department.

I just use this to get the language 'language = Apexpages.currentPage().getParameters().get('lang');'.


Before that I have a Map ready to accommodate the values: 

 

Map<String, String[]> serviceEmailAddresses = new Map<String, String[]>();

 

So the intention is that depending in the user's current page language to send an email to the correct service department, like I mention before.

If the page language is 'en' the email will go to uk.service@something.com, if the current page language is 'es' the email goes to es.servicio@something.com and so on, these are the languages we use: 'en', 'be', 'es','de', 'fr', 'it', 'nl' and 'pt'.

 

Each of those values have an email assign to it. 

 

public ServiceForm() {
        language = Apexpages.currentPage().getParameters().get('lang');
        if ((language == 'en')&&(serviceType != 'Spare Parts Order')) {
            serviceEmailAddresses.put('en', new String[] {'uk.support@something.com'});
        }else{
       
        serviceEmailAddresses.put('en', new String[] {'uk.serviceparts@something.com'});
        serviceEmailAddresses.put('be', new String[] {'service.benelux@something.com'});
        serviceEmailAddresses.put('es', new String[] {'servicio.tecnico@something.com'});
        serviceEmailAddresses.put('de', new String[] {'kundendienst@something.com'});
        serviceEmailAddresses.put('fr', new String[] {'service.benelux@something.com'});
        serviceEmailAddresses.put('it', new String[] {'assistenzatecnica@something.com'});
        serviceEmailAddresses.put('nl', new String[] {'service.benelux@something.com'});
        serviceEmailAddresses.put('pt', new String[] {'servicio.tecnico@something.com'});
        }        
        if (language != 'be'&& language != 'en' && language != 'es' && language != 'de' && language != 'fr' && language != 'it' && language != 'nl' && language != 'pt') {
            language = 'en';
        }

 At the end we use this to send an email to the service department:

 

 private void sendServiceMail() {
        Messaging.SingleEmailMessage serviceMail = new Messaging.SingleEmailMessage();
        serviceMail.setToAddresses(serviceEmailAddresses.get(language));
        serviceMail.setSenderDisplayName(Label.Sender_Display_Name);
        serviceMail.setReplyTo(noReplyEmail);
        serviceMail.setSubject('' + companyName + ', ' + addressCodeCity + ' - ' + serviceType + ' - ONLINE REQUEST');
        String serviceMailMessage = Label.Email_Subject_Service + ':\n\n';
        serviceMailMessage = serviceMailMessage + setPlainTextMessage('\n\n');
        serviceMail.setPlainTextBody(serviceMailMessage);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { serviceMail });        

 The third line I believe is correct, can anyone let me know otherwise?: 

                  serviceMail.setToAddresses (serviceEmailAddresses.get(language)); 

 

 The form works fine but for some unknown reason, sometimes it sends emails to the wrong inbox. Last time a client from Spain submitted his form     and it went to the uk.serviceparts address!! 

 Does anyone knows why this is happening? The script looks pretty straightforward ... 

 

Any help on this will be much appreciated. 

Thanks

Hello all,

 

I have a question regarding a form I want to build with Apex and Visualforce pages.

The form will have 1 row and 4 columns but I want  to allow the user to add more rows if needed.

The question is, what would be the best way to automatically add a new row when the user enters data on the first row?

Could anyone give me a few examples please?

Thanks in advanced!

 

 

Hello all,

 

 

There is a way to delete files older than 3 minutes? 

Thanks.

 

 

Hello all,

 

I'm trying to send an email from a Visualforce page after the user is done with a form. All this is working just fine. 

Now I need to add the possibility of adding an attachment to that form.  I use this code together with a visual force page and it works.

 

 public PageReference upload() {
      
      attachment.ParentId = '500Q0000004eDnT';
      attachment.IsPrivate = true;
      
      
    try {
      insert attachment;
    } catch (DMLException e) {
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
      return null;
    }
     finally{
      attachment = new Attachment(); 
    }
 
    ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Attachment uploaded successfully'));
    return null;
    
  }
  

 The problem is that now I need to attach that attachment to the email that will be send after the form is done and the attachment is uploaded. 

I was thinking on doing a SOQL on Attachments, something like this:

 

Attachment attachmentToSend = [select Body, Id, Name, ContentType from Attachment where Parentid=:' 500Q0000004eDnt'  FROM <------- after this the problem starts for me. 

 

Here is the question:

 

How can I get the id of that attachment that have been just uploaded and put it in some place to use it for my query in order for me to get the correct attachment for that email that will be send. 

I can query for all attachment but I need to get the id related to the one the user uploaded

 

Thanks

Hello all,

 

I having a hard time when trying to modify a apex code from the previous person that was working in my company. He was a developer and I'm not. My level in Apex is normal, I'm an administrator and I'm trying to pull this up because is kind of urgent for my company. 

 

We have a Scorecard system that will keep track of a number of fields from different objects. The scorecard object contains these cards for each account owner, contact related and leads.

 

 The all idea is that if you fill in a number of fields you will get a percentage in these scorecards. The scorecards have a page layout and in those page layouts you have fields that will keep track of the percentages. Lest say you fill in 50% of you phone field on you accounts, there is a field in your scorecard page layout with a field Account Phone Number Filled = 50%.  

This is done with a number of fields from different objects like I mentioned before. There is an apex schedule that will trigger the apex that update this scorecards every hour. 

 

This is the script: 

 

 

global class ScoreCardGenerator {

    global void processScoreCards() {

        final String RESOURCE_NAME_HAS = 'ScorecardQueriesHAS';
        final String RESOURCE_NAME_ALL = 'ScorecardQueriesALL';
    
        Map<String, Map<String, String>> scHASQueries = new Map<String, Map<String, String>>();
        Map<String, Map<String, String>> scALLQueries = new Map<String, Map<String, String>>();
        Map<Id, Score_Card__c> scoreCards = new Map<Id, Score_Card__c>();
        Map<String, String> fieldsToUpdateHAS = new Map<String, String>();
        Map<String, String> fieldsToUpdateALL = new Map<String, String>();
        StaticResource theStaticResource;
        List<Score_Card__c> updatedScoreCards = new List<Score_Card__c>();
        Set<Id> ownerIdKeys = new Set<Id>();
        Map<Id, Map<String, Double>> userHASResults = new Map<Id, Map<String, Double>>();
        Map<Id, Map<String, Double>> userALLResults = new Map<Id, Map<String, Double>>();
        DateTime todayDate = System.Now();
        DateTime startOfYear = DateTime.newInstanceGMT(todayDate.year(), 1, 1, 0, 0, 0);
        Integer currentHour = System.Now().hourGMT();

        try {
            theStaticResource = [SELECT id, Body FROM StaticResource WHERE name = :RESOURCE_NAME_HAS];
            String bodyText = theStaticResource.body.toString();
            List<String> bodyLines = bodyText.split('\n');
            for(String line : bodyLines) {
                if(line.trim().length() != 0) {
                    List<String> keyValuePairs = line.split('~');
                    String mapKey;
                    Map<String, String> tempMap = new Map<String, String>();
                    String objectName = '';
            
                    for(String pairString : keyValuePairs) {
                
                        // Some boilerplate splitting
                        List<String> pairs = pairString.split('#');
                        String key = pairs[0].trim();
                        String value = pairs[1].trim();
    
                        if (key == 'ID') {
                            mapKey = value;
                        }
                        else {
                            tempMap.put(key, value);
                        }
                        
                        if (key == 'OBJECT') {
                            objectName = value;
                        }   
            
                        if (key == 'FIELD') {
                            fieldsToUpdateHAS.put(value, objectName);
                        }
                    }
                    scHASQueries.put(mapKey, tempMap);
                }
            }
        } catch(System.QueryException e) {
            System.debug(e);
            // You should always let the admins/devs know if
            // something unexpected happened.
            // e.g. ExceptionUtils.mail(Administrator);
        }
           
        try {
            theStaticResource = [SELECT id, Body FROM StaticResource WHERE name = :RESOURCE_NAME_ALL];
            String bodyText = theStaticResource.body.toString();
            List<String> bodyLines = bodyText.split('\n');
            for(String line : bodyLines){
                if(line.trim().length() != 0) {
                    List<String> keyValuePairs = line.split('~');
                    String mapKey;
                    Map<String, String> tempMap = new Map<String, String>();
                    String objectName = '';
            
                    for(String pairString : keyValuePairs) {
            
                        // Some boilerplate splitting
                        List<String> pairs = pairString.split('#');
                        String key = pairs[0].trim();
                        String value = pairs[1].trim();
            
                        if (key == 'ID') {
                            mapKey = value;
                        }
                        else {
                            tempMap.put(key, value);
                        }
                        
                        if (key == 'OBJECT') {
                            objectName = value;
                        }   
            
                        if (key == 'FIELD') {
                            fieldsToUpdateALL.put(value, objectName);
                        }
                    }
                    scALLQueries.put(mapKey, tempMap);
                }
            }
        } catch(System.QueryException e) {
            System.debug(e);
            // You should always let the admins/devs know if
            // something unexpected happened.
            // e.g. ExceptionUtils.mail(Administrator);
        }   
        
        String businessUnitSalesTeam;
        if (currentHour == 0 || currentHour == 12) {
            businessUnitSalesTeam = 'Business_Unit__c = \'Benelux\'';
        }
        else if (currentHour == 1 || currentHour == 13) {
            businessUnitSalesTeam = 'Business_Unit__c = \'DACHI\' AND Sales_Team__c = \'Centre\'';
        }
        else if (currentHour == 2 || currentHour == 14) {
            businessUnitSalesTeam = 'Business_Unit__c = \'DACHI\' AND Sales_Team__c = \'North\'';
        }
        else if (currentHour == 3 || currentHour == 15) {
            businessUnitSalesTeam = 'Business_Unit__c = \'DACHI\' AND Sales_Team__c = \'South\'';
        }
        else if (currentHour == 4 || currentHour == 16) {
            businessUnitSalesTeam = 'Business_Unit__c = \'DACHI\' AND Sales_Team__c IN (\'Austria\', \'Dresden\', \'Italy\', \'Switzerland\')';
        }
        else if (currentHour == 5 || currentHour == 17) {
            businessUnitSalesTeam = 'Business_Unit__c IN (\'DB\', \'Consumer\', \'Hong Kong\')';
        }    
        else if (currentHour == 6 || currentHour == 18) {
            businessUnitSalesTeam = 'Business_Unit__c = \'Japan\'';
        }
        else if (currentHour == 7 || currentHour == 19) {
            businessUnitSalesTeam = 'Business_Unit__c = \'Spain\'';
        }
        else if (currentHour == 8 || currentHour == 20) {
            businessUnitSalesTeam = 'Business_Unit__c = \'UK\' AND Sales_Team__c = \'Key\'';
        }
        else if (currentHour == 9 || currentHour == 21) {
            businessUnitSalesTeam = 'Business_Unit__c = \'UK\' AND Sales_Team__c IN (\'Midlands\', \'MOD\')';
        }
        else if (currentHour == 10 || currentHour == 22) {
            businessUnitSalesTeam = 'Business_Unit__c = \'UK\' AND Sales_Team__c IN (\'North\', \'Telesales\')';
        }
        else if (currentHour == 11 || currentHour == 23) {
            businessUnitSalesTeam = 'Business_Unit__c = \'UK\' AND Sales_Team__c = \'South\'';
        }

    if (businessUnitSalesTeam != null) {
            for (Score_Card__c sc : Database.Query('Select Id, User__c FROM Score_Card__c WHERE Active__c = TRUE AND ' + businessUnitSalesTeam)) {
                scoreCards.put(sc.User__c, sc);
            }
        }
        ownerIdKeys = scorecards.keyset();
        for (Integer i = 1; i < scALLQueries.size()+1; i++) {
            String queryALL = scALLQueries.get(String.valueOf(i)).get('QUERYALL');
            for (AggregateResult arALL : Database.Query(queryALL + ' GROUP BY OwnerId ORDER BY OwnerId')) {
                Map<String, Double> tempMap = new Map<String, Double>();    
                if (userALLResults.containsKey(String.valueOf(arALL.get('OwnerId')))) {
                    tempMap = userALLResults.get(String.valueOf(arALL.get('OwnerId')));
                }
                tempMap.put(scALLQueries.get(String.valueOf(i)).get('OBJECT'), Double.valueOf(arALL.get('expr0')));
                userALLResults.put(String.valueOf(arALL.get('OwnerId')), tempMap);                      
            }
        } 
        for (Integer i = 1; i < scHASQueries.size()+1; i++) {
            String queryHAS = scHASQueries.get(String.valueOf(i)).get('QUERYHAS');
            for (AggregateResult arHAS : Database.Query(queryHAS + ' AND OwnerId IN :ownerIdKeys GROUP BY OwnerId ORDER BY OwnerId')) {
                Map<String, Double> tempMap = new Map<String, Double>();
                if (userHASResults.containsKey(String.valueOf(arHAS.get('OwnerId')))) {
                    tempMap = userHASResults.get(String.valueOf(arHAS.get('OwnerId')));
                }
                tempMap.put(scHASQueries.get(String.valueOf(i)).get('FIELD'), Double.valueOf(arHAS.get('expr0')));
                userHASResults.put(String.valueOf(arHAS.get('OwnerId')), tempMap);
            }
        }
        for (Id userId : ownerIdKeys) {
            SObject updateSC = scoreCards.get(userId);
            Set<String> hasFieldNames = fieldsToUpdateHAS.keySet();
            Set<String> allFieldNames = fieldsToUpdateALL.keySet();
            for (String field : hasFieldNames) {

        /*
                if (!userHASResults.get(userId).containsKey(field) || !userALLResults.get(userId).containsKey(fieldsToUpdateHAS.get(field)) || fieldsToUpdateHAS.get(field) == null) {
                  
                    updateSC.put(field, 0);
                }
        */
              if (fieldsToUpdateHAS.get(field) != null && !userALLResults.get(userId).containsKey(fieldsToUpdateHAS.get(field))) {
                updateSC.put(field, 100);
              }
                else if (!userHASResults.get(userId).containsKey(field) || fieldsToUpdateHAS.get(field) == null) {
                    updateSC.put(field, 0);
                }
                else {
                    updateSC.put(field, (userHASResults.get(userId).get(field) / userALLResults.get(userId).get(fieldsToUpdateHAS.get(field))) * 100);
                }
            }
            for (String field : allFieldNames) {
                if (!userALLResults.get(userId).containsKey(fieldsToUpdateALL.get(field))) {
                    updateSC.put(field, 0);
                }
                else {
                    updateSC.put(field, userALLResults.get(userId).get(fieldsToUpdateALL.get(field)));
                }
            }
            updatedScoreCards.add((Score_Card__c)updateSC);
        }       
        if (!updatedScoreCards.isEmpty()) { 
            update(updatedScoreCards);
        }
    } 
}

 

 

What I want is just to add another field in the scorecard object to track the Name in the Contact object.  I noticed that on the scrip there are two lines:

 

        final String RESOURCE_NAME_HAS = 'ScorecardQueriesHAS';
        final String RESOURCE_NAME_ALL = 'ScorecardQueriesALL';

 

These two lines are very important becasue they contain the query for the fields that are in the scorecards.

Here it is one of the files (ScorecardQueriesHAS):

 

ID#1~OBJECT#Event~FIELD#Events_with_Comments__c~QUERYHAS#SELECT OwnerId  count(Subject) FROM Event WHERE StartDateTime >= :startOfYear AND EndDateTime <= :todayDate AND Sales_Comments__c != '',,
ID#2~OBJECT#Account~FIELD#Accounts_with_Address__c~QUERYHAS#SELECT ownerId count(Name) FROM Account WHERE BillingStreet != '' AND BillingCity != '' AND BillingPostalCode != '' AND BillingCountry != '', ,
ID#3~OBJECT#AccountExact~FIELD#Accounts_with_Exact_Debtor_Number__c~QUERYHAS#SELECT OwnerId count(Name) FROM Account WHERE Id IN (SELECT AccountId FROM Opportunity WHERE IsWon = true AND RecordTypeId != '01280000000PydL') AND Exact_Debtor_Number__c != '',,
ID#4~OBJECT#Account~FIELD#Accounts_with_Segmentation__c~QUERYHAS#SELECT ownerId count(Name) FROM Account WHERE ((Industry != '' AND Life_Segment__c != '' AND Sub_Sector__c != '') OR (Segment__c != '' AND Industry__c != '' AND Dimension__c != '' AND Organization__c != '')), ,
ID#5~OBJECT#Account~FIELD#Accounts_with_Status__c~QUERYHAS#SELECT ownerId count(Name) FROM Account WHERE Account_Status__c != '', , ID#6~OBJECT#Account~FIELD#Accounts_with_Territory__c~QUERYHAS#SELECT ownerId count(Name) FROM Account WHERE Territory__c != '', , ID#7~OBJECT#Account~FIELD#Accounts_with_Zone__c~QUERYHAS#SELECT ownerId count(Name) FROM Account WHERE Zones__c != '',, ID#8~OBJECT#Account~FIELD#Accounts_with_Phone_Number__c~QUERYHAS#SELECT ownerId count(Name) FROM Account WHERE Phone != '', , ID#9~OBJECT#Account~FIELD#Contacts_with_Email_Address__c~QUERYHAS#Select ownerId COUNT(Name) FROM Account WHERE Id IN (SELECT AccountId FROM Contact WHERE Email != '' AND RecordTypeId != '01280000000PydJ'),,
ID#10~OBJECT#OpportunityProduct~FIELD#Open_Opportunities_with_Products__c~OBJECT#Opportunity~QUERYHAS#SELECT ownerId count(Name) FROM Opportunity WHERE IsClosed = FALSE AND HasOpportunityLineItem = true AND StageName NOT IN ('F- First Phase Open' 'P - Qualified Prospect'), ,
ID#11~OBJECT#Opportunity~FIELD#Open_Opportunities_with_Net_Revenue__c~QUERYHAS#SELECT OwnerId count(Name) FROM Opportunity WHERE IsClosed = FALSE AND Net_Revenue__c != NULL,,
ID#12~OBJECT#Account~FIELD#Contact_with_First_Name__c~QUERYHAS#Select ownerId COUNT(Name) FROM Account WHERE Id IN (SELECT AccountId FROM Contact WHERE Name != '' AND RecordTypeId != '01280000000PydJ'),,

 I added the last line ID#12. 

The first think that I'm not sure is when I try to view ScorecardQueriesHAS from the the Static Resources. I see that the file is a 

MIME Typeapplication/vnd.ms-excel

 and if I click on View file, I get a file and when I try to open this file I get the msg in excel: 'Excel has detected that 'ScorecardQueriesHAS (11).xls' is a SYKL file, but cannot load it. Either the file has errors or it is not a SKYLK file format.'

 

I beileve this is a csv file but I was wondering if there is any particular way to save this files or to modify them, because when I modified the file and put it back to the static resourcers the line ID#12 is not doing what it is suppose to do.

 

So, I need to know what I'm doing wrong here in order for me to be able to modify this. Any ideas?

 

One more question :( , I have to wait about one hour to see if there is any luck after making any modification. There is a way to execute this from the Developer Console?

 

Thanks in advance.

 

 

 

Hello all,

 

I'm trying to look for the best way to delete an Account if there is not Opportunies, Contacts, Tasks or Events active on that Account. Wat would be the best a more simple way to wirte this on Apex?

 

Thanks on advance.

 

 

 

Hello all, 

 

I have a question involving the Task object, Lead object, a Workflow and 2 custom fields, one on the Lead page and another on one Task page layout.

 

The logic is that when a user change the value of a field (Picking list) in the Lead page layout, a workflow will create a task for the Lead Owner.

This is done easily with a Workflow. 

 

Here is what I want to do now and I haven't been able to accomplish yet. 

I want to change the value of a custom field (‘C’) that it is on that Task generated by the workflow. 

 

Explanation: 

 

There is a custom field on the Leads object page layout. This field is a picking list data type.

 

We have a number of people that will be working with our leads and they will make a number of changes on these leads.

One of the updates will need to be done on a field, lest call it, field ‘A’.

 

Depending on the values selected on the ‘A’ field a workflow will be triggered. This workflow will be responsible for the creation of a new Task. This Task will be send to the Lead Owner.

 

On that same Lead page layout there is another field, field ‘B’. The intention is to put the ‘B’ field value into a custom field in the new Task, field ‘C’. The new task is created by the workflow.

 

What I’m trying to do is to build a Trigger on the Task object (after insert), that will add the value of the Lead ‘B’ field into the ‘C’ field on the new task that will be generated depending the value on the field ‘A’, by the workflow.

How can I do this?

How can I build a trigger that will add the value of that specify Lead field (‘B’) value in to the new task field ‘A’?

 

I’m busy with APEX but I’m not a guru L … any help will be great!

 

Thanks in advance.

 

 

Hello, 

 

I have a script that works together with a visualforce page, it is a form. 

The script will take the language in the current page and based on that it will send an email to the a specify service department.

I just use this to get the language 'language = Apexpages.currentPage().getParameters().get('lang');'.


Before that I have a Map ready to accommodate the values: 

 

Map<String, String[]> serviceEmailAddresses = new Map<String, String[]>();

 

So the intention is that depending in the user's current page language to send an email to the correct service department, like I mention before.

If the page language is 'en' the email will go to uk.service@something.com, if the current page language is 'es' the email goes to es.servicio@something.com and so on, these are the languages we use: 'en', 'be', 'es','de', 'fr', 'it', 'nl' and 'pt'.

 

Each of those values have an email assign to it. 

 

public ServiceForm() {
        language = Apexpages.currentPage().getParameters().get('lang');
        if ((language == 'en')&&(serviceType != 'Spare Parts Order')) {
            serviceEmailAddresses.put('en', new String[] {'uk.support@something.com'});
        }else{
       
        serviceEmailAddresses.put('en', new String[] {'uk.serviceparts@something.com'});
        serviceEmailAddresses.put('be', new String[] {'service.benelux@something.com'});
        serviceEmailAddresses.put('es', new String[] {'servicio.tecnico@something.com'});
        serviceEmailAddresses.put('de', new String[] {'kundendienst@something.com'});
        serviceEmailAddresses.put('fr', new String[] {'service.benelux@something.com'});
        serviceEmailAddresses.put('it', new String[] {'assistenzatecnica@something.com'});
        serviceEmailAddresses.put('nl', new String[] {'service.benelux@something.com'});
        serviceEmailAddresses.put('pt', new String[] {'servicio.tecnico@something.com'});
        }        
        if (language != 'be'&& language != 'en' && language != 'es' && language != 'de' && language != 'fr' && language != 'it' && language != 'nl' && language != 'pt') {
            language = 'en';
        }

 At the end we use this to send an email to the service department:

 

 private void sendServiceMail() {
        Messaging.SingleEmailMessage serviceMail = new Messaging.SingleEmailMessage();
        serviceMail.setToAddresses(serviceEmailAddresses.get(language));
        serviceMail.setSenderDisplayName(Label.Sender_Display_Name);
        serviceMail.setReplyTo(noReplyEmail);
        serviceMail.setSubject('' + companyName + ', ' + addressCodeCity + ' - ' + serviceType + ' - ONLINE REQUEST');
        String serviceMailMessage = Label.Email_Subject_Service + ':\n\n';
        serviceMailMessage = serviceMailMessage + setPlainTextMessage('\n\n');
        serviceMail.setPlainTextBody(serviceMailMessage);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { serviceMail });        

 The third line I believe is correct, can anyone let me know otherwise?: 

                  serviceMail.setToAddresses (serviceEmailAddresses.get(language)); 

 

 The form works fine but for some unknown reason, sometimes it sends emails to the wrong inbox. Last time a client from Spain submitted his form     and it went to the uk.serviceparts address!! 

 Does anyone knows why this is happening? The script looks pretty straightforward ... 

 

Any help on this will be much appreciated. 

Thanks

Hello all,

 

I have a question regarding a form I want to build with Apex and Visualforce pages.

The form will have 1 row and 4 columns but I want  to allow the user to add more rows if needed.

The question is, what would be the best way to automatically add a new row when the user enters data on the first row?

Could anyone give me a few examples please?

Thanks in advanced!

 

 

Hello all,

 

 

There is a way to delete files older than 3 minutes? 

Thanks.

 

 

Hello all,

 

I'm trying to send an email from a Visualforce page after the user is done with a form. All this is working just fine. 

Now I need to add the possibility of adding an attachment to that form.  I use this code together with a visual force page and it works.

 

 public PageReference upload() {
      
      attachment.ParentId = '500Q0000004eDnT';
      attachment.IsPrivate = true;
      
      
    try {
      insert attachment;
    } catch (DMLException e) {
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
      return null;
    }
     finally{
      attachment = new Attachment(); 
    }
 
    ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Attachment uploaded successfully'));
    return null;
    
  }
  

 The problem is that now I need to attach that attachment to the email that will be send after the form is done and the attachment is uploaded. 

I was thinking on doing a SOQL on Attachments, something like this:

 

Attachment attachmentToSend = [select Body, Id, Name, ContentType from Attachment where Parentid=:' 500Q0000004eDnt'  FROM <------- after this the problem starts for me. 

 

Here is the question:

 

How can I get the id of that attachment that have been just uploaded and put it in some place to use it for my query in order for me to get the correct attachment for that email that will be send. 

I can query for all attachment but I need to get the id related to the one the user uploaded

 

Thanks

Hello all,

 

I having a hard time when trying to modify a apex code from the previous person that was working in my company. He was a developer and I'm not. My level in Apex is normal, I'm an administrator and I'm trying to pull this up because is kind of urgent for my company. 

 

We have a Scorecard system that will keep track of a number of fields from different objects. The scorecard object contains these cards for each account owner, contact related and leads.

 

 The all idea is that if you fill in a number of fields you will get a percentage in these scorecards. The scorecards have a page layout and in those page layouts you have fields that will keep track of the percentages. Lest say you fill in 50% of you phone field on you accounts, there is a field in your scorecard page layout with a field Account Phone Number Filled = 50%.  

This is done with a number of fields from different objects like I mentioned before. There is an apex schedule that will trigger the apex that update this scorecards every hour. 

 

This is the script: 

 

 

global class ScoreCardGenerator {

    global void processScoreCards() {

        final String RESOURCE_NAME_HAS = 'ScorecardQueriesHAS';
        final String RESOURCE_NAME_ALL = 'ScorecardQueriesALL';
    
        Map<String, Map<String, String>> scHASQueries = new Map<String, Map<String, String>>();
        Map<String, Map<String, String>> scALLQueries = new Map<String, Map<String, String>>();
        Map<Id, Score_Card__c> scoreCards = new Map<Id, Score_Card__c>();
        Map<String, String> fieldsToUpdateHAS = new Map<String, String>();
        Map<String, String> fieldsToUpdateALL = new Map<String, String>();
        StaticResource theStaticResource;
        List<Score_Card__c> updatedScoreCards = new List<Score_Card__c>();
        Set<Id> ownerIdKeys = new Set<Id>();
        Map<Id, Map<String, Double>> userHASResults = new Map<Id, Map<String, Double>>();
        Map<Id, Map<String, Double>> userALLResults = new Map<Id, Map<String, Double>>();
        DateTime todayDate = System.Now();
        DateTime startOfYear = DateTime.newInstanceGMT(todayDate.year(), 1, 1, 0, 0, 0);
        Integer currentHour = System.Now().hourGMT();

        try {
            theStaticResource = [SELECT id, Body FROM StaticResource WHERE name = :RESOURCE_NAME_HAS];
            String bodyText = theStaticResource.body.toString();
            List<String> bodyLines = bodyText.split('\n');
            for(String line : bodyLines) {
                if(line.trim().length() != 0) {
                    List<String> keyValuePairs = line.split('~');
                    String mapKey;
                    Map<String, String> tempMap = new Map<String, String>();
                    String objectName = '';
            
                    for(String pairString : keyValuePairs) {
                
                        // Some boilerplate splitting
                        List<String> pairs = pairString.split('#');
                        String key = pairs[0].trim();
                        String value = pairs[1].trim();
    
                        if (key == 'ID') {
                            mapKey = value;
                        }
                        else {
                            tempMap.put(key, value);
                        }
                        
                        if (key == 'OBJECT') {
                            objectName = value;
                        }   
            
                        if (key == 'FIELD') {
                            fieldsToUpdateHAS.put(value, objectName);
                        }
                    }
                    scHASQueries.put(mapKey, tempMap);
                }
            }
        } catch(System.QueryException e) {
            System.debug(e);
            // You should always let the admins/devs know if
            // something unexpected happened.
            // e.g. ExceptionUtils.mail(Administrator);
        }
           
        try {
            theStaticResource = [SELECT id, Body FROM StaticResource WHERE name = :RESOURCE_NAME_ALL];
            String bodyText = theStaticResource.body.toString();
            List<String> bodyLines = bodyText.split('\n');
            for(String line : bodyLines){
                if(line.trim().length() != 0) {
                    List<String> keyValuePairs = line.split('~');
                    String mapKey;
                    Map<String, String> tempMap = new Map<String, String>();
                    String objectName = '';
            
                    for(String pairString : keyValuePairs) {
            
                        // Some boilerplate splitting
                        List<String> pairs = pairString.split('#');
                        String key = pairs[0].trim();
                        String value = pairs[1].trim();
            
                        if (key == 'ID') {
                            mapKey = value;
                        }
                        else {
                            tempMap.put(key, value);
                        }
                        
                        if (key == 'OBJECT') {
                            objectName = value;
                        }   
            
                        if (key == 'FIELD') {
                            fieldsToUpdateALL.put(value, objectName);
                        }
                    }
                    scALLQueries.put(mapKey, tempMap);
                }
            }
        } catch(System.QueryException e) {
            System.debug(e);
            // You should always let the admins/devs know if
            // something unexpected happened.
            // e.g. ExceptionUtils.mail(Administrator);
        }   
        
        String businessUnitSalesTeam;
        if (currentHour == 0 || currentHour == 12) {
            businessUnitSalesTeam = 'Business_Unit__c = \'Benelux\'';
        }
        else if (currentHour == 1 || currentHour == 13) {
            businessUnitSalesTeam = 'Business_Unit__c = \'DACHI\' AND Sales_Team__c = \'Centre\'';
        }
        else if (currentHour == 2 || currentHour == 14) {
            businessUnitSalesTeam = 'Business_Unit__c = \'DACHI\' AND Sales_Team__c = \'North\'';
        }
        else if (currentHour == 3 || currentHour == 15) {
            businessUnitSalesTeam = 'Business_Unit__c = \'DACHI\' AND Sales_Team__c = \'South\'';
        }
        else if (currentHour == 4 || currentHour == 16) {
            businessUnitSalesTeam = 'Business_Unit__c = \'DACHI\' AND Sales_Team__c IN (\'Austria\', \'Dresden\', \'Italy\', \'Switzerland\')';
        }
        else if (currentHour == 5 || currentHour == 17) {
            businessUnitSalesTeam = 'Business_Unit__c IN (\'DB\', \'Consumer\', \'Hong Kong\')';
        }    
        else if (currentHour == 6 || currentHour == 18) {
            businessUnitSalesTeam = 'Business_Unit__c = \'Japan\'';
        }
        else if (currentHour == 7 || currentHour == 19) {
            businessUnitSalesTeam = 'Business_Unit__c = \'Spain\'';
        }
        else if (currentHour == 8 || currentHour == 20) {
            businessUnitSalesTeam = 'Business_Unit__c = \'UK\' AND Sales_Team__c = \'Key\'';
        }
        else if (currentHour == 9 || currentHour == 21) {
            businessUnitSalesTeam = 'Business_Unit__c = \'UK\' AND Sales_Team__c IN (\'Midlands\', \'MOD\')';
        }
        else if (currentHour == 10 || currentHour == 22) {
            businessUnitSalesTeam = 'Business_Unit__c = \'UK\' AND Sales_Team__c IN (\'North\', \'Telesales\')';
        }
        else if (currentHour == 11 || currentHour == 23) {
            businessUnitSalesTeam = 'Business_Unit__c = \'UK\' AND Sales_Team__c = \'South\'';
        }

    if (businessUnitSalesTeam != null) {
            for (Score_Card__c sc : Database.Query('Select Id, User__c FROM Score_Card__c WHERE Active__c = TRUE AND ' + businessUnitSalesTeam)) {
                scoreCards.put(sc.User__c, sc);
            }
        }
        ownerIdKeys = scorecards.keyset();
        for (Integer i = 1; i < scALLQueries.size()+1; i++) {
            String queryALL = scALLQueries.get(String.valueOf(i)).get('QUERYALL');
            for (AggregateResult arALL : Database.Query(queryALL + ' GROUP BY OwnerId ORDER BY OwnerId')) {
                Map<String, Double> tempMap = new Map<String, Double>();    
                if (userALLResults.containsKey(String.valueOf(arALL.get('OwnerId')))) {
                    tempMap = userALLResults.get(String.valueOf(arALL.get('OwnerId')));
                }
                tempMap.put(scALLQueries.get(String.valueOf(i)).get('OBJECT'), Double.valueOf(arALL.get('expr0')));
                userALLResults.put(String.valueOf(arALL.get('OwnerId')), tempMap);                      
            }
        } 
        for (Integer i = 1; i < scHASQueries.size()+1; i++) {
            String queryHAS = scHASQueries.get(String.valueOf(i)).get('QUERYHAS');
            for (AggregateResult arHAS : Database.Query(queryHAS + ' AND OwnerId IN :ownerIdKeys GROUP BY OwnerId ORDER BY OwnerId')) {
                Map<String, Double> tempMap = new Map<String, Double>();
                if (userHASResults.containsKey(String.valueOf(arHAS.get('OwnerId')))) {
                    tempMap = userHASResults.get(String.valueOf(arHAS.get('OwnerId')));
                }
                tempMap.put(scHASQueries.get(String.valueOf(i)).get('FIELD'), Double.valueOf(arHAS.get('expr0')));
                userHASResults.put(String.valueOf(arHAS.get('OwnerId')), tempMap);
            }
        }
        for (Id userId : ownerIdKeys) {
            SObject updateSC = scoreCards.get(userId);
            Set<String> hasFieldNames = fieldsToUpdateHAS.keySet();
            Set<String> allFieldNames = fieldsToUpdateALL.keySet();
            for (String field : hasFieldNames) {

        /*
                if (!userHASResults.get(userId).containsKey(field) || !userALLResults.get(userId).containsKey(fieldsToUpdateHAS.get(field)) || fieldsToUpdateHAS.get(field) == null) {
                  
                    updateSC.put(field, 0);
                }
        */
              if (fieldsToUpdateHAS.get(field) != null && !userALLResults.get(userId).containsKey(fieldsToUpdateHAS.get(field))) {
                updateSC.put(field, 100);
              }
                else if (!userHASResults.get(userId).containsKey(field) || fieldsToUpdateHAS.get(field) == null) {
                    updateSC.put(field, 0);
                }
                else {
                    updateSC.put(field, (userHASResults.get(userId).get(field) / userALLResults.get(userId).get(fieldsToUpdateHAS.get(field))) * 100);
                }
            }
            for (String field : allFieldNames) {
                if (!userALLResults.get(userId).containsKey(fieldsToUpdateALL.get(field))) {
                    updateSC.put(field, 0);
                }
                else {
                    updateSC.put(field, userALLResults.get(userId).get(fieldsToUpdateALL.get(field)));
                }
            }
            updatedScoreCards.add((Score_Card__c)updateSC);
        }       
        if (!updatedScoreCards.isEmpty()) { 
            update(updatedScoreCards);
        }
    } 
}

 

 

What I want is just to add another field in the scorecard object to track the Name in the Contact object.  I noticed that on the scrip there are two lines:

 

        final String RESOURCE_NAME_HAS = 'ScorecardQueriesHAS';
        final String RESOURCE_NAME_ALL = 'ScorecardQueriesALL';

 

These two lines are very important becasue they contain the query for the fields that are in the scorecards.

Here it is one of the files (ScorecardQueriesHAS):

 

ID#1~OBJECT#Event~FIELD#Events_with_Comments__c~QUERYHAS#SELECT OwnerId  count(Subject) FROM Event WHERE StartDateTime >= :startOfYear AND EndDateTime <= :todayDate AND Sales_Comments__c != '',,
ID#2~OBJECT#Account~FIELD#Accounts_with_Address__c~QUERYHAS#SELECT ownerId count(Name) FROM Account WHERE BillingStreet != '' AND BillingCity != '' AND BillingPostalCode != '' AND BillingCountry != '', ,
ID#3~OBJECT#AccountExact~FIELD#Accounts_with_Exact_Debtor_Number__c~QUERYHAS#SELECT OwnerId count(Name) FROM Account WHERE Id IN (SELECT AccountId FROM Opportunity WHERE IsWon = true AND RecordTypeId != '01280000000PydL') AND Exact_Debtor_Number__c != '',,
ID#4~OBJECT#Account~FIELD#Accounts_with_Segmentation__c~QUERYHAS#SELECT ownerId count(Name) FROM Account WHERE ((Industry != '' AND Life_Segment__c != '' AND Sub_Sector__c != '') OR (Segment__c != '' AND Industry__c != '' AND Dimension__c != '' AND Organization__c != '')), ,
ID#5~OBJECT#Account~FIELD#Accounts_with_Status__c~QUERYHAS#SELECT ownerId count(Name) FROM Account WHERE Account_Status__c != '', , ID#6~OBJECT#Account~FIELD#Accounts_with_Territory__c~QUERYHAS#SELECT ownerId count(Name) FROM Account WHERE Territory__c != '', , ID#7~OBJECT#Account~FIELD#Accounts_with_Zone__c~QUERYHAS#SELECT ownerId count(Name) FROM Account WHERE Zones__c != '',, ID#8~OBJECT#Account~FIELD#Accounts_with_Phone_Number__c~QUERYHAS#SELECT ownerId count(Name) FROM Account WHERE Phone != '', , ID#9~OBJECT#Account~FIELD#Contacts_with_Email_Address__c~QUERYHAS#Select ownerId COUNT(Name) FROM Account WHERE Id IN (SELECT AccountId FROM Contact WHERE Email != '' AND RecordTypeId != '01280000000PydJ'),,
ID#10~OBJECT#OpportunityProduct~FIELD#Open_Opportunities_with_Products__c~OBJECT#Opportunity~QUERYHAS#SELECT ownerId count(Name) FROM Opportunity WHERE IsClosed = FALSE AND HasOpportunityLineItem = true AND StageName NOT IN ('F- First Phase Open' 'P - Qualified Prospect'), ,
ID#11~OBJECT#Opportunity~FIELD#Open_Opportunities_with_Net_Revenue__c~QUERYHAS#SELECT OwnerId count(Name) FROM Opportunity WHERE IsClosed = FALSE AND Net_Revenue__c != NULL,,
ID#12~OBJECT#Account~FIELD#Contact_with_First_Name__c~QUERYHAS#Select ownerId COUNT(Name) FROM Account WHERE Id IN (SELECT AccountId FROM Contact WHERE Name != '' AND RecordTypeId != '01280000000PydJ'),,

 I added the last line ID#12. 

The first think that I'm not sure is when I try to view ScorecardQueriesHAS from the the Static Resources. I see that the file is a 

MIME Typeapplication/vnd.ms-excel

 and if I click on View file, I get a file and when I try to open this file I get the msg in excel: 'Excel has detected that 'ScorecardQueriesHAS (11).xls' is a SYKL file, but cannot load it. Either the file has errors or it is not a SKYLK file format.'

 

I beileve this is a csv file but I was wondering if there is any particular way to save this files or to modify them, because when I modified the file and put it back to the static resourcers the line ID#12 is not doing what it is suppose to do.

 

So, I need to know what I'm doing wrong here in order for me to be able to modify this. Any ideas?

 

One more question :( , I have to wait about one hour to see if there is any luck after making any modification. There is a way to execute this from the Developer Console?

 

Thanks in advance.

 

 

 

Hello all,

 

I'm trying to look for the best way to delete an Account if there is not Opportunies, Contacts, Tasks or Events active on that Account. Wat would be the best a more simple way to wirte this on Apex?

 

Thanks on advance.

 

 

 

Please help!!  I have lost the salesforce lab app and can't get it back.  Is it coming back or am I completely out of luck?  This was the best thing for iPad yet