• Stephen Piercey 5
  • NEWBIE
  • 5 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 5
    Replies
Hello,

when you click on a record, it show a button sharing, when we click on it, it shows the some sharing rules, but how are the rules in sharing populated,
for example, one of the record it show that, its been shared to XYS Group.
How is it populated
Hi

I have class which i have to cover more than 80%,i tried to cover it but some how am seeing few errors! Any help Greatly Appreciated!
Here am attching my class and test class!
public class Mailtemplate{
    public static Map<String,Email_notification__c> EMN = Email_notification__c.getAll();
    
    //Method to get all templates
    public static Map<String,String> method1(){
        Map<String,String> Templates = new Map<String,String>();
        String username = EMN.get('SIT').UserName__c;
        String password = EMN.get('SIT').Password__c;
        Boolean success;
        Blob headerValue = Blob.valueOf(username + ':' + password);
        String authorizationHeader = 'BASIC ' +
            EncodingUtil.base64Encode(headerValue);
        HttpRequest req = new HttpRequest();
        req.setHeader('Authorization', authorizationHeader);
        req.setHeader('Content-Type','application/json');
        req.setEndpoint('https://api.EF.com/v3/templates');
        req.setMethod('GET');
        try{
            
            //send request
            Http h = new Http();
            HttpResponse res = h.send(req);
            System.debug('Responce : '+ res.getBody());
            
            String responceBody = res.getBody();
            System.debug('Response from EMailnote:' + responceBody);
            ControllerJson obj = new ControllerJson();
            obj = (ControllerJson)ControllerJson.parseTemplate(responceBody);
            List<ControllerJson.mailtemp> lstObjTemp = (List<ControllerJson.mailtemp>) obj.templates;
            for(ControllerJson.mailtemp template : lstObjTemp)
            {
                System.debug('Template Id : '+ template.id +', Template Name : '+template.name);
                Templates.put(template.name,template.id);
            }
            
            
            
            //check response
            String status = res.getStatus();
            if(status.toUpperCase()=='OK'){
                success=true;
            }
            else{
                success=false;
            }
        }
        catch(Exception e){
            System.Debug(LoggingLevel.ERROR,'******  Template.');
            success=false;
        }
        
        return Templates;
    }    

    public static boolean method2(String toEmail){
        string Recipient = toEmail;
        string CC;
        string Subject;
        string Body;
        boolean Success;
           CC = 'testmail@gmail.com';
            subject = 'Test : Hello';
            Body = 'Hi';
            String requestBody='';
            requestBody += 'to[]='+EncodingUtil.urlEncode(Recp.meth(),'UTF-8');
            requestBody += '&to[]='+EncodingUtil.urlEncode('testmail@gmail.com','UTF-8');
            requestBody += '&from='+EncodingUtil.urlEncode('testmail@gmail.com','UTF-8');
            requestBody += '&fromname='+EncodingUtil.urlEncode('testmail','UTF-8');
            requestBody += '&subject='+EncodingUtil.urlEncode(subject,'UTF-8');
            requestBody += '&text='+EncodingUtil.urlEncode(Body.trim(),'UTF-8');
            requestBody += '&html='+EncodingUtil.urlEncode(Body.trim(),'UTF-8');
            requestBody += '&api_user='+EMN.get('SIT').UserName__c;
            requestBody += '&api_key='+EMN.get('SIT').Password__c;
            
            
            HttpRequest req = new HttpRequest();
            req.setEndpoint('https://Edf.com/api/mail.send.json');
            //req.setHeader('Content-Type','application/json');
            req.setMethod('POST');
            
            req.setBody(requestBody);
            
            try{
                
                //send request
                Http h = new Http();
                
                HttpResponse res = h.send(req);
                res.setHeader('Content-Type','application/json');
                System.debug('Response from mailtemp:' + res);
                
                //check response
                String status = res.getStatus();
                if(status.toUpperCase()=='OK'){
                    success=true;
                }
                else{
                    success=false;
                }
            }
            catch(Exception e){
                System.Debug(LoggingLevel.ERROR,'******  email.');
                success=false;
            }
        
        return success;
        
    }
    
