• Leonardi Koh
  • NEWBIE
  • 85 Points
  • Member since 2015

  • Chatter
    Feed
  • 1
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 27
    Replies
Hello everyone,
I'm unable to execute this Batch test successfully.
I'm facing the following error ;:

Date de début30/11/2017 18:18
ClassebatchTaskRayTaskUpdateTest
Nom de méthodebatchTaskRayTaskUpdateTest
Réussite/ÉchecFail
Message d'erreurSystem.QueryException: line 1:105 no viable alternative at character '"'
Trace de pileClass.batchTaskRayTaskUpdate.start: line 4, column 1

I don't see any double quote at line 4!
I tried to delete and retype all of single quote, as said in existing posts but it does not solve the issue.

Here is the code:
@isTest(seeAllData=false)
public class batchTaskRayTaskUpdateTest {
    static testmethod void batchTaskRayTaskUpdateTest(){
    Test.startTest();
        TASKRAY__Project__c TRP1 = new TASKRAY__Project__c();
        TRP1.Name ='PlanningVianney';
        TRP1.RecordTypeId = '012b0000000UZYp';
        insert TRP1;
        
        Date oppDate = Date.newInstance(2018,01,8);        
        Opportunity Opp1 = new Opportunity();
        Opp1.Name ='OppVianneyTst';
        Opp1.StageName ='Devis en cours';
        Opp1.CloseDate=oppDate;
        insert Opp1;
                       
        TASKRAY__Project_Task__c taskR1= new TASKRAY__Project_Task__c();
        TASKRAY__Project_Task__c taskR2= new TASKRAY__Project_Task__c();
        TASKRAY__Project_Task__c taskR3= new TASKRAY__Project_Task__c();       
        
        
        
        Date taskRayDate = Date.newInstance(2017,12,6);
                
        taskR1.Name='testTask1';        
        taskR2.Name='testTask2';
        taskR3.Name='testTask3';
        taskR1.TASKRAY__Deadline__c = taskRayDate;
        taskR2.TASKRAY__Deadline__c = taskRayDate;
        taskR3.TASKRAY__Deadline__c = taskRayDate;
        taskR2.RecordTypeID = '012b0000000UZUs';
        taskR3.RecordTypeId = '012b0000000UZUs';
        taskR1.RecordTypeId = '012b0000000UZUs';
        
        taskR1.TASKRAY__Project__c = TRP1.Id;
        taskR2.TASKRAY__Project__c = TRP1.Id;
        taskR3.TASKRAY__Project__c = TRP1.Id;
       
        taskR1.Opportunity__c = Opp1.Id;
        taskR2.Opportunity__c = Opp1.Id;
        taskR3.Opportunity__c = Opp1.Id;
        
        List<TASKRAY__Project_Task__c> taskRList = new List<TASKRAY__Project_Task__c>();
        taskRList.add(taskR1);
        taskRList.add(taskR2);
        taskRList.add(taskR3);
        insert taskRList;
              
               
        batchTaskRayTaskUpdate b = new batchTaskRayTaskUpdate();
        database.executeBatch(b);
        TASKRAY__Project_Task__c newTaskR1 =[SELECT Name, TASKRAY__Project__c, TASKRAY__Deadline__c from TASKRAY__Project_Task__c where Id=:taskRList[0].Id];
        TASKRAY__Project_Task__c newTaskR2 =[SELECT Name, TASKRAY__Project__c, TASKRAY__Deadline__c from TASKRAY__Project_Task__c where Id=:taskRList[1].Id];
        TASKRAY__Project_Task__c newTaskR3 =[SELECT Name, TASKRAY__Project__c, TASKRAY__Deadline__c from TASKRAY__Project_Task__c where Id=:taskRList[2].Id];
        
        
        
    Test.stopTest();
    } 
}
Thanks for the help!

Vianney

 
As the title suggested, I am attempting to access the Proxy Handler target content in javascript running on an Aura component , so I had a line similar to
 
var theElements = document.getElementsByClassName('slds-text-heading_small');
console.log(theElements);

in my Aura component, and when rendered predictably enough this shows a Proxy object with Handler, etc... typical of what one expect.

(the result looks like this:)
User-added image

so I can see it right there in the console, and in the example above i can see the innerText, outerText value etc...

So the question is what is the correct way to read these values in javascript?

For example, if i want to read the value of this Proxy -> Handler -> target -> 0 (1st element of this HTMLCollection) -> innerText

then what is the correct way to do it in javascript?
With regular webpage and javascript, the old method i can recall for checking if a certain element is within the user's view port (to ensure that the element is actually visible by the user before performing certain css effects) involve using getBoundingClientRect.

Then there's the new method involving IntersectionObserver.

From what i understand, i cannot utilize IntersectionObserver in Lightning Component as i recall that it is not currently supported by the underlying secure window in Lightning Component (please correct me if i am wrong there)...

So my assumption is that currently we only can use getBoundingClientRect to ascertain the position of our element in Lightning Component.

But i noticed that when i used getBoundingClientRect to check my element's position... the value does not appear to be accurate.

To be more precise, in my case said lightning component was placed inside a page via Lightning Community Builder within certain layout, and it appears that the position value returned is the position relative to the parent element and NOT the position of the element relative to the user's view port.

So what would be the best way to do this currently?
So in the past we used the following to get our code running once rendering is complete
<aura:handler event="aura:doneRendering" action="{!c.onRender}"/>

In particular, I have utilized this to allow my elements to make use of slds-transition.

So i have a component with "slds-transition-hide"

And the moment rendering is complete i have the following code
onRender : function(component, event, helper) {
     // Fade In the components 
     var targetcomp = component.find('mycomponent');
     $A.util.removeClass(targetcomp, 'slds-transition-hide');
     $A.util.addClass(targetcomp, 'slds-transition-show');
},

