• SaketJoshi
  • NEWBIE
  • 167 Points
  • Member since 2014


  • Chatter
    Feed
  • 5
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 30
    Replies
hello all,

I am writing a trigger that sums up the invoice balances from a managed package object Zuora__ZInvoice__c custom field(Zuora__Balance2__c) to a field open_balance__c on the account. I wrote a corresponnding test class for the same and my test classes assertion method is failing. Am not sure why DML operation is failing.
trigger UpdateOpenBalance on Zuora__ZInvoice__c (after insert, after update) {
  
  Set<Id> Acc = new Set<Id>();
  List<account> ade = new List<account>();
  
   for(Zuora__ZInvoice__c zi : trigger.new){
      if(Trigger.isInsert){
          Acc.add(zi.Zuora__Account__c);
      }
         else if (Trigger.isUpdate){
            Acc.add(zi.Zuora__Account__c);
         }
   }
   
   List<Account> AccountsImpacted = [SELECT Id,Open_Balance__c FROM Account WHERE Id IN :Acc];
   List<Zuora__ZInvoice__c> Invoices = [SELECT Id,Zuora__Balance2__c,Zuora__Account__c FROM Zuora__ZInvoice__c WHERE Zuora__Account__c IN:AccountsImpacted];  
   Set<Zuora__ZInvoice__c>InvToAdd = new Set<Zuora__ZInvoice__c>();
   
   for(Zuora__ZInvoice__c inv : Invoices){
      InvToAdd.add(inv);
   }
   
  if(AccountsImpacted.size() > 0){
   for( Account a : AccountsImpacted){
     a.Open_Balance__c = 0.00;
     for( Zuora__ZInvoice__c zd : InvToAdd){
        a.Open_Balance__c = a.Open_Balance__c + zd.Zuora__Balance2__c ;
        ade.add(a);
     }
   }
  }
   
   update ade ;
}

Apex Test Class
@istest(SeeAllData = true)

 public class TestUpdateOpenBalance{
   public static testmethod void UpdateOpenBalance(){
      Account a = new Account();
     // a.RecordType = 'Client';
      a.name = 'Test Account';
      a.Type_of_Client__c = 'Commercial';
      insert a;
      Profile profileId = [SELECT Id FROM Profile WHERE Name = 'Standard User' LIMIT 1];

      User u = new User();
      u.LastName = 'Test Code';
      u.Email = 'test@test.com';
      u.Alias = 'Tcode';
      u.Username = 'ramupdhay@chatopadhay.com';
      u.CommunityNickname = 'test12';
      u.LocaleSidKey = 'en_US';
      u.TimeZoneSidKey = 'GMT';
      u.ProfileID = profileId.id;
      u.LanguageLocaleKey = 'en_US';
      u.EmailEncodingKey = 'UTF-8';
      insert u;
     
     a.CS_Primary__c = u.id;
     update a;
     
     Zuora__CustomerAccount__c ba = new Zuora__CustomerAccount__c();
     ba.name = 'Test Test';
     ba.Zuora__Account__c = a.id;
     ba.Zuora__Credit_Balance__c = 10.00;
     insert ba;
     
     Zuora__ZInvoice__c zi = new Zuora__ZInvoice__c();
     zi.Name = 'Test Invoice';
     zi.Zuora__Account__c = a.id;
     zi.Zuora__Balance2__c = 10.00;
     insert zi;
     
     zi.Zuora__Balance2__c = 20.00;
     update zi;
     
      System.assertEquals(20,a.open_balance__c);
    
   }
 }
 
I have a batch job which is currently calling out to an external API for just 1 record  at a time and is getting response back for ALL reords which is over 12 MB.
Can Salesforce do something to chunk the response into smaller uints and process them correctly or does the external API needs to just send the response back for 1 record, instead of sending them all at once??

I think it should be the latter as I don't know any method to do the former.
Please provide some guidance if you happen to know.

Thanks!
  • I have class A and I want to display List<A> on VF Page.
  • // Class A
    public with sharing class A
    {
        public String p;
        public String q;
        public String r;
        public String s;
        public String t;
    }
    
    // My Apex Code
    public class MyApexClass
    {
        public void m1()
        {
            StaticResource sr = [select id,body from StaticResource Where Name = 'MyFile'];
            String contents = sr.body.toString();
            List<A> list_obj = new List<A>();
            for(String line : contents.split('\n')) 
            {
                String[] myArray= line.split('#');
                A a = new A();
                a.p = myArray[0];
                a.q  = myArray[1];
                a.r  = myArray[2];
                a.s  = myArray[3];
                a.t  = myArray[4];
                list_obj.add(a) ;
            }
        }
    }

     

 
