• mrferdos mrferdos
  • NEWBIE
  • 3 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 18
    Replies
I have more than 500 records in invoice which is in related list to one account and the name of the account is "Account1"(Invoice- Account: Lookup relationship). Now Im try to insert more than 10 records into Invoice for the same account using dataloader. In that time only Im getting an error like "System.LimitException: Too many SOQL queries: 101". 
And my code is public class CommercientSF21InvoiceTriggerHandler1 {
    public static void accountUpdate(List<Invoice__c> currentRecordId){
        List<Account> accUpdate = new List<Account>();
        List<Account> accountWithoutInvoice = new List<Account>();
        Id accountId;
        for(Invoice__c acc : currentRecordId ){
            accountId = acc.Account__c;
        }
        List<Invoice__c> invoiceList = [select Id,CommercientSF21_IVM_InvoiceDate__c from Invoice__c where Account__c=: accountId];
        System.debug(invoiceList.size());
         for(Account acc : [select id,Current_Year_Revenue__c,Last_Order_Date__c,
                           Previous_Year_Revenue__c from Account where Id =:accountId]){
                               if(invoiceList.size() == 0){
                                   acc.Current_Year_Revenue__c = NULL;
                                   acc.Lifetime_Value_LTV__c = NULL;
                                   acc.Previous_Year_Revenue__c = NULL;
                                   accountWithoutInvoice.add(acc);
                               }
                           }
        map<id,account> accmap = new map<id,account>();
        accmap.putall(accountWithoutInvoice);
        if(accmap.size()>0){
            update accmap.values();
        }
        Set<Id> currentYearRecordIds = new Set<Id>();
        Set<Id> previousYearRecordIds = new Set<Id>();
        for(integer i=0; i<invoiceList.size(); i++){ 
            Datetime record = invoiceList[i].CommercientSF21_IVM_InvoiceDate__c;
            if(record != NULL){ 
                String yearoftherecord = String.valueOf(record.Year());
                Integer curentYear = Date.Today().Year();
                String currentYearInteger = String.valueOf(curentYear);
                Integer previousyear = curentYear -1;
                String previousyearInteger = String.valueOf(previousyear);
                if(currentYearInteger == yearoftherecord ){
                    currentYearRecordIds.add(invoiceList[i].Id);
                }
                else if(previousyearInteger == yearoftherecord){
                    previousYearRecordIds.add(invoiceList[i].Id);
                }
            }
        }
        List<AggregateResult> currentYearAmountList = [SELECT SUM(CommercientSF21_IVM_InvoiceAmt_c__c )tot FROM Invoice__c WHERE Id= :currentYearRecordIds];
        List<AggregateResult> previousYearAmountList = [SELECT SUM(CommercientSF21_IVM_InvoiceAmt_c__c )tot FROM Invoice__c WHERE Id= :previousYearRecordIds];
        List<AggregateResult> totalAmountList = [SELECT SUM(CommercientSF21_IVM_InvoiceAmt_c__c )tot FROM Invoice__c WHERE Account__c =: accountId ];
        System.debug(totalAmountList);
        Object sumAmountCurrentYear;
        Object sumAmountPreviousYear; 
        Object sumAmountTotalYear;
        for(AggregateResult acc : currentYearAmountList){
            sumAmountCurrentYear = acc.get('tot');  
        }
        for(AggregateResult acc : previousYearAmountList){
            sumAmountPreviousYear = acc.get('tot');  
        }
        
        for(AggregateResult acc : totalAmountList){
            sumAmountTotalYear = acc.get('tot');  
        }
        for(Account acc: [select id,Current_Year_Revenue__c,Last_Order_Date__c,
                          Previous_Year_Revenue__c from Account where Id =: accountId] ){
                              acc.Previous_Year_Revenue__c = Integer.valueOf(sumAmountPreviousYear);
                              acc.Current_Year_Revenue__c = Integer.valueOf(sumAmountCurrentYear);
                              acc.Lifetime_Value_LTV__c = Integer.valueOf(sumAmountTotalYear);
                              accUpdate.add(acc);
                          }
        map<id,account> accMapToUpdate = new map<id,account>();
        accMapToUpdate.putall(accUpdate);
        if(accMapToUpdate.size()>0){
            update accMapToUpdate.values();
        } 
    } 
}
Chat Transcript tabs  wont close for users. When i try the keyboard shortcuts like Shift + W, this "We couldn’t close your tabs. Try closing them manually." error appears. I would do that but the tabs don't have close buttons. I attempted creating a button to place on the record page that if clicked would close the focused tab but that didnt appear to work either. Any tips would be great! Thanks! 
I have successfully integrated the google api services and also i am abe to create .CSV fine in the google drive.But the data inside the CSV file is null(it must be due to incorrect or in proper body format). Please have a look at the code and tell me where to correct it.
Document doc = new Document(Name = 'documentName', Body = Blob.valueOf(csvFile),  Type = 'csv', ContentType='application/vnd.ms-excel');
Here the csvFile is string which contains the data of the CSV in proper format(including spaces and commas).I have used email and upload services to check the CSV file and recieved exactly what I wanted. So I used the following code for drive upload.
String boundary = 'SalesforceNewsTechnologyStuff';
String delimiter = '\r\n--' + boundary + '\r\n'; 
String close_delim = '\r\n--' + boundary + '--';
String bodyEncoded = EncodingUtil.base64Encode(doc.body);
String body = delimiter + 'Content-Type: application/json\r\n\r\n' + '{ "name" : "' + doc.Name + '",' + ' "mimeType" : "text/csv"}' + delimiter + 'Content-Type: text/application/vnd.ms-excel'  + '\r\n' + 'Content-Transfer-Encoding: base64\r\n' + '\r\n' + bodyEncoded + close_delim;
HttpRequest req = new HttpRequest();
req.setheader('Content-Length',String.valueOf(body.length()));
req.setheader('Content-Type','multipart/related; boundary='+boundary);
req.setMethod('POST'); 
req.setEndpoint('callout:Drive1'); 
req.setBody(body); 
Http h = new Http();
Httpresponse resp = h.send(req);
A blank csv gets created every time this code runs.Can any one suggest me how to add the data in the csv file?

 
Hi All, 