Which produce the effect of the component slowly transitioning into view... (for the timing it's controlled by css with transition: opacity 3s;)

This works perfectly fine... but since aura:doneRendering is apparently deprecated and replaced by the newer render event we were updating our components and replacing them with
<aura:handler name="render" value="{!this}" action="{!c.onRender}"/>

Excep now all our codes that previously worked fine for onRender doesn't do anything anymore...

Am i missing something with the usage of the newer render event? I had assumed it would've behaved exactly the same as doneRendering but that does not appear to be the case.
I noticed that lightning:inputField does not appear to provide the option to create new record when it is showing a lookup field, unlike force:inputField

User-added image

So unlike the above example of force:inputField... lightning:inputField of the exact same field would show a similar lookup EXCEPT the 'New' part and this applies to both aura component as well as lightning web component.

Is there any way to have this functionality on the lightning:inputField?

Why not just use force:inputField you might ask.
Well that is because there is a bug involving force:inputField and aura:iteration which Salesforce never fixed for years already (and i doubt they'll ever fix it).

https://success.salesforce.com/issues_view?id=a1p3A0000008gDzQAI
Salesforce Analytics REST API provide us with 
/wave/lenses/<lens ID> [GET]

to retrieve resources that makes up the Lens, one of which is the query.

This however returns the SAQL query in it's short form, rather than the complete one that we'll see in the Analytics Studio SAQL Mode. So is this all we can get from the REST API?

And if this is the case, then is there any way to get the REST API Analytic Query
/wave/query [POST]

to accept this short form SAQL?
Recently i discovered the following error on a custom scheduler class runtime.

"First error: SfdcSchedulerFactoryImpl has not been initialized - check your CronScheduler config"

This scheduler class was designed to automatically reschedule itself periodically, and for a long while now has been doing the job without any issue, until this error came recently.

If i am to hazard a guess it has something to do with a class that the Scheduler system is dependent upon in the internal system which for some reason isn't initializing properly, but does anyone have an idea what exactly is this error about or what caused it?
So i've been trying to update the CustomField metadata using Tooling API through Apex class, but i have no idea if this is actually possible.

What i've done so far is:
String endpoint = 'https://XXX.salesforce.com/services/data/v41.0/tooling';
String param = '/sobjects/CustomField/{Custom Field Id}?_HttpMethod=PATCH';

HttpRequest req2 = createHttpRequest(endpoint+param, 'POST');
req2.setBody('{"Metadata":{"summaryFilterItems":[{"field":"MyObject__c.MyField__c","operation":"greaterThan","value":"1/01/2018"}]}}');

String responseJSON2 = getResponse(req2);
...
private HttpRequest createHttpRequest(String endpoint, String method) {
        HttpRequest req = new HttpRequest();        
        // endpoint += '';
        req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());
        req.setHeader('Content-Type', 'application/json');
        req.setEndpoint(endpoint);
        req.setMethod(method);
        return req;
}
...
private String getResponse(HttpRequest req) {
        try {
            Http httpreq = new Http();
            HttpResponse res = httpreq.send(req);
            String reqresponse = res.getBody();
            return reqresponse;
        }
        catch (Exception e) {
          return 'Error:' +e.getMessage();
        }
}

But i've been constantly rejected by Tooling API indicating that they could not resolve the standard field name

Does anyone have any luck with this kind of process in Apex?
Hi guys, i have a most peculiar behavior with Salesforce scheduler that i've never seen before
So i wrote a little code whose job is just to queue itself every minute to do some work
SomeClass m = new SomeClass();
datetime nextMinuteRun = datetime.now().addMinutes(1);

string sch = '0 '+ string.valueof(nextMinuteRun.minute()) + ' ' + 
string.valueof(nextMinuteRun.hour()) + ' ' + 
string.valueof(nextMinuteRun.day())
+ ' ' + string.valueof(nextMinuteRun.month()) + ' ? ' 
+ string.valueof(nextMinuteRun.year());
            
system.schedule('Keep Running ', sch, m);
This system works fine and keeps rescheduling itself every minute
.. most of the time that is because once in a while, the schedule will fail with the exception in the title and i'd have to restart the scheduler manually again.

Now my guess is that there are times when the system was scheduling itself at say 11:59 : 59
and that gives the next runtime schedule of 12:00 : 00 (a 1 second difference)
but during the process... by the time Salesforce reached the line to schedule the systtem, it was already at 12:00:00, and this causes the failure.

Now, what i am curious is... can Salesforce actually take THAT LONG before it processed the schedule line?
1 second sounds like a short time, but in computer processing that ought to be a long time... especially since this is a line by line code processing that normally would take a fraction of a second.
Hi,

i recently created a Visualforce Page utilizing BootStrap and noticed that the when viewed in Salesforce1 for iOS, the page button which was created using apex:commandButton would keep move the page to the top and not executing the appropriate method in the controller that has been linked to the commandButton.

after digging around, i found several issues which while not exactly the same appears related to an extent and they mentioned scripts that can help the issue, the one i found to be most useful was the following:
 
(function() {
	try {
		var a = navigator.userAgent;
		if ((a.indexOf('Salesforce') != -1) && (a.indexOf('iPhone') != -1 || a.indexOf('iPad') != -1) && (a.indexOf('OS/8') != -1 || a.indexOf('OS 8') != -1 || a.indexOf('OS/9') != -1 || a.indexOf('OS 9') != -1) && (a.indexOf('Safari') == -1)) {		
			var s = document.createElement('style');
			if (a.indexOf('OS/8') != -1 || a.indexOf('OS 8') != -1) {
				s.innerHTML = "html,html body{overflow: auto;-webkit-overflow-scrolling:touch;}body{position:absolute;left:0;right:0;top:0;bottom:0;}";
			} else if (a.indexOf('OS/9') != -1 || a.indexOf('OS 9') != -1) {
				s.innerHTML = "html,html body{overflow: auto;-webkit-overflow-scrolling:auto;}body{position:absolute;left:0;right:0;top:0;bottom:0;}";
			}
			document.getElementsByTagName('head')[0].appendChild(s);
		}
	} catch (e) {}
})();

and voila, it worked and the button now worked in Salesforce1 for iOS (it worked fine for Android from the start so no issue there)

I noticed however that the scroll is very rigid and absolute, ie: it has no 'slide' and thus the scroll moves at a painfully slow rate for a long page.

Does anyone ever encountered similar issue? Or perhaps had a similar problem as i had with the button moving the page to the top and have a different solution that work better than the script i used above?
So according to the documentation, SOSL can be instructed to search within limited types of text fields using the 'IN' clause
much like so:
FIND {"Test*"} IN NAME FIELDS RETURNING Product2 (Id, Name)

for example and according to the same documentation, this should return the results from Product2 that contain the word "test" or very close to it... within the Name field (no additional fields are searched according to the list for Product2)

The behavior within the instance i tested however did not follow this, and the SOSL instead behaves much like it's default state where it seaches in 'ALL FIELDS' mode,

it is returning results where the Name field of Product2 most definitely do not contain the characters in question, but the character sequence does exist in a custom field within Product2.

Is there something missing within the syntax usage of the SOSL that i have missed that is somehow altering the behavior in this manner?
Hi guys, i have a most peculiar behavior with Salesforce scheduler that i've never seen before
So i wrote a little code whose job is just to queue itself every minute to do some work
SomeClass m = new SomeClass();
datetime nextMinuteRun = datetime.now().addMinutes(1);

string sch = '0 '+ string.valueof(nextMinuteRun.minute()) + ' ' + 
string.valueof(nextMinuteRun.hour()) + ' ' + 
string.valueof(nextMinuteRun.day())
+ ' ' + string.valueof(nextMinuteRun.month()) + ' ? ' 
+ string.valueof(nextMinuteRun.year());
            
system.schedule('Keep Running ', sch, m);
This system works fine and keeps rescheduling itself every minute
.. most of the time that is because once in a while, the schedule will fail with the exception in the title and i'd have to restart the scheduler manually again.

Now my guess is that there are times when the system was scheduling itself at say 11:59 : 59
and that gives the next runtime schedule of 12:00 : 00 (a 1 second difference)
but during the process... by the time Salesforce reached the line to schedule the systtem, it was already at 12:00:00, and this causes the failure.

Now, what i am curious is... can Salesforce actually take THAT LONG before it processed the schedule line?
1 second sounds like a short time, but in computer processing that ought to be a long time... especially since this is a line by line code processing that normally would take a fraction of a second.
public class BatchAccountUpdate implements Database.Batchable<sObject>, Database.Stateful {
    
    public Database.QueryLocator start(Database.BatchableContext BC){
        String query =  ' Select Id, Name,ParentId'
            + ' from Account ' 
            + ' where Account.Recordtype.DeveloperName = \'IndustriesIndividual\' ' 
            + ' and ParentId = Null ';
        
        
        return Database.getQueryLocator(query);
    }
    
    
    public void execute(Database.BatchableContext bc, List<Account> accounts ){
        
        Map<Id, Account> accountToUpdateMap = new Map<Id, Account>();
        Map<Id, Id> mapAccountIndvAccIdToHouseholdAccId = new Map<Id, Id>();
        
        // fetch primary contact for individual account 
        // and inner query to fetch house hold account contact relation
        for(Contact con : [SELECT Id, AccountId,Account.ParentId,
                           ( SELECT Id, ContactId, AccountId
                            FROM AccountContactRelations 
                            WHERE Account.RecordType.DeveloperName = 'IndustriesHousehold' 
                           )
                           FROM Contact 
                           WHERE AccountId in: accounts 
                          ] ){
                              
                   for( AccountContactRelation acr : con.AccountContactRelations ) {
                         con.Account.ParentId = acr.AccountId;
                         mapAccountIndvAccIdToHouseholdAccId.put( con.AccountId, acr.AccountId );
                   }
        }
        
        for(Account acc : [ SELECT Id, ParentId 
                            FROM Account 
                            WHERE Id IN: accounts
                          ]){
                              
            if( acc.ParentId == Null && mapAccountIndvAccIdToHouseholdAccId.containsKey( acc.Id )){
                Account accToUpdate = new Account( Id = acc.Id, 
                                                   ParentId = mapAccountIndvAccIdToHouseholdAccId.get(  acc.Id ));
                accountToUpdateMap.put( accToUpdate.Id, accToUpdate );
            } 
        }
         
        if( accountToUpdateMap.size() > 0 ){
            update accountToUpdateMap.values();
        } 
    }
     
    public void finish(Database.BatchableContext bc){ 
        
    }
}
Hi, 
I can't understand why my 500 Pts Challenge is not validated while all the items are right. 
The error message is : Challenge Not yet complete... here's what's wrong:
The 'Web Leads' report is not using Leads as the report type.
But my type report is "Pistes" that means Leads in French
Any help?
Thanks


 
Hi guys,
We just created a library named R.apex, which helps simplify the common tasks in apex code development by adopting a functional style.
It offers tons of utility functions to work with lists, sets, maps and sobjects, making apex code clean and readable. We were suffering from the pain points of writing similar Apex code to complete trivial tasks once and once again, and that is the reason why we want to stop that and start to write reusable code. Here are some examples of what R.apex can do:
 
// Reverse a list
List<Integer> reversedList = R.of(new List<Integer>{ 1, 2, 3 })
    .reverse()
    .toIntegerList();
 
// Fina specific account
List<Account> accountList = ...;
Account acc = (Account)R.of(accountList)
    .find(R.whereEq.apply(new Map<String, Object>{
        'LastName' => 'Wilson',
        'IsDeleted' => false
    }))
    .toSObject();

Hopefully R.apex can help make your Apex code development easier, and you are always welcome to give feedback so that we can improve it.

R.apex is an open source project hosted at https://github.com/Click-to-Cloud/R.apex/.
You can check it out. Feel free to clone it, make changes or submit a PR.

^_^
Hi

I'm trying to write a trigger to update a custom text field on the account object based on the line items (Name field) from a custom object that's linked to the account object. I want the values on the custom text field to be updated as an when line items are added / edited to the custom object or  even deleted. 
I'm quite new to apex so any guidance will be helpful, thanks
 
I'm using the validation rule below to check if the billing period field is blank when the opportunity stage is Compliance and it works perfectly, but 
I actually have 3 more pick list values (Conditions Met, Funded and No Sale) I'd to check if the billing period is blank. What is the syntax for this? I've done many searches and can't find an answer. I feel like this is so simple. Thanks for your help.

ISPICKVAL(Stage__c,"Compliance") 
&& ISBLANK(Billing_period__c)
Hi, 

  I have a helper class code which is working as expected need your suggestion in making this bulkified. Please suggest the code change with logic
public static void processOptySharingOppTeam(List<Opportunity> newLst) {
     List<id> actIds = new List<id>();
     List<id> paractIds = new List<id>();
     List<id> OpptIds = new List<id>();
     map<id,Opportunity_Sharing__c> oppshare = new map<id,Opportunity_Sharing__c>([select id, Account_Names__c, Key_Text__c, Partner_Account_Names__c,User__c,Access_Level__c,Global_Account_Rep__c,Top_Account_ID__r.id, Top_Partner_Account_ID__r.id from Opportunity_Sharing__c]);
     List<OpportunityTeamMember> Otmlst = new List<OpportunityTeamMember>();
     String TopActID;
     String TopPartActId; 
     
     for(Opportunity opp : newLst) {
       OpptIds.add(opp.id); 
       actIds.add(opp.AccountID);
       paractIds.add(opp.partner_account__c);
         }
  
       if(!actIds.isempty()){
       TopActID = GetTopLevleElement(actIds[0]);
       }
       
       if(!paractIds.isempty()){
       TopPartActId = GetTopLevleElement(paractIds[0]);
       }
      
        system.debug('TopActID  :' + TopActID);
        system.debug('TopPartActId :' + TopPartActId); 
      
   
       for(Opportunity_Sharing__c rec : oppshare.values()){
            if(TopActID <> null && TopActID == rec.Top_Account_ID__r.id){
              system.debug('Found Account Id '  + rec.Top_Account_ID__r.id );
               if( rec.User__c != null & rec.Access_Level__c != null ){
                   OpportunityTeamMember otm = new OpportunityTeamMember(OpportunityId = OpptIds[0],UserId=rec.User__c,OpportunityAccessLevel=rec.Access_Level__c
                                                                              ,TeamMemberRole=rec.Global_Account_Rep__c  ); 
                        Otmlst.add(otm);
                 }
               }      
               
            if(TopPartActId <> null && TopPartActId  == rec.Top_Partner_Account_ID__r.id){
              system.debug('Found Partner Account Id '  + rec.Top_Partner_Account_ID__r.id );
               if( rec.User__c != null & rec.Access_Level__c != null ){
                   OpportunityTeamMember otm = new OpportunityTeamMember(OpportunityId = OpptIds[0],UserId=rec.User__c,OpportunityAccessLevel=rec.Access_Level__c
                                                                              ,TeamMemberRole=rec.Global_Account_Rep__c  ); 
                        Otmlst.add(otm);
                 }
               }      
               
               
           }
          
            if(!Otmlst.Isempty()){ 
              insert Otmlst; 

       }   
   
   }
            
    public static String GetTopLevleElement(Id objId ){
        Boolean topLevelParent = false;
        if( objId <> null){
        while ( !topLevelParent ) {
            Account a = [ Select Id, ParentId From Account where Id = :objId limit 1 ];
            if ( a.ParentID != null ) {
                objId = a.ParentID;
            }
            else {
                topLevelParent = true;
            }
        }
         }
        return objId ;
    }

Thanks
Sudhir
 
Is there any way of creating a basic Code Coverage Class to allow me to move the changes to Production?

The visualforce page I have is simply to have an output in PDF format.  There is no record update or inserts.  Is there anyway of creating somewhich will allow me to push the code to Production

thanks
Not sure if my syntax is correct, what I'm trying to achive is updating a text field (X80_20__c), where the data is coming from a formula text field (X80_20_Yes_or_No__c). The output from the formula field produces a Yes or No value.

This is the Apex trigger I attempted but its not populating the X80_20__c field. Any help would be appreciated or would a Apex Class be better to do in this situation? Also, I'm avoiding in using a workflow trigger or process builder for this.
 
trigger a8020 on Account (before insert,before update) {
    List obj = [SELECT Id,Name,X80_20_Yes_or_No__c,X80_20__c FROM Account WHERE
 (X80_20_Yes_or_No__c = 'Yes' OR X80_20_Yes_or_no__c = 'No') AND
 Outlet_Type__c = 'Home Depot' AND Has_1_2_3x5_DULO__c = 'Yes' ]; 

    for (Account a: obj) {
        string s = a.X80_20_Yes_or_No__c; 
        a.X80_20__c = s;  
    } 

    update obj; 
}

 
Hello,
I'm new to triggers and struggling with this. I need a trigger that pulls the Opportunity name and creates a new record in my custom object, AE Opp. I do not need it to create a lookup or link it to the opp, i just need it to create a whole new record so that I can create a task on it.. Is this feasible?
Error Received:

Apex script unhandled trigger exception by user/organization: 00570000004LeTu/00D300000006E35
 
Region_cLeadTrigger: execution of BeforeInsert
 
caused by: System.QueryException: List has no rows for assignment to SObject
 
Trigger.Region_cLeadTrigger: line 3, column 1




Below is the full Trigger:

trigger Region_cLeadTrigger on Lead (before insert) {

    staticResource sr = [
        select Body
        from StaticResource
        where Name = 'regionjson'
    ];
    String country = '';
    JSONParser parser = JSON.createParser(sr.Body.toString());
   
    try {
        if(Trigger.isBefore) {
            for (Lead l : trigger.New) { 
                System.debug('Inbound country is: ' + l.Country__c + ' Inbound Region is: ' + l.Region__c);
                if (l.Region__c == null) {
                    String region = findRegion(l.Country__c);
                    System.debug('Value of new region is: ' + region);
                    if (region != null) {
                        l.Region__c = region;
                    }
                }
            }
        }
    } catch (Exception ex) {
        System.debug('Unable to save region due to incorrect mapping error is: ' + ex);
    }
    private String findRegion(String uiCountry) {
        boolean rootFlag = false;
        String country;
        while (parser.nextToken() != null) {
            // root found
            if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'Workbook')) {
                System.debug('Found root!');
                rootFlag = true;
                parser.nextToken();
            }         
            if (rootFlag)  {
                if (parser.getCurrentToken() == JSONToken.FIELD_NAME) {
                    country = parser.getText();
                    while (parser.nextToken() != null) {
                        if (parser.getCurrentToken() == JSONToken.VALUE_STRING) {
                            if (uiCountry.equalsIgnoreCase(country)) {
                                return parser.getText();   
                            }
                            break;
                        }                      
                    }
                }
            }
        }
        return null;
    }
}
 