I want the dialog popup to display only when the checkbox is checked, but this code displys when checked and unchecked. I want a different pop up for uncheck..How do I write that script?
checkbox code
<input id="showprompt" type="checkbox" name="CO_BRAND" value="cobrand"  onclick="ShowPrompt()" /> 

Javascript Code

<script>
    
var checkmodal = document.getElementById('checkboxModal');
var btn = document.getElementById("showprompt");
var span = document.getElementsByClassName("checkboxclose")[0];


function ShowPrompt()

{
  checkmodal.style.display = "block";
  
}

span.onclick = function() {
    checkmodal.style.display = "none";
}

window.onclick = function(event) {
    if (event.target == modal) {
        checkmodal.style.display = "none";
    }
}
  • April 13, 2017
  • Like
  • 0
Hi folks,
   Can anyone give me the test code for My apex Trigger;
Trigger:
     trigger Test_Share on Test__c (after insert) {
    Id UserId=UserInfo.getUserId();
    Boolean bln=false;
    List<Id> ParentUserId = new List<Id>();
    User u = new User();
    while(bln == false){
       
      u = [select id,ManagerId from user where id = :UserId];
       if(u.ManagerId == null){
           
          bln = true;
      }
       else{
          ParentUserId.add(u.ManagerId);
          UserId = u.ManagerId;
      }
  
  }
  
    //ID groupId = [select id from Group where Type = 'Organization'].id;
    Id parent;
        if(trigger.isInsert){
   
    List<Test__Share> testShare= new List<Test__Share>();
         for(Test__c t : trigger.new){
            
           parent=t.Id;
          
           for(Integer j=0;j<ParentUserId.size();j++)
           {
               
                //string ob='ts'+coun;
                Test__Share ob= new Test__Share();
                ob.ParentId = parent;
                ob.UserOrGroupId =ParentUserId[j];
               
                system.debug('Id='+ParentUserId[j]);


       
                ob.AccessLevel = 'edit';

                ob.RowCause = Schema.Test__Share.RowCause.Test_Access__c;
                testShare.add(ob);
                //coun++;
                              
           }
        }
       
            if(!testShare.isEmpty())
                insert testShare;
           
           
    }
}



My test scenario :
If user1 creates record on test object then it is visible to all 49 users and If user50 creates record then it is visble to all user
Hierarchy is
user1-->user2-->user3-->.....user50
user1's manager is user2 and user2's manager is usr3 and etc



My test code is:
@isTest
private class TestUserCreate {
     static testMethod void testShares() {
       
        List<Test__c> deleteTestData= [select id from Test__c limit 50000];
        if(deleteTestData.size()>0)
            delete deleteTestData;
       
        Set<ID> ids = new Set<ID>();
        List<User> users = new List<User>();
        List<User> updatedusers = new List<User>();
        String pid = [Select id from Profile where Name='Test Reps'].Id;
        for(integer i=1; i<=50; i++){
           
  
            User tuser = new User(  firstname = 'test',
                            lastName = 'Name'+i,
                            email = 'testname'+i+'@email.com',
                            Username = 'testname'+i+'@email.com',
                            EmailEncodingKey = 'ISO-8859-1',
                            Alias = 'test',
                            TimeZoneSidKey = 'America/Los_Angeles',
                            LocaleSidKey = 'en_US',
                            LanguageLocaleKey = 'en_US',
                            ProfileId = pid);
            users.add(tuser);
                           
        }
        insert users;
        for(Integer i=0;i<users.size();i++){
                             
            if(i!=49){
                users[i].ManagerId=users[i+1].Id;
                             
            }
           
        }
       update users;
        for(user u:users){
            System.debug('LastName='+u.LastName);
            System.debug('UserId='+u.Id);
            System.debug('UserManager Id='+u.ManagerId);
        }
        Test__c t=new Test__c();
        t.Email__c='test@gmail.com';
        t.Mobile__c='12345678';
        t.OwnerId=users[0].id;
       
        insert t;
        system.debug('Test t='+t);
       
        List<Test__Share> testsha = [select id from Test__Share where AccessLevel = 'edit' ];
        System.debug('TestShares='+testsha.size());
System.assertEquals( testsha.size(),49);
    }
}



The above test code covers only 62%
Please Help!

lightning on init method 