    //Method to send Email using Template
    public static boolean method3(String str){
        string Recipient;
        string RecipientName;
        string to;
        string Subject;
        string Body;
        boolean Success;
        String requestBody='';
        
        system.debug('JsonString'+str);
        to = 'testmail12@gmail.com';
        Body = 'sample mail '; //Text Mandatory
        subject = ' ';
        
        requestBody += 'to[]='+EncodingUtil.urlEncode(to.trim(),'UTF-8');
        requestBody += '&x-smtpapi='+str;
        requestBody += '&from='+EncodingUtil.urlEncode('testmail@gmail.com','UTF-8');
        requestBody += '&fromname='+EncodingUtil.urlEncode('sample temp','UTF-8');
        requestBody += '&subject='+EncodingUtil.urlEncode(subject,'UTF-8');
        requestBody += '&text='+EncodingUtil.urlEncode(Body.trim(),'UTF-8');
        requestBody += '&html='+EncodingUtil.urlEncode(Body.trim(),'UTF-8');
        requestBody += '&api_user='+EMN.get('SIT').UserName__c;
        requestBody += '&api_key='+EMN.get('SIT').Password__c;
        
        
        system.debug('-----------------'+  requestBody);
        HttpRequest req = new HttpRequest();
        req.setEndpoint('https://mailtemp.com/api/mail.send.json');
        //req.setHeader('Content-Type','application/json');
        req.setMethod('POST');
        
        req.setBody(requestBody);
        
        try{
            
            //send request
            Http h = new Http();
            
            HttpResponse res = h.send(req);
            res.setHeader('Content-Type','application/json');
            System.debug('Response from mailtemp:' + res);
            
            //check response
            String status = res.getStatus();
            if(status.toUpperCase()=='OK'){
                success=true;
            }
            else{
                success=false;
            }
        }
        catch(Exception e){
            System.Debug(LoggingLevel.ERROR,'****** email.');
            success=false;
            
        }
        return success;
        
    }
    
    public static String method4(String date1, String date2){
        String requestBody='';
        String responceBody;
        requestBody += 'start_date='+EncodingUtil.urlEncode(startDate,'UTF-8'); 
        requestBody += '&end_date='+EncodingUtil.urlEncode(endDate,'UTF-8'); 

        requestBody += '&api_user='+EMN.get('SIT').UserName__c;
        requestBody += '&api_key='+EMN.get('SIT').Password__c;

              
        HttpRequest req = new HttpRequest();
        req.setEndpoint('https://api.mailtemp.com/api/bounces.get.json');
        req.setMethod('GET');
        req.setHeader('Content-Type','application/x-www-form-urlencoded');
        req.setBody(requestBody);
        req.setHeader('Content-Length',String.valueof(requestBody.length()));
        
        try{
            //send request
            Http h = new Http();
            System.HttpResponse res = h.send(req);
            responceBody= res.getBody();
            
        }
        catch(Exception e){
            
        }
        
        return responceBody;
    }

    
}
@isTest
private with sharing class Test_Mailtemplate {
  //public class MockHttpResponseGenerator implements HttpCalloutMock{
  
  static testMethod void Test_method1() {   
   string testmail;

    Email_notification__c EMN= new Email_notification__cEmail_notification__c();
        EMN.Name = 'test name';
        EMN.Username__c = 'testuname';
        EMN.Password__c = 'testpswd';
        Insert EMN; 
 
   Test.startTest();
   
   Mailtemplate rc = new Mailtemplate();
   Mailtemplate.method1();
    

  Test.stopTest();
        }
        
      static testMethod void Test_Method2() {     
      string testmail;
         Test.startTest();
        Mailtemplate.Method2(testmail);

        Test.stopTest();
        }
        
        static testMethod void Test_Method3() {    
         string testmail1; 
         Test.startTest();
        Mailtemplate.Method3(testmail1);
        
        Test.stopTest();
        }
       
        static testMethod void Test_Method4() {   
         string startdate;
         string enddate;  
         Test.startTest();
        Mailtemplate.Method4(startdate,enddate);

        Test.stopTest();
        }
      
   static testmethod void testMe() {
        Test.setMock(HttpCalloutMock.class, new Stubby());
        HttpRequest req = new HttpRequest();
        req.setEndpoint('http://123.63.33.43/blank/sms/user/urlsmstemp.php?');
        req.setMethod('GET');
        Http h = new Http();
        HttpResponse res = Mailtemplate.method1();
        String contentType = res.getHeader('Content-Type');
        System.assert(contentType == 'application/json');
        String actualValue = res.getBody();
        String expectedValue = '{"foo":"bar"}';
        System.assertEquals(actualValue, expectedValue);
        System.assertEquals(200,res.getStatusCode());

}
  
}




 
Hi all,

I am unable to get the code coverage for below trigger. All lines are covered except 8 and 9 lines.

Scinario: Only once record can be Active for a User. Leader__c is in Lookup-Relationship with User. Also if I update one record "Active__c = True" remaining records of that User should be updated (Active__c = False).
trigger OneRecordCanBeActive on Leader__c(after insert, before update) {

	if(checkRecursive.runOnce()){
		List<Leader__c> lList = new List<Leader__c>();
		List<Leader__c> gAccs = [select Id, Active__c, User__c from Leader__c where Id not in :Trigger.new and Active__c = True and User__c = :UserInfo.getUserId()];
			
			for(Leader__c l : gAccs){
				l.Active__c = False;
				lList.add(l);
			}
			update lList;
	}
}

