• Swetha B 7
  • NEWBIE
  • 30 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 5
    Replies
I have an Email to Case set up. Details coming into the body of the email. Need to Parse that Case Description Info into fields in Case. 

Email to the case is set up. The detail comes into the description: 

Contact Form

A user submitted the following information on the Contact us page

Name: XXXX

Phone: XXXX

Email: XXXX

Question/Comments: 

I have fields for each option and I need to pass the information into those fields. the format is the same every time. 

Please correct the trigger logic or provide me the solution for it.

trigger parsingemail on Case (before insert) {
 for(Case C:trigger.new){
        if(C.Subject!=Null && C.Subject.Contains('Contact Form')==True){
        if(C.Description!='' && C.Description.length()>0){
            String data=C.Description;
            C.SuppliedName=data.substringBetween('Name:', 'Phone:'); 
            C.SuppliedPhone=data.substringBetween('Phone:', 'Email:');
            C.SuppliedEmail=data.substringBetween('Email:', 'Question / Comment:');    
            update C;
            }
        }
     }
}

 
Trigger
 
trigger Attchementsharing on ContentDocumentLink (before insert) 
{
    Set<Id> Ids = new Set<Id>();
    for (ContentDocumentLink cdl : trigger.new) {
        String id = cdl.LinkedEntityId;
        if (id.substring(0,3) == '02s') {
            Ids.add(Id);   
        }
        else if (id.substring(0,3) == '500'&& cdl.visibility !='AllUsers') {
            cdl.visibility ='AllUsers';
        }     
    } 
    Map<ID, EmailMessage> m = new Map<ID, EmailMessage>([SELECT Id, RelatedToId FROM EmailMessage where Id IN:Ids]);
    List<ContentDocumentLink> docs = new  List<ContentDocumentLink>();
    for (ContentDocumentLink cdl : trigger.new) {
        String id = cdl.LinkedEntityId;
        if (id.substring(0,3) == '02s') {
            ContentDocumentLink sr = new ContentDocumentLink();
            sr.sharetype = 'I';
            sr.visibility = 'AllUsers';
            sr.ContentDocumentId = cdl.ContentDocumentId;
            sr.LinkedEntityId = m.get(Id).RelatedToId ;
            docs.add(sr);
        }
    }
    If (docs.size()>0){
        
        Insert docs;
    }  
}
Test Class: Current Code Coverage is 55%, Please help me to get 100%
 
@IsTest
public class Attachementsharing_Test {
    
    static testmethod void testmethod1(){
        Test.startTest();
        Case cs = new Case(SuppliedName='test Case',SuppliedEmail='Test@test.com', Category__c='Client');
        insert cs;
        ContentVersion content=new ContentVersion(); 
        content.Title='Header_Picture1'; 
        content.PathOnClient='/' + content.Title + '.jpg'; 
        Blob bodyBlob=Blob.valueOf('Unit Test ContentVersion Body'); 
        content.VersionData=bodyBlob; 
        //content.LinkedEntityId=sub.id;
        content.origin = 'H';
        insert content;
        ContentDocumentLink sr=new ContentDocumentLink();
        sr.LinkedEntityId=cs.id;
        sr.contentdocumentid=[select contentdocumentid from contentversion where id =: content.id].contentdocumentid;
        sr.ShareType = 'I';
        sr.Visibility = 'AllUsers'; 
        insert sr;
        Test.stopTest();
        
    }
}

 
Please help code coverage for my trigger

Apex Trigger

trigger AccountAddressTrigger on Apartment_Property__c (before insert, before update) {

 Set<String> reviewList = new Set<String>();  

 for(Apartment_Property__c a : trigger.new) {
        if( a.multi__c!= null){
            List<String> review = a.multi__c.split(';');
            reviewList.addAll(review);
        }        
           string reviewLogs = '';
           if(reviewList.size()>0) {
             
             for(string r: reviewList) {
                 if(r == 'A') {
                     reviewLogs += Label.Test+'\n';
                 }                
                 if(r == 'B') {
                    reviewLogs += Label.Test1+'\n';
                 }
               
                 if(r == 'c') {
                    reviewLogs += Label.Test3+'\n';
                 }
            }

        }
               a.Longtext__c = reviewLogs;
    }
}
Test Class: Written below test class but am not able to code coverage, Please help  

@isTest
public class AccountAddressTrigger {
    public static testmethod void utilitytestACTIVITY() {

    list<Apartment_Property__c> Acc = new list<Apartment_Property__c>();
        Apartment_Property__c obj = new Apartment_Property__c();
        obj.multi__c ='abe';
        obj.Longtext__c  ='xyz';
        Acc.add(obj);
        insert Acc;
}
}

Thnaks for the help!
Dear friends,

how to display object related attachments into Visualforce page.

Thanks for your quick response!
Please suggest my following scenario