controller$doInit [jQuery is not defined] anyone know what to do about this?
Hi Expert, 

I am using a trigger that will fire to delete any record but when  record delete then new screen appears
"The record you attempted to access has been deleted. The user who deleted this record may be able to recover it from the Recycle Bin. Deleted data is stored in the Recycle Bin for 15 days."

But here i don't need this message.
Can any one plesae suggest.

Thanks
Mukesh 
Response code: 400
Error,  { "error": { "code": "BadRequest", "message": "The MIME type 'text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2' requires a '/' character between type and subtype, such as 'text/plain'.", "innerError": { "request-id": "822a994e-6ef7-4c4c-bd27-5b96186165f0", "date": "2017-04-13T13:44:15" } } }

        HttpRequest req = new HttpRequest();
        req.setMethod('GET');
        req.setHeader('Content-Type', 'application/json');
        req.setHeader('Authorization', 'Bearer '+ accessToken);
        req.setEndpoint('https://graph.microsoft.com/v1.0/me/drive/root');      
        HttpResponse res = h.send(req);
hello all,

I am writing a trigger that sums up the invoice balances from a managed package object Zuora__ZInvoice__c custom field(Zuora__Balance2__c) to a field open_balance__c on the account. I wrote a corresponnding test class for the same and my test classes assertion method is failing. Am not sure why DML operation is failing.
trigger UpdateOpenBalance on Zuora__ZInvoice__c (after insert, after update) {
  
  Set<Id> Acc = new Set<Id>();
  List<account> ade = new List<account>();
  
   for(Zuora__ZInvoice__c zi : trigger.new){
      if(Trigger.isInsert){
          Acc.add(zi.Zuora__Account__c);
      }
         else if (Trigger.isUpdate){
            Acc.add(zi.Zuora__Account__c);
         }
   }
   
   List<Account> AccountsImpacted = [SELECT Id,Open_Balance__c FROM Account WHERE Id IN :Acc];
   List<Zuora__ZInvoice__c> Invoices = [SELECT Id,Zuora__Balance2__c,Zuora__Account__c FROM Zuora__ZInvoice__c WHERE Zuora__Account__c IN:AccountsImpacted];  
   Set<Zuora__ZInvoice__c>InvToAdd = new Set<Zuora__ZInvoice__c>();
   
   for(Zuora__ZInvoice__c inv : Invoices){
      InvToAdd.add(inv);
   }
   
  if(AccountsImpacted.size() > 0){
   for( Account a : AccountsImpacted){
     a.Open_Balance__c = 0.00;
     for( Zuora__ZInvoice__c zd : InvToAdd){
        a.Open_Balance__c = a.Open_Balance__c + zd.Zuora__Balance2__c ;
        ade.add(a);
     }
   }
  }
   
   update ade ;
}

Apex Test Class
@istest(SeeAllData = true)

 public class TestUpdateOpenBalance{
   public static testmethod void UpdateOpenBalance(){
      Account a = new Account();
     // a.RecordType = 'Client';
      a.name = 'Test Account';
      a.Type_of_Client__c = 'Commercial';
      insert a;
      Profile profileId = [SELECT Id FROM Profile WHERE Name = 'Standard User' LIMIT 1];

      User u = new User();
      u.LastName = 'Test Code';
      u.Email = 'test@test.com';
      u.Alias = 'Tcode';
      u.Username = 'ramupdhay@chatopadhay.com';
      u.CommunityNickname = 'test12';
      u.LocaleSidKey = 'en_US';
      u.TimeZoneSidKey = 'GMT';
      u.ProfileID = profileId.id;
      u.LanguageLocaleKey = 'en_US';
      u.EmailEncodingKey = 'UTF-8';
      insert u;
     
     a.CS_Primary__c = u.id;
     update a;
     
     Zuora__CustomerAccount__c ba = new Zuora__CustomerAccount__c();
     ba.name = 'Test Test';
     ba.Zuora__Account__c = a.id;
     ba.Zuora__Credit_Balance__c = 10.00;
     insert ba;
     
     Zuora__ZInvoice__c zi = new Zuora__ZInvoice__c();
     zi.Name = 'Test Invoice';
     zi.Zuora__Account__c = a.id;
     zi.Zuora__Balance2__c = 10.00;
     insert zi;
     
     zi.Zuora__Balance2__c = 20.00;
     update zi;
     
      System.assertEquals(20,a.open_balance__c);
    
   }
 }
 