Hi All - I am getting the follwoing error : Illegal assignment from List<AggregateResult> to List<Deployment_Item__c> for the code in Apex : 

 List<Deployment_Item__c> DIList = [SELECT Count(Member_Value__c),    Name_tag__c
                                             FROM  Deployment_Item__c
                                           WHERE Created_Date__c = Today
                                           GROUP BY Name_tag__c ];
Kindly help me to resolve this . 

Thanks,
Sujatha.M

 
  • December 21, 2017
  • Like
  • 0
Can you suggest me to get below requirment with code samples. 

Button that will display all email details and comments for the case in a page 
Button created, would display all emails and their details along with all comments relating to the case.

thanks 
Hello Friends,

I'm getting the following error because the trigger doesn't have enough coverage. How do I accomplish that? Thank you!
The following triggers have 0% code coverage. Each trigger must have at least 1% code coverage.
 
trigger Product00001 on OpportunityLineItem( after insert, after update )
{
    List<OpportunityLineItem> oliList = new List<OpportunityLineItem>();
    Set<Id> opptyIds = new Set<Id>();
 
    for( OpportunityLineItem optLineItem: trigger.new )
    {
        if( optLineItem.ProductCode == '00001a' )
        {
            opptyIds.add( optLineItem.OpportunityId );
        }
    }
 
    if( opptyIds.size() > 0 )
    {
        //retrieve the values based on Product list
List<OpportunityLineItem> lstOpptyLineItems = [ SELECT Opportunity.Pricebook2Id, OpportunityId, Name, ProductCode,
                                                        PricebookEntryId, Quantity, UnitPrice
                                                        FROM OpportunityLineItem
                                                        WHERE OpportunityId IN: opptyIds order by ProductCode ];
 
        Map<Id, List<OpportunityLineItem>> mapOpptyLineItem = new Map<Id, List<OpportunityLineItem>>();
        for( OpportunityLineItem item : lstOpptyLineItems )
        {
            List<OpportunityLineItem> oliList1 = new List<OpportunityLineItem>();
            if( mapOpptyLineItem.containsKey( item.OpportunityId ))
            {
                oliList1 = mapOpptyLineItem.get( item.OpportunityId );
            }
            
            oliList1.add( item );
            mapOpptyLineItem.put( item.OpportunityId, oliList1 );
        }
 
 
        //retrieve PriceBookEntry of the Product B, this is most important
        PricebookEntry pbeProduct2 = [ SELECT Id, Pricebook2Id, UnitPrice, Name, Percentage_Entry__c
                                        FROM PricebookEntry
                                        WHERE Name ='Product 00001'
                                        AND Pricebook2Id  IN (SELECT Id FROM PriceBook2 WHERE Id ='01sA00000004lbRIAQ')
                                        LIMIT 1 ];
 
         if( trigger.isInsert )
         {
             for( Id oppId : mapOpptyLineItem.keySet() )
             {
                 for( OpportunityLineItem item : mapOpptyLineItem.get( oppId ))
                 {
                     if( item.ProductCode == '00001a' )
                     {
                         oliList.add( new OpportunityLineItem(
                                            OpportunityId = oppId,
                                            PricebookEntryId = pbeProduct2.Id,
                                            Quantity = item.Quantity,
                                            UnitPrice = item.UnitPrice * pbeProduct2.Percentage_Entry__c * 0.01 )
                                          );
                     }
                 }
             }
             
             if( oliList.size() > 0 )
                 insert oliList;
         }
         else if( trigger.isUpdate )
         {
             for( Id oppId : mapOpptyLineItem.keySet() )
             {
                 OpportunityLineItem itemProductA = new OpportunityLineItem();
                 for( OpportunityLineItem item : mapOpptyLineItem.get( oppId ))
                 {
                     if( item.ProductCode == '00001a' )
                     {
                         itemProductA = item;
                         break;
                     }
                 }

                 for( OpportunityLineItem item : mapOpptyLineItem.get( oppId ))
                 {
                     if( item.ProductCode == '00001b' )
                     {
                         oliList.add( new OpportunityLineItem( Id = item.Id,
                                            OpportunityId = oppId,
                                            PricebookEntryId = pbeProduct2.Id,
                                            Quantity = itemProductA.Quantity,
                                            UnitPrice = itemProductA.UnitPrice * pbeProduct2.Percentage_Entry__c * 0.01 )
                                          );
                     }
                 }
             }
             
             if( oliList.size() > 0 )
                 update oliList;
         }
    }
}

 
  • December 14, 2017
  • Like
  • 0