My Test Class:
@isTest
private class OneRecordCanBeActive_Test {

	private static testMethod void test() {
	    
        Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];
        
        User u = new User();
            u.Alias = 'SysAdmin';
            u.Email='sysAdmin@testorg.com';
            u.EmailEncodingKey='UTF-8';
            u.LastName='Testing';
            u.LanguageLocaleKey='en_US';
            u.LocaleSidKey='en_US';
            u.ProfileId = p.Id;
            u.TimeZoneSidKey='America/Los_Angeles';
            u.UserName='gaccuser@testorg.com';
        Insert u;
            
        Leader__c l1 = new Leader__c();
            l1.Active__c = True ;
            l1.User__c = u.id;
        Insert l1;
        
        Leader__c l2 = new Leader__c();
            l2.Active__c = True ;
            l2.User__c = u.id;
        Insert l2;
		
        l1.Active__c = True ;
        Update l1;
	}

}

Thankyou.
  • August 31, 2016
  • Like
  • 0
An error has occurred while processing your request. The salesforce.com support team has been notified of the problem. If you believe you have additional information that may be of help in reproducing or correcting the error, please contact Salesforce Support. Please indicate the URL of the page you were requesting, any error id shown on this page as well as any other related information. We apologize for the inconvenience. 

Thank you again for your patience and assistance. And thanks for using salesforce.com!
Error ID: 1836710115-341721 (1204153959)



Above error is occurred while updating.
But Error has been gone when I inactive the trigger



Below is my trigger code
Helper class 
public class UpdateAction
{
    List<Case> newCaseListToUpdate;
    List<Case> oldCaseList;
    
    List<ID> productIdList;//List Collection for product obj.ID
    List<ID > srTypeIdList;//List Collection for srtype obj.ID
    List<ID> srSubTyeIdList;//List Collection for srsubtype obj.ID
    
    Map<String,Case_Configuration__c> caseConfigIdsWithCaseStage;
    Map<Case,ID> caseStepsOfcases;
    
    public UpdateAction(List<Case> newCaseListToUpdate,List<Case> oldCaseList)
    {
        this.newCaseListToUpdate=newCaseListToUpdate;
        this.oldCaseList=oldCaseList;
    }
    
    
    public Boolean isProductSRTypeOrSRSubTypeUpdated()
    {
        if(initUpdatedListOfProductSrTypeAndSRSubType()==true)
            return true;
        return false;
    }
    
    private Boolean initUpdatedListOfProductSrTypeAndSRSubType()
    {
        productIdList=new List<ID>();
        srTypeIdList=new List<ID>();
        srSubTyeIdList=new List<ID>();
        
        Boolean isNewDataFound=false;
        
        for(Integer i=0;i<newCaseListToUpdate.size();i++)
        {   
            Case newCase=newCaseListToUpdate[i];
            if(newCase.Product__c != oldCaseList[i].Product__c 
            || newCase.SR_Type__c != oldCaseList[i].SR_Type__c
            || newCase.SR_Sub_Type__c != oldCaseList[i].SR_Sub_Type__c) 
            {
                productIdList.add(newCase.Product__c );
                srTypeIdList.add(newCase.SR_Type__c );
                srSubTyeIdList.add(newCase.SR_Sub_Type__c );
                
                isNewDataFound=true;
            }
        }
        
        return isNewDataFound;
    }
    
    public void setCaseConfigAndCurrStage()
    {  
           // initCaseConfigMap();
       caseConfigIdsWithCaseStage=CaseConfigurationOperation.getCaseStageOfCaseConfig(productIdList,srTypeIdList,srSubTyeIdList);
       if(caseConfigIdsWithCaseStage!=null && caseConfigIdsWithCaseStage.size()>0)
       {
            for(Case cs:newCaseListToUpdate)
            {
                 //System.debug('insert keyyy='+key(cs));
                Case_Configuration__c caseConfig=caseConfigIdsWithCaseStage.get(CaseConfigurationOperation.caseKey(cs));
                if(caseConfig!=null)
                {
                    cs.Case_Configuration__c= caseConfig.Id;
                    cs.Current_Stage__c=caseConfig.Case_Steps__r[0].Case_Stage__c;
                }
            } 
        }
    }
    
