• hatch hozzen
  • NEWBIE
  • 0 Points
  • Member since 2023

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
I am an Admin with no real Apex experience and need help to determine what exactly is happening in this Apex Trigger. I belive it is a trigger to share an Account record when some custom Shared With fields are populated. Trying to determine if we can do away with this trigger and utilize something simpler like Account Teams. Thanks!
 
public class ShareWithTriggerHandler {
    public static void afterInsert(Account[] accounts){
    List<AccountShare> sharesToadd = new List<AccountShare>();
    List<AccountShare> sharesToadd2 = new List<AccountShare>();
    List<AccountShare> sharesToadd3 = new List<AccountShare>();
    List<AccountShare> sharesToadd4 = new List<AccountShare>();
  AccountToContactSync acs = new AccountToContactSync();
  acs.UpdateSharedWith(accounts);
        for(Account acclist: [SELECT Id,Name,Shared_With2__c,Shared_With3__c,Shared_With4__c,Shared_With__c FROM Account WHERE Id IN : accounts])
            {
                if(acclist.Shared_With2__c != null)
                {
                // manualShareEdit(acclist.id,acclist.Shared_With2__c);
                AccountShare accShare2  = new AccountShare();
                accShare2.AccountId = acclist.id;
                accShare2.UserOrGroupId = acclist.Shared_With2__c;
                accShare2.AccountAccessLevel = 'Edit';
                accShare2.OpportunityAccessLevel = 'Read';
                accShare2.RowCause = Schema.AccountShare.RowCause.Manual;
                sharesToadd2.add(accShare2);
                // Database.insert(accShr,false);
                }
                if(acclist.Shared_With3__c != null)
                {
                // manualShareEdit(acclist.id,acclist.Shared_With3__c);
                AccountShare accShare3  = new AccountShare();
                accShare3.AccountId = acclist.id;
                accShare3.UserOrGroupId = acclist.Shared_With3__c;
                accShare3.AccountAccessLevel = 'Edit';
                accShare3.OpportunityAccessLevel = 'Read';
                accShare3.RowCause = Schema.AccountShare.RowCause.Manual;
                sharesToadd3.add(accShare3);
                }
                if(acclist.Shared_With4__c != null)
                {
                // manualShareEdit(acclist.id,acclist.Shared_With4__c);
                AccountShare accShare4  = new AccountShare();
                accShare4.AccountId = acclist.id;
                accShare4.UserOrGroupId = acclist.Shared_With4__c;
                accShare4.AccountAccessLevel = 'Edit';
                accShare4.OpportunityAccessLevel = 'Read';
                accShare4.RowCause = Schema.AccountShare.RowCause.Manual;
                sharesToadd4.add(accShare4);
                }
                if(acclist.Shared_With__c != null)
                {
                // manualShareEdit(acclist.id,acclist.Shared_With__c);
                AccountShare accShare  = new AccountShare();
                accShare.AccountId = acclist.id;
                accShare.UserOrGroupId = acclist.Shared_With__c;
                accShare.AccountAccessLevel = 'Edit';
                accShare.OpportunityAccessLevel = 'Read';
                accShare.RowCause = Schema.AccountShare.RowCause.Manual;
                sharesToadd.add(accShare);
                }
                system.debug('!!!!'+acclist);
            }
            if(!sharesToadd.isEmpty())
            {
            Database.insert(sharesToadd, false);
            }
            if(!sharesToadd2.isEmpty())
            {
            Database.insert(sharesToadd2, false);
            }
            if(!sharesToadd.isEmpty())
            {
            Database.insert(sharesToadd3, false);
            }
            if(!sharesToadd.isEmpty())
            {
            Database.insert(sharesToadd4, false);
            }

        }
    public static void afterUpdate(Account[] accounts,Map<Id,Account> oldMap)
        {
        List<AccountShare> sharesToDelete = new List<AccountShare>();
    System.debug('******BEGIN UpdateSharedWith******');
    AccountToContactSync acs = new AccountToContactSync();
    acs.UpdateSharedWith(accounts);
    System.debug('******END UpdateSharedWith******');
        for(AccountShare acclist1: [SELECT Id FROM AccountShare WHERE AccountId IN :trigger.oldMap.keyset() AND RowCause = 'Manual'])
            {
            sharesToDelete.add(acclist1);
            // List<AccountShare> sharesToDelete = [SELECT Id FROM AccountShare WHERE AccountId IN :trigger.oldMap.keyset() AND RowCause = 'Manual'];
            }
        if(!sharesToDelete.isEmpty())
            {
            Database.Delete(sharesToDelete, false);
            }
        List<AccountShare> sharesToadd = new List<AccountShare>();
        List<AccountShare> sharesToadd2 = new List<AccountShare>();
        List<AccountShare> sharesToadd3 = new List<AccountShare>();
        List<AccountShare> sharesToadd4 = new List<AccountShare>();
        for(Account acclist: [SELECT Id,Name,Shared_With2__c,Shared_With3__c,Shared_With4__c,Shared_With__c FROM Account WHERE Id IN : accounts])
            {
            if(acclist.Shared_With2__c != null)
                {
                // manualShareEdit(acclist.id,acclist.Shared_With2__c);
                AccountShare accShare2  = new AccountShare();
                accShare2.AccountId = acclist.id;
                accShare2.UserOrGroupId = acclist.Shared_With2__c;
                accShare2.AccountAccessLevel = 'Edit';
                accShare2.OpportunityAccessLevel = 'Read';
                accShare2.RowCause = Schema.AccountShare.RowCause.Manual;
                sharesToadd2.add(accShare2);
                // Database.insert(accShr,false);
                }
                if(acclist.Shared_With3__c != null)
                {
                // manualShareEdit(acclist.id,acclist.Shared_With3__c);
                AccountShare accShare3  = new AccountShare();
                accShare3.AccountId = acclist.id;
                accShare3.UserOrGroupId = acclist.Shared_With3__c;
                accShare3.AccountAccessLevel = 'Edit';
                accShare3.OpportunityAccessLevel = 'Read';
                accShare3.RowCause = Schema.AccountShare.RowCause.Manual;
                sharesToadd3.add(accShare3);
                }
                if(acclist.Shared_With4__c != null)
                {
                // manualShareEdit(acclist.id,acclist.Shared_With4__c);
                AccountShare accShare4  = new AccountShare();
                accShare4.AccountId = acclist.id;
                accShare4.UserOrGroupId = acclist.Shared_With4__c;
                accShare4.AccountAccessLevel = 'Edit';
                accShare4.OpportunityAccessLevel = 'Read';
                accShare4.RowCause = Schema.AccountShare.RowCause.Manual;
                sharesToadd4.add(accShare4);
                }
                if(acclist.Shared_With__c != null)
                {
                // manualShareEdit(acclist.id,acclist.Shared_With__c);
                AccountShare accShare  = new AccountShare();
                accShare.AccountId = acclist.id;
                accShare.UserOrGroupId = acclist.Shared_With__c;
                accShare.AccountAccessLevel = 'Edit';
                accShare.OpportunityAccessLevel = 'Read';
                accShare.RowCause = Schema.AccountShare.RowCause.Manual;
                sharesToadd.add(accShare);
                }
            }
            if(!sharesToadd.isEmpty())
            {
            Database.insert(sharesToadd, false);
            }
            if(!sharesToadd2.isEmpty())
            {
            Database.insert(sharesToadd2, false);
            }
            if(!sharesToadd.isEmpty())
            {
            Database.insert(sharesToadd3, false);
            }
            if(!sharesToadd.isEmpty())
            {
            Database.insert(sharesToadd4, false);
            }

        }
    