Hi,

  I have a code below which is working perfect in saleforce need suggestion make it bulkified. Please suggest me how to modify 
// Working Code

Public class ContactCertificateRollupHandlerNew1{
 
Public static Map<id,integer> NSEmap1;
Public static Map<id,integer> NSEmap2;
Public static Map<id,integer> NSEmap3;
Public static Map<id,integer> NSEmap4;
Public static Map<id,integer> NSEmap5;
Public static Map<id,integer> NSEmap7;
Public static Map<id,integer> NSEmap8;

Public static Map<id,integer> NSEmap6;

Public static Integer NSEint1 = 0;
Public static Integer NSEint2 = 0;
Public static Integer NSEint3 = 0;
Public static Integer NSEint4 = 0;
Public static Integer NSEint5 = 0;
Public static Integer NSEint7 = 0;
Public static Integer NSEint8 = 0;

Public static Integer NSEint6 = 0;

Public static List<account> NSE1_Update = new List<account>();
Public static List<account> NSE2_Update = new List<account>(); 
Public static List<account> NSE3_Update = new List<account>();
Public static List<account> NSE4_Update = new List<account>();
Public static List<account> NSE5_Update = new List<account>();
Public static List<account> NSE7_Update = new List<account>();
Public static List<account> NSE8_Update = new List<account>();

Public static List<account> NSE6_Update = new List<account>();
 
Public static map<id,account> NSE1_Update_Map = new map<id,account>();
Public static map<id,account> NSE2_Update_Map = new map<id,account>();
Public static map<id,account> NSE3_Update_Map = new map<id,account>();
Public static map<id,account> NSE4_Update_Map = new map<id,account>();
Public static map<id,account> NSE5_Update_Map = new map<id,account>();
Public static map<id,account> NSE7_Update_Map = new map<id,account>();
Public static map<id,account> NSE8_Update_Map = new map<id,account>();

Public static Account LastAccount; 

public class CertRollupSum {
        Integer Nse6 = 0;  
        Boolean NSE_6_FortiMail = false;
        Boolean NSE_6_FortiWeb = false;
        Boolean NSE_6_FortiWireless = false;
        Boolean NSE_6_FortiAuthenticator = false;
        Boolean NSE_6_FortiADC_D = false;
        Boolean NSE_6_FortiADC_E = false;
        Boolean NSE_6_FortiDDos = false;
        Boolean NSE_6_FortiSandbox = false;
        Boolean NSE_6_FortiWireless_Controller = false;
    }
     
public static void ProcessInsert(List<Contact> newCntLst){
   
    set<id> actidSet = new set<id>();
       
     for(Contact cont : newCntLst){
       actidSet.add(cont.AccountId);                                 
      }  
 }
  
 public static void ProcessDelete (List<Contact> oldCntLst){
 
     list<id> actidlst = new list<id>();       
     for(Contact cont : oldCntLst){
       actidlst.add(cont.AccountId);                                       
      }  
      GetLastAccounts(actidlst[0]);        
 } 
 
 public static void ProcessUpdate (Map<id, Contact> newMap, Map<id, Contact> oldMap){
 
    set<id> actidSet = new set<id>();
    list<id> actidlst = new list<id>();
    
    for(Contact cont : newMap.values()){
          actidlst.add(cont.AccountId);
      }                    
 
        GetLastAccounts(actidlst[0]); 
    
       
  }
     
     
  public static void GetLastAccounts (Id AccountID){    
   
    set<id> GetAllActID = new set<id>();

    GetAllActID = GetChildToParnet(AccountID);
    GetAllActID = GetParnetToChild(AccountID);
    
    system.debug('ChildToParent ' + AccountHierarchyUtil.ChildToParnet(AccountID));
    system.debug('ParenttoChild ' + AccountHierarchyUtil.ParnetToChild(AccountID));
    
    if( AccountHierarchyUtil.ParnetToChild(AccountID).size() > 0 ) {
      List<Account> LastAct = [SELECT Id, name FROM Account where id in :GetAllActID];
  
      LastAccount  = LastAct[LastAct.size() - 1]; 
        accountRollupUpdate(LastAccount.id);
     } else {
       accountRollupUpdate(AccountID);
      
     }   
     
   }
   
  
   public static void accountRollupUpdate(Id PAccountID) {
        
        Id accountId = PAccountID;
        
        NSEmap1 = new Map<id,integer>();
        NSEmap2 = new Map<id,integer>();
        NSEmap3 = new Map<id,integer>();
        NSEmap4 = new Map<id,integer>();
        NSEmap5 = new Map<id,integer>();
        NSEmap7 = new Map<id,integer>();
        NSEmap8 = new Map<id,integer>();
        NSEmap6 = new Map<id,integer>();

        ChildToParnet(accountId);

        if(NSEmap1.size()>0){
    
            For(Id i : NSEmap1.keyset()){        
                Account ains = new Account(); 
                ains.id = i;
        
                system.debug('Account' + i);       
                system.debug(NSEmap1.get(i));
        
                ains.NSE_1_Status__c = NSEmap1.get(i);
                   NSE1_Update.add(ains);                      
            }
        }


       if(NSEmap2.size()>0){
    
           For(Id i : NSEmap2.keyset()){        
               Account ains = new Account();        
               ains.id = i;
        
              system.debug('Account' + i);        
              system.debug(NSEmap2.get(i));
        
              ains.NSE_2_Status__c = NSEmap2.get(i);        
                NSE2_Update.add(ains);
                      
           }
        }
        
       if(NSEmap3.size()>0){
    
           For(Id i : NSEmap3.keyset()){        
               Account ains = new Account();        
               ains.id = i;
        
              system.debug('Account' + i);        
              system.debug(NSEmap3.get(i));
        
              ains.NSE_3_Status__c = NSEmap3.get(i);        
                NSE3_Update.add(ains);
                      
           }
        }
          
       if(NSEmap4.size()>0){
    
           For(Id i : NSEmap4.keyset()){        
               Account ains = new Account();        
               ains.id = i;
        
              system.debug('Account' + i);        
              system.debug(NSEmap4.get(i));
        
              ains.NSE_4_Status__c = NSEmap4.get(i);        
                NSE4_Update.add(ains);
                      
           }
        }  
        
       if(NSEmap5.size()>0){
    
           For(Id i : NSEmap5.keyset()){        
               Account ains = new Account();        
               ains.id = i;
        
              system.debug('Account' + i);        
              system.debug(NSEmap5.get(i));
        
              ains.NSE_5_Status__c = NSEmap5.get(i);        
                NSE5_Update.add(ains);
                      
           }
        }   
        
       if(NSEmap7.size()>0){
    
           For(Id i : NSEmap7.keyset()){        
               Account ains = new Account();        
               ains.id = i;
        
              system.debug('Account' + i);        
              system.debug(NSEmap7.get(i));
        
              ains.NSE_7_Status__c = NSEmap7.get(i);        
                NSE7_Update.add(ains);
                      
           }
        }  
        
       if(NSEmap8.size()>0){
    
           For(Id i : NSEmap8.keyset()){        
               Account ains = new Account();        
               ains.id = i;
        
              system.debug('Account' + i);        
              system.debug(NSEmap8.get(i));
        
              ains.NSE_8_Status__c = NSEmap8.get(i);        
                NSE8_Update.add(ains);
                      
           }
        }                            

       if(NSEmap6.size()>0){
    
           For(Id i : NSEmap6.keyset()){        
               Account ains = new Account();        
               ains.id = i;
        
              system.debug('Account' + i);        
              system.debug(NSEmap6.get(i));
        
              ains.NSE_6_Status__c = NSEmap6.get(i);        
                NSE6_Update.add(ains);
                     
           }
        }     
                
        if(NSE1_Update.size()>0)           
          
          update NSE1_Update;

        if(NSE2_Update.size()>0)
        
          update NSE2_Update;  
          
        if(NSE3_Update.size()>0)
        
          update NSE3_Update;  
          
        if(NSE4_Update.size()>0)
        
          update NSE4_Update;   
          
        if(NSE5_Update.size()>0)
        
          update NSE5_Update;  
          
        if(NSE7_Update.size()>0)
        
          update NSE7_Update;   
          
        if(NSE8_Update.size()>0)
        
          update NSE8_Update;                        
            
        if(NSE6_Update.size()>0)
        
          update NSE6_Update; 
              
          /* map<id,account> nse1map = new map<id,account>();
            nse1map.putall(NSE1_Update);
        
            if(nse1map.size()>0){
            update nse1map.values();         
            }
            
            map<id,account> nse2map = new map<id,account>();
            nse2map.putall(NSE2_Update);
        
            if(nse2map.size()>0){
            update nse2map.values();
            }    */        
            
        
   }


public static void ChildToParnet (Id ChildId){
     
    For(Account acc : [select id,name, parentid,NSE_6_Status__c, (Select id,NSE_1__c,NSE_2__c,NSE_3__c,NSE_4__c,NSE_5__c,NSE_7__c,NSE_8__c,
                                                                         NSE_6_FortiMail__c, NSE_6_FortiWeb__c, NSE_6_FortiWireless__c, 
                                                                         NSE_6_FortiAuthenticator__c, NSE_6_FortiADC_D__c, NSE_6_FortiADC_E__c, NSE_6_FortiDDos__c, 
                                                                         NSE_6_FortiSandbox__c,NSE_6_FortiWireless_Controller__c 
                                                  from contacts)from account where id =: ChildId]){
        CertRollupSum rollup = new CertRollupSum();
        For(Contact c : acc.contacts ){
          
            if(c.NSE_1__c == true)               
                 NSEint1 = NSEint1 +1;                                 
            
            if(c.NSE_2__c == true)
                NSEint2 = NSEint2 + 1;  
                
            if(c.NSE_3__c == true)
                NSEint3 = NSEint3 + 1;    
               
            if(c.NSE_4__c == true)
                NSEint4 = NSEint4 + 1;  
                
            if(c.NSE_5__c == true)
                NSEint5 = NSEint5 + 1; 
                
            if(c.NSE_7__c == true)
                NSEint7 = NSEint7 + 1;   
                
            if(c.NSE_8__c == true)
                NSEint8 = NSEint8 + 1;     
                
              if(c.NSE_6_FortiMail__c && !rollup.NSE_6_FortiMail) {
                    rollup.NSE_6_FortiMail = true;
                    rollup.Nse6 += 1;
                    //NSEint6 = rollup.Nse6; // Single rollup
                    NSEint6 = NSEint6 + 1;   // Multiple rollup
                }
                if(c.NSE_6_FortiWeb__c && !rollup.NSE_6_FortiWeb) {
                    rollup.NSE_6_FortiWeb = true;
                    rollup.Nse6 += 1;
                    //NSEint6 = rollup.Nse6;
                    NSEint6 = NSEint6 + 1;
                }
                if(c.NSE_6_FortiWireless__c && !rollup.NSE_6_FortiWireless) {
                    rollup.NSE_6_FortiWireless = true;
                    rollup.Nse6 += 1;
                    //NSEint6 = rollup.Nse6;
                    NSEint6 = NSEint6 + 1;
                }
                if(c.NSE_6_FortiAuthenticator__c && !rollup.NSE_6_FortiAuthenticator) {
                    rollup.NSE_6_FortiAuthenticator = true;
                    rollup.Nse6 += 1;
                    //NSEint6 = rollup.Nse6; 
                    NSEint6 = NSEint6 + 1;
                }
                if(c.NSE_6_FortiADC_D__c && !rollup.NSE_6_FortiADC_D) {
                    rollup.NSE_6_FortiADC_D = true;
                    rollup.Nse6 += 1;
                    //NSEint6 = rollup.Nse6;
                    NSEint6 = NSEint6 + 1;
                }
                if(c.NSE_6_FortiADC_E__c && !rollup.NSE_6_FortiADC_E) {
                    rollup.NSE_6_FortiADC_E = true;
                    rollup.Nse6 += 1;
                    //NSEint6 = rollup.Nse6;
                    NSEint6 = NSEint6 + 1;
                }
                if(c.NSE_6_FortiDDos__c && !rollup.NSE_6_FortiDDos) {
                    rollup.NSE_6_FortiDDos = true;
                    rollup.Nse6 += 1;
                    //NSEint6 = rollup.Nse6;
                    NSEint6 = NSEint6 + 1;
                }
                if(c.NSE_6_FortiSandbox__c && !rollup.NSE_6_FortiSandbox) {
                    rollup.NSE_6_FortiSandbox = true;
                    rollup.Nse6 += 1;
                    //NSEint6 = rollup.Nse6;
                    NSEint6 = NSEint6 + 1;
                }
                if(c.NSE_6_FortiWireless_Controller__c && !rollup.NSE_6_FortiWireless_Controller) {
                    rollup.NSE_6_FortiWireless_Controller = true;
                    rollup.Nse6 += 1;
                    //NSEint6 = rollup.Nse6;
                    NSEint6 = NSEint6 + 1;
                }               
                
                                                                                                             
            
        }
           NSEmap1.put(acc.id,NSEint1);
           NSEmap2.put(acc.id,NSEint2);  
           NSEmap3.put(acc.id,NSEint3);
           NSEmap4.put(acc.id,NSEint4);
           NSEmap5.put(acc.id,NSEint5);
           NSEmap7.put(acc.id,NSEint7);
           NSEmap8.put(acc.id,NSEint8);            
           NSEmap6.put(acc.id,NSEint6);
           
        if(acc.parentid != null)            
           childToParnet(acc.parentid);
        
     }
  }
  
   public static set<id> GetChildToParnet (Id PAccountID){
        
        set<id> setactid = new set<id>();
        
        Id accountId = PAccountID;
        
        Account[] allparents = new Account[] {};
            
            Set<Id> parentIds = new Set<Id>{accountId};
                
                Account[] parent;
        
        do {
            
            parent = [select Id,ParentId, Name from Account where Id in :parentIds];
            
            allparents.addAll(parent);
            
            parentIds.clear();
            
            for (Account par : parent) 
                
                parentIds.add(par.ParentId);
            
        } while (parent.size() > 0);
        
        list<Account> Act = [select id, name from account where id in :allparents];
        
        for(Account A : Act){
            
            system.debug('Parent Accounts ' + a.name);  
            setactid.add(a.id);
            
        }      
        
        return setactid;
        
    }
    
    public static set<id> GetParnetToChild (Id PAccountID){
        
        set<id> setactid = new set<id>();
        
        Id accountId = PAccountID;
        
        Account[] allChildren = new Account[] {};
            
            Set<Id> parentIds = new Set<Id>{accountId};
                
                Account[] children;
        
        do {
            
            children = [select Id, Name from Account where ParentId in :parentIds];
            
            allChildren.addAll(children);
            
            parentIds.clear();
            
            for (Account child : children) 
                
                parentIds.add(child.Id);
            
        } while (children.size() > 0);
        
        list<Account> Act = [select id, name from account where id in :allChildren];
        
        for(Account A : Act){
            
            system.debug('Child Accounts ' + a.name);  
            setactid.add(a.id);      
            
        }
        return setactid;
    }  
    

  }