1. I would like to populate Live weather update from weather.com to visualforce page(Test Page) based on current user zipcode.
2. So based on user's zipcode find from above point 1, we need to pull record details from salesforce to our visualforce page(Test page).  
3. also based on zipcode, we need to pull video related to the zipcode from salesforce to visualforce page(Test Page)

Note: In Salesfporce custom object we have created records for each individual zip code and uploaded video in notes and attachment.

Appericiate for your quick reposponse.
Thank you!
I have an Email to Case set up. Details coming into the body of the email. Need to Parse that Case Description Info into fields in Case. 

Email to the case is set up. The detail comes into the description: 

Contact Form

A user submitted the following information on the Contact us page

Name: XXXX

Phone: XXXX

Email: XXXX

Question/Comments: 

I have fields for each option and I need to pass the information into those fields. the format is the same every time. 

Please correct the trigger logic or provide me the solution for it.

trigger parsingemail on Case (before insert) {
 for(Case C:trigger.new){
        if(C.Subject!=Null && C.Subject.Contains('Contact Form')==True){
        if(C.Description!='' && C.Description.length()>0){
            String data=C.Description;
            C.SuppliedName=data.substringBetween('Name:', 'Phone:'); 
            C.SuppliedPhone=data.substringBetween('Phone:', 'Email:');
            C.SuppliedEmail=data.substringBetween('Email:', 'Question / Comment:');    
            update C;
            }
        }
     }
}

 
Trigger
 
trigger Attchementsharing on ContentDocumentLink (before insert) 
{
    Set<Id> Ids = new Set<Id>();
    for (ContentDocumentLink cdl : trigger.new) {
        String id = cdl.LinkedEntityId;
        if (id.substring(0,3) == '02s') {
            Ids.add(Id);   
        }
        else if (id.substring(0,3) == '500'&& cdl.visibility !='AllUsers') {
            cdl.visibility ='AllUsers';
        }     
    } 
    Map<ID, EmailMessage> m = new Map<ID, EmailMessage>([SELECT Id, RelatedToId FROM EmailMessage where Id IN:Ids]);
    List<ContentDocumentLink> docs = new  List<ContentDocumentLink>();
    for (ContentDocumentLink cdl : trigger.new) {
        String id = cdl.LinkedEntityId;
        if (id.substring(0,3) == '02s') {
            ContentDocumentLink sr = new ContentDocumentLink();
            sr.sharetype = 'I';
            sr.visibility = 'AllUsers';
            sr.ContentDocumentId = cdl.ContentDocumentId;
            sr.LinkedEntityId = m.get(Id).RelatedToId ;
            docs.add(sr);
        }
    }
    If (docs.size()>0){
        
        Insert docs;
    }  
}
Test Class: Current Code Coverage is 55%, Please help me to get 100%
 
@IsTest
public class Attachementsharing_Test {
    
    static testmethod void testmethod1(){
        Test.startTest();
        Case cs = new Case(SuppliedName='test Case',SuppliedEmail='Test@test.com', Category__c='Client');
        insert cs;
        ContentVersion content=new ContentVersion(); 
        content.Title='Header_Picture1'; 
        content.PathOnClient='/' + content.Title + '.jpg'; 
        Blob bodyBlob=Blob.valueOf('Unit Test ContentVersion Body'); 
        content.VersionData=bodyBlob; 
        //content.LinkedEntityId=sub.id;
        content.origin = 'H';
        insert content;
        ContentDocumentLink sr=new ContentDocumentLink();
        sr.LinkedEntityId=cs.id;
        sr.contentdocumentid=[select contentdocumentid from contentversion where id =: content.id].contentdocumentid;
        sr.ShareType = 'I';
        sr.Visibility = 'AllUsers'; 
        insert sr;
        Test.stopTest();
        
    }
}

 
Please help code coverage for my trigger

Apex Trigger

trigger AccountAddressTrigger on Apartment_Property__c (before insert, before update) {

 Set<String> reviewList = new Set<String>();  

 for(Apartment_Property__c a : trigger.new) {
        if( a.multi__c!= null){
            List<String> review = a.multi__c.split(';');
            reviewList.addAll(review);
        }        
           string reviewLogs = '';
           if(reviewList.size()>0) {
             
             for(string r: reviewList) {
                 if(r == 'A') {
                     reviewLogs += Label.Test+'\n';
                 }                
                 if(r == 'B') {
                    reviewLogs += Label.Test1+'\n';
                 }
               
                 if(r == 'c') {
                    reviewLogs += Label.Test3+'\n';
                 }
            }

        }
               a.Longtext__c = reviewLogs;
    }
}
Test Class: Written below test class but am not able to code coverage, Please help  

@isTest
public class AccountAddressTrigger {
    public static testmethod void utilitytestACTIVITY() {

    list<Apartment_Property__c> Acc = new list<Apartment_Property__c>();
        Apartment_Property__c obj = new Apartment_Property__c();
        obj.multi__c ='abe';
        obj.Longtext__c  ='xyz';
        Acc.add(obj);
        insert Acc;
}
}

Thnaks for the help!