  /*  public static void manualShareEdit(Id recordId, Id userOrGroupId)
        {
        AccountShare accShr  = new AccountShare();
        accShr.AccountId = recordId;
        accShr.UserOrGroupId = userOrGroupId;
        accShr.AccountAccessLevel = 'Edit';
        accShr.OpportunityAccessLevel = 'Edit';
        accShr.RowCause = Schema.AccountShare.RowCause.Manual;
        Database.insert(accShr,false);
        }    */
    }

 
hello

   i write a test method for a controller.but i get only  71% code coverage.

  i am facing  problem to write the test method for get set method.please help me

 here is my code:
public class eiException extends exception{
    public String code{get; set;}
    public String text{get; set;}
    public String severity{get; set;}
    public String category{get; set;}
    public String subcategory{get; set;}
    public String dataState{get; set;}
    public Boolean retryAllowed{get; set;}
    public String additionalInformation{get; set;}
    
    public eiException(Dom.XmlNode node){
        dom.XmlNode p;
        
        p=node.getChildElement('code', eiEnvelope.namespace);
        if(p != null){code = p.getText();}
        
        p=node.getChildElement('text', eiEnvelope.namespace);
        if(p != null){text = p.getText();}
        
        p=node.getChildElement('severity', eiEnvelope.namespace);
        if(p != null){severity = p.getText();}
        
        p=node.getChildElement('category', eiEnvelope.namespace);
        if(p != null){category = p.getText();}
        
        p=node.getChildElement('subcategory', eiEnvelope.namespace);
        if(p != null){subcategory = p.getText();}
        
        p=node.getChildElement('dataState', eiEnvelope.namespace);
        if(p != null){dataState = p.getText();}
        
        p=node.getChildElement('retryAllowed', eiEnvelope.namespace);
        if(p != null){retryAllowed = p.getText().equalsIgnoreCase('true');}
        
        p=node.getChildElement('additionalInformation', eiEnvelope.namespace);
        if(p != null){additionalInformation = p.getText();}
        
    }
    
    public static testmethod void testeiException() {
    
        
        DOM.Document doc = new DOM.Document();
        dom.XmlNode envelope= doc.createRootElement('Envelope',null,null);
        dom.XmlNode body= envelope.addChildElement('code', null, null);

        eiException eiEx = new eiException(body);
      
    }
}

Hello,

        I want to do authentication from my java client. I got Rest API which authenticate using web Application client and its working fine. But my requirement is little bit different as I need to use normal java client which will authenticate me directly to Salesforce site.

        

 

Regards,

Deepak