Thanks
Sudhir
 
Hello community

I'm struggling with a small error which I can't seem to find an answer to. Can you help?

[{"message":"bad value for restricted picklist field: Bristol","errorCode":"INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST","fields":["RM_Region__c"]}]

There are scores of picklist values within "RM_Region__c". For some reason, "Bristol" is being rejected.

The closest I can get to a possible answer is that "Bristol" needs to be allocated somewhere for it to work?

I'd really appreciate any ideas the community have.

Many thanks and look forward to hearing from you.

Define Parent Object:Foo with Standard Field "Name".
Define Child Object: Bar with Standard Field "Name" and Custom Field Lookup(Foo) (with Child Relationship Name Bars).
Define Grandchild Object: Ziff with Standard Field "Name" and Custom Field Lookup(Bar) (with Child Relationship Name Ziffs).

Background:

 

1. This queries the Parent Foo and makes elements of Bar visible:

Select Name,(Select Name from Bars__r) from Foo__c


2. This queries the Child Bar  and makes elements of Foo visible:

Select Name, Foo__r.Name From Bar__c where Foo__c  !=  null

3. These queries in the Grandchild work:

 

Select Name,  Bar__r.Name From Ziff__c

Select Name,  Bar__r.Name, Bar__r.Foo__r.Name From Ziff__c


I'm seeking a query on the Parent Foo, similar to #1, that makes elements of Bar and Ziff visible.

 

Thanks.