I have a batch job which is currently calling out to an external API for just 1 record  at a time and is getting response back for ALL reords which is over 12 MB.
Can Salesforce do something to chunk the response into smaller uints and process them correctly or does the external API needs to just send the response back for 1 record, instead of sending them all at once??

I think it should be the latter as I don't know any method to do the former.
Please provide some guidance if you happen to know.

Thanks!
We are trying to post apex page messages to our custom community Visualforce Pages where we have a Language Dropdown that drops a cookie for the language to change to spanish using custom labels and translation workbench.
Unfortunately it doesn't apply to any page messages sent through apexPages.addMessage() through Apex Controller even if we use a custom label in the class that doesn't get translated.

Any help would be greatly appreciated.

Thanks!
its my Trigger

// this trigger used and sum of the contact on the account object
trigger countcontacts on Contact (after insert, after delete) {
    Set<Id> aId = new Set<Id>();
    
    if(Trigger.isInsert){
        System.debug('Insert contact for trigger.new - '+Trigger.New);
        for(Contact opp : Trigger.New){
            aId.add(opp.AccountId);
        }
        List<Account> acc = [select id,sum_of_the_contact__c from Account where Id in:aId];
        List<Contact> con = [select id from contact where AccountId in :aId];
        
        for(Account a : acc){
            a.sum_of_the_contact__c=con.size();
        }
        update acc;
        System.debug('Number is '+acc);
    }
    
    if(Trigger.isDelete){
        System.debug('delete contact for trigger.old - '+Trigger.Old);
        for(Contact opp : Trigger.old){
            aId.add(opp.AccountId);
        }
        List<Account> acc = [select id,sum_of_the_contact__c from Account where Id in:aId];
        List<Contact> con = [select id from contact where AccountId in :aId];
        
        for(Account a : acc){
            a.sum_of_the_contact__c=con.size();
            
        }
        update acc;
        System.debug('Number is '+acc);
    }
    }
    *****************************************
    its my test class but only covred 58% how to 100% please slove
    
    
    @isTest
public class countcontacts_Test{
    @isTest
    static void tesMethodss()
    {
        account ac=new account(name='test');
        insert ac;
        
        contact cont=new contact(lastName='test',firstName='test', Accountid=ac.Id);
        insert cont;
      
        
    }
}
**************************************************************
  • April 13, 2017
  • Like
  • 0
  • I have class A and I want to display List<A> on VF Page.
  • // Class A
    public with sharing class A
    {
        public String p;
        public String q;
        public String r;
        public String s;
        public String t;
    }
    
    // My Apex Code
    public class MyApexClass
    {
        public void m1()
        {
            StaticResource sr = [select id,body from StaticResource Where Name = 'MyFile'];
            String contents = sr.body.toString();
            List<A> list_obj = new List<A>();
            for(String line : contents.split('\n')) 
            {
                String[] myArray= line.split('#');
                A a = new A();
                a.p = myArray[0];
                a.q  = myArray[1];
                a.r  = myArray[2];
                a.s  = myArray[3];
                a.t  = myArray[4];
                list_obj.add(a) ;
            }
        }
    }

     

 
Hi All,
I have developed a custom component and I'm facing an issue related to CSP. When I open the component from the quick action for the first time it works well, but when I close the window that contains the component and I open it again (from the quick action), I'm facing in the console the following error and the component will never load. 

Refused to execute JavaScript URL because it violates the following Content Security Policy directive: "script-src 'self' chrome-extension: https://sfdc.azureedge.net *.na35.visual.force.com https://ssl.gstatic.com/accessibility/". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.

Screenshot from Chrome browser.

User-added image


Note: if I deactive Lightning LockerService Security I'm not facing that problem, but the component never load.

Is this an issue or is going to be the default behaviour from now?

has anyone had this problem?

Thanks in advance


 
I want the dialog popup to display only when the checkbox is checked, but this code displys when checked and unchecked. I want a different pop up for uncheck..How do I write that script?
checkbox code
<input id="showprompt" type="checkbox" name="CO_BRAND" value="cobrand"  onclick="ShowPrompt()" /> 

Javascript Code

<script>
    
var checkmodal = document.getElementById('checkboxModal');
var btn = document.getElementById("showprompt");
var span = document.getElementsByClassName("checkboxclose")[0];


function ShowPrompt()

{
  checkmodal.style.display = "block";
  
}

span.onclick = function() {
    checkmodal.style.display = "none";
}

window.onclick = function(event) {
    if (event.target == modal) {
        checkmodal.style.display = "none";
    }
}
  • April 13, 2017
  • Like
  • 0