I am using Source Code Scanner for scanning my code. But it isn't identifying all the issues that come with Salesforce's security report. 

How do I identify all the issues before submitting my app again? 

Thank you. 
Hi,

I'm trying to complete the trailhead "" and encountering a challenge.  If anyone has any feedback for me on this, I'd appreciate very much.  

Added VerifyDate.apxc as I did with TemperatureConverter.apxc.  Added TestVerifyDate.apxc (even with VerifyDateTest.apxc) as I did with TemperatureConverterTest.apxc.  I verified that those classes exist per screenshot1 below:
User-added image

I'm supposed to be able to go to Test, select New Run, then with Select Tests pop-up, I'm supposed to see the TestVerifyDate (and/or VerifyDateTest) classes to select and run; however, I'm not seeing those test classes.  Why?  Even with "[All Namespaces]", they still don't show.  

Workaround for now is to run the test suite per instructions earlier in the trailhead.  

Reference screenshot2 below:
User-added image

Thanks in advance for your help.
Tien





 
Hi All,
In Salesforce Lightning, do we have any option to remove/disable the Drilldown/View report hyper link on Dashboard?.

Thanks,
Naren
Hi all,

We're thinking about activating Dev Hub in our production org, but I see that once it's been enabled, it can't be disabled. Is there any downside to enabling Dev Hub? Will we still have access to our old sandbox system? There's a lot of in-flight development in the current sandboxes and we don't want to change the way we work yet, we just want to explore Dev Hub and see it working in a practical environment.

Is there anything else we might need to bear in mind when activating Dev Hub? The documentation is a bit patchy on this subject.

Thanks!
As I am only a contract employee and I am sick of starting new each time I move to a new org to work in, I thought it time to ask the question. How do I change my trailhead email for logging in from my work (current employer) email to my 'personal work' email.

How do I solve the error

REQUEST_LIMIT_EXCEEDED: TotalRequests Limit exceeded.

 

Riyaj

  • May 17, 2012
  • Like
  • 1

Hi,

 

I am following the book "Developement with the Force.com platform" by JasonOuelette.

When creating the Custom Objects, I did not check the box to be visible in a tab, and so I could not add this object to the Custom App I was creating. Now I have a created fields and relationships in the custom object. How do I add this Object to the Custom App?

 

thanks

Svidya

  • September 27, 2010
  • Like
  • 2

Problem statement:

 

When APEX inserting OpportunityShare records, you get DML Exception: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY

 

Why does this happen?

 

The obvious reasons are:

 

  • OpportunityShare.OpportunityId is for an invalid Opportunity (or not an opportunity at all)
  • Running user doesn't have access to the Opportunity in OpportunityId



But if neither of these are the case...what else could it be?

 

ANSWER:

 

You can not insert OpportunityShare records for the current owner of the record.  You'll need to modify the Apex code to see if the current owner is the same as OpportunityShare.UserOrGroupId.  If it is, then don't insert.  You can still create OpportunityTeamMember records for that user but not OpportunityShare.  Who the current user is will depend if you are doing the OpportunityShare Dml statement in a before trigger, after trigger, VF controller, or API.

 

Although I haven't tested this, I presume the above applies to AccountShare and CaseShare objects as well.

I want to convert DateTime Value to Date Value , Please help me out ????????????