    /*--    private void initCaseConfigMap()
    {
        try
        {
            caseConfigIdsWithCaseStage=new Map<String,Case_Configuration__c>();
            for(Case_Configuration__c caseConfig :
                                             [select Id,Product__r.Id,SR_Sub_Type__r.Id,SR_Type__r.Id,(select Case_Stage__c from Case_Steps__r where Name='001')
                                             from Case_Configuration__c 
                                             where Product__r.Id  In :productIdList and SR_Sub_Type__r.Id  In :srSubTyeIdList
                                             and SR_Type__r.Id In :srTypeIdList])
            {
                //System.debug(caseConfig.Product__r);
                if(isKeyNull(caseConfig)==false)
                    caseConfigIdsWithCaseStage.put(key(caseConfig),caseConfig);
            }
                                                     
        }
        catch(DMLException e)
        {    
            System.debug(e);
        }
    }
    
    private Boolean isKeyNull(Case_Configuration__c caseConfig)
    {
        if(caseConfig.Product__r.Id==null && caseConfig.SR_Type__r.Id==null && caseConfig.SR_Sub_Type__r.Id==null)
        {
            return true;
        }
        return false;
    }
    
    private static String key(Case cs) 
    {
         return cs.Product__c + '|' + cs.SR_Type__c + '|' + cs.SR_Sub_Type__c ;
    }

    private static String key(Case_Configuration__c caseConfig) 
    {
        return caseConfig.Product__r.Id + '|' + caseConfig.SR_Type__r.Id + '|' + caseConfig.SR_Sub_Type__r.Id ;
    }
        --*/
    
    public void updateSteps()
    {
        if(isCurrStepUpdated()==true)
        {
             
             System.debug('current step is updated');                                        
            Map<ID,case_step__c> currentCaseStepList=new  Map<ID,case_step__c>(
                                            [select ID,Next_Step__r.Id,Next_Step__r.Case_Stage__c
                                             from Case_Step__c 
                                             where Id In :caseStepsOfcases.values()]);
                                              System.debug('currentCaseStepList obj created'); 
                                              
                                              
            if(currentCaseStepList!=null && currentCaseStepList.size()>0)    
            {
                for(Case caseToUpdate:caseStepsOfcases.keySet())
                {
                    caseToUpdate.Previous_Status__c =caseToUpdate.Current_Status__c;
                    Case_Step__c currCaseStep=currentCaseStepList.get(caseToUpdate.Current_Step__c);
                    
                    if(currCaseStep!=null)
                    {
                        ID nextStepId=currCaseStep.Next_Step__r.Id;
                
                        if(nextStepId!=null)
                        {
                            caseToUpdate.Current_Stage__c=currCaseStep.Next_Step__r.Case_Stage__c;
                        }
                        else
                        {
                            System.debug('no next found at line 150');
                        }
                        
                        caseToUpdate.Current_Step__c=null;
                    }
                    else
                    {
                        System.debug('currCaseStep found null at 157');
                    }
                }
            }
            else
            {
                System.debug('currentCaseStepList fount null empty at 158');
            }
           
        }
        
    }
    
    private Boolean isCurrStepUpdated()
    {
        Boolean currStepUpdated=false;
        caseStepsOfcases=new Map<Case,ID>();
        for(Integer i=0;i<newCaseListToUpdate.size();i++)
        {   
            Case newCase=newCaseListToUpdate[i];
            if(newCase.Current_Step__c != oldCaseList[i].Current_Step__c) 
            {
                caseStepsOfcases.put(newCase,newCase.Current_Step__c);
                currStepUpdated=true;
            }
        }
        
        return currStepUpdated;
    }
}


Below is my trigger
trigger testCase on Case(before insert,before update)
{
    if(Trigger.isBefore)
    {
        if(Trigger.Isinsert )
        {
            new InsertAction(Trigger.new).setCaseConfigAndCurrStage();
        }//end of if
        
        if(Trigger.isupdate)
        {
            UpdateAction updateAct=new UpdateAction(Trigger.new,Trigger.old);
            
            if(updateAct.isProductSRTypeOrSRSubTypeUpdated()==true)
            {
                System.debug('updating config and curr stage');
                updateAct.setCaseConfigAndCurrStage();
            }
            updateAct.updateSteps();
            System.debug('trigger executed');
            
        
        }
       
    }//End of ISbefore.
}//end of trigg
I have followed a progression.

1.  I built Lightning components on the developer console, and the documentation shows.

     In order to keep snapshots of my work as I went, I copied and pasted to emails that I sent to myself. 

2.  I attended Midwest Dreaming, and discovered that my compatriots worked in Sublime and Eclipse, and connected to Salesforce. 

     That would allow me to use git, as I'm used to.  

3.  I tried Sublime 3 with MavensMate.  I got a complaint that TLS 1.0 wasn't supported, only TLS 1.1. 

4.  I looked into using Eclipse with the Force.com IDE.  It's not clear that environment supports building Lightning components conveniently.

5.  I discovered that if you go to salesforce...devcenter/lightning, they talk about a plug-in for Sublime.  Not a MavensMate plug-in.  One made by Salesforce.

So my question is:  Where can I go for reliable, convenient development of Lightning components?