I have generated Enterprise wsdl from one of my Developer org and tried generating apex class from that wsdl by logging into other develope org.

Its not showing any error while parsing but generating the following error when i click on generate.

Unsupported schema type: {http://www.w3.org/2001/XMLSchema}anyType

Did anybody come across this? If so please help it out .
Is it possible to load a soql returned list to be loaded into a visualforce page with multiple pages containing the list
i have a Del button in page and when i click on Del the pagereference section delCont is not called..instead it is getUserName method and closing after that..kindly suggest

page
-------

<apex:commandlink value="Del" action="{!delCont}" id="all">
                       <apex:param name="contIdParam" value="{!user.UserOrGroupId}" assignTo="{!contIdChosen}"/>                  
                     </apex:commandlink>

Controller
--------------

public class WV_ManualShareRead {
  
   public List<Scheme__Share> users;
   public List<User> userName;
   public list<id> useridlist{get;set;}  
  
 
  
   public String contIdChosen {get; set;}

   public WV_ManualShareRead()
   {
    useridList = new list<id>(); 
         
   }
   
   
    public List<Scheme__Share> getUsers()
    {       
        if(users == null)
        {
            users= [select UserOrGroupId from Scheme__Share where ParentId= :ApexPages.currentPage().getParameters().get('parentId')];
            system.debug('----------------My ID is------------------'+users);            
          
            // return users;
            for(Scheme__Share  X:users ){
            id value=X.UserOrGroupId;
             useridlist.add(value);          
            }
           
            return users;                      
         }
         return null;   
    }
   
    public List<User> getUserName()
    {
   
      if(useridlist != null && useridlist.size() > 0)
           {               
               userName = [SELECT Name FROM user WHERE id in :useridlist];
               system.debug('--------------Name is---------------'+userName);
               return userName;
               }
           
        return null;
    }
  
  
    public PageReference delCont()
    {
  
     system.debug('----------------------------------------Test Me------------------------------');
     Id id = System.currentPageReference().getParameters().get('parentId');
     Scheme__Share toDel=new Scheme__Share(id=contIdChosen );
     system.debug('----------Id is------------'+contIdChosen );
     //delete todel;
     //setupContacts();  
     PageReference nextpage1 = new PageReference('/apex/share/WV_SharingDetails?parentId='+id);
     return nextpage1;
    }
   
  
  
   
   
}
How To Convert String Lowercase to Uppercase In Vf page
HI,
Ihave following VF page
<apex:page standardController="account" extensions="searchform">  
  <apex:form >  
 <apex:inputText value="{!searchstring}" label="Input"/>   
  <apex:commandButton value="Search records" action="{!search}"/>  
  <apex:commandButton value="Clear records" action="{!search}"/>  
   <apex:pageBlock title="Search Result">  
    <apex:pageblockTable value="{!acc}" var="a">  

     <apex:column >  
      <apex:outputlink value="https://cochlear--guest1.cs8.my.salesforce.com/{!a.id}">{!a.Name}</apex:outputlink>  
    
     </apex:column>  
      
      <apex:column value="{!a.personEmail}"/> 
       <apex:column value="{!a.phone}"/> 
       <apex:column value="{!a.personMobilephone}"/>
     
        
       
       
  
    </apex:pageBlockTable>  

       
   </apex:pageBlock>   
  </apex:form>  

 </apex:page>
basically it does searches when i open the page, however what i like to include is another button on it that when clicked will let me create custom object
Person__c where it will have only first name, last name and Email address how can i do this?
my controller is
public with sharing class searchform {  
   public list <account> acc {get;set;}  
   public list <Install_Base__c> ib {get;set;}  
   public string searchstring {get;set;}  
   public searchform(ApexPages.StandardController controller) {  
   }  
   public void search(){  
     string searchquery='select name,phone,personEmail,PersonMobilePhone,Latest_Fitting_Date__c from account where name like \'%'+searchstring+'%\' Limit 20';  
     acc= Database.query(searchquery);  
   }  
   public void clear(){  
   acc.clear();  
   }  
  

 }

how is it possible, also
is there  a way to display on that page most recent Person Added to that account? 
any code would be greatly appreciated
like we  use string, integer for red and 10 ,If i want  to include a description about an colur (1 paragraph) which datatype type can i use?
Hi,

Kindly suggest the best practice to configure Authentication details (like username / password) inside Salesforce for REST call out using HttpRequest class.

User-added image