+ Start a Discussion
Shubhashesh MisraShubhashesh Misra 
<apex:page showHeader="false" sidebar="false" renderAs="pdf" applyBodyTag="false"  standardStylesheets="false">
    <head>
        <style>  
        </style>
    </head>
    <apex:form >
        <body data-new-gr-c-s-loaded="14.991.0" spellcheck="false">
            <p style="text-align: center;"><strong>Test Pdf </strong><br /><strong>INFORMATION </strong></p>
            <div style="{!IF((1==1), 'display:block', 'display:none')}">
                <p>TO:&nbsp; <strong>Moblee, LLC</strong><br /><strong>&nbsp; &nbsp; &nbsp; &nbsp; There is </strong><br /><strong>&nbsp; &nbsp; &nbsp; &nbsp; Mount BSR</strong></p>
            </div>
            
            <div style="{!IF((1==2), 'display:block', 'display:none')}">
                <p>TO:&nbsp; <strong>Task, LLC</strong><br /><strong>&nbsp; &nbsp; &nbsp; &nbsp; PO 538643254</strong><br /><strong>&nbsp; &nbsp; &nbsp; &nbsp; hostel</strong></p>
            </div>
            
            <p>RE:<span style="white-space:pre;">&nbsp; &nbsp;&nbsp;</span>Patient Name: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</p>
            <p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Date of Birth: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Number: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>
            <p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;I authorize and request the disclosure of all protected information for the purpose of review and evaluation in connection with a legal claim. I expressly request that the designated record custodian or agent of the covered  under entity identified above disclose full and complete protected medical information including the following:</p>
            
            <p>I love the feel of wood curls flying off the lathe as I begin to shape the log in front of me. The sound of scraping changes based on the wetness of the wood, the speed at which the lathe is turning, and the type of cut I am making. The smell and feel of wet wood being turned are unique. The water is sprayed out as I cut through the different layers of wood. A log can turn into anything one's imagination can think of with the right set of hands-on tools. I have those hands and imagination. I use all of my senses and intuition to create a beautiful object. That is why I enjoy turning wood.</p>
            <p>Twenty-five stars were neatly placed on the piece of paper. There was room for five more stars but they would be difficult ones to earn. It had taken years to earn the first twenty-five, and they were considered the "easy" ones.</p>
            <p>______________________________________________________________________________<br />Name</p>
            <p>______________________________________________________________________________<br />Law </p>
            <p>______________________________________________________________________________<br />Street Address<br /></p>
            <p>The alarm went off at exactly 6:00 AM as it had every morning for the past five years. Barbara began her morning and was ready to eat breakfast by 7:00 AM. The day appeared to be as normal as any other, but that was about to change. In fact, it was going to change at exactly 7:23 AM.</p>
            <ul>
                <li>I have a right to revoke .</li>
                <li>The information released in response </li>
                <li>My treatment in payment for my treatment.</li>
            </ul>
            <p>Then came the night of the first falling star. It was seen early in the morning, rushing over Winchester eastward, a line of flame high in the atmosphere. Hundreds must have seen it and taken it for an ordinary falling star. It seemed that it fell to earth about one hundred miles east of him.</p>
            <p>Signature of Patient / Legally Authorized Representative<span style="white-space:pre;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span>Date</p>
            <p>Signature<span style="white-space:pre;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;</span>Date</p>
        </body>
    </apex:form>
</apex:page>Here is Pdf
Best Answer chosen by Shubhashesh Misra
Suraj Tripathi 47Suraj Tripathi 47
Hi Shubhasheesh Mishra,

Add border for page in style tag
Here is code:

<style> 
@page {
size:A4 portrait;
border: 2px solid black;    
}
</style> 

Here is a pdf with the border:

Pdf with border

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Suraj Tripathi
SrinivasSrinivas 

How to add try catch for error handling for the below code

 

global class updatePolicyStatusSchedule implements Schedulable {
    global void execute(SchedulableContext ctx) {
        updatePolicyStatus();
    }
    
    public void updatePolicyStatus() {
        List<Policy__c> expiredInForcePolicies = [SELECT Id, Status__c, Policy_End_Date__c, Policy_Effective_Date__c
                                                  FROM Policy__c
                                                  WHERE (Policy_End_Date__c <= TODAY AND Status__c != 'Expired' AND Status__c != 'Terminated')
                                                  OR (Policy_Effective_Date__c <= TODAY AND Policy_End_Date__c > TODAY AND Status__c NOT IN ('In Force','In-Force - Non-Renewing'))];

        List<Policy__c> updateExpiredInForcePolicies = new List<Policy__c>();
        

        for(Policy__c policy : expiredInForcePolicies){
            if((policy.Policy_End_Date__c<=System.today() && policy.Status__c!='Expired' && policy.Status__c!='Terminated') && !(policy.Policy_Effective_Date__c <= System.today() && policy.Policy_End_Date__c > System.today() && (policy.Status__c!='In Force' || policy.Status__c!='In-Force - Non-Renewing'))){
                policy.Status__c = 'Expired';
            }

            if(!(policy.Policy_End_Date__c<=System.today() && policy.Status__c!='Expired' && policy.Status__c!='Terminated') && (policy.Policy_Effective_Date__c <= System.today() && policy.Policy_End_Date__c > System.today() && (policy.Status__c!='In Force' || policy.Status__c!='In-Force - Non-Renewing'))){
                policy.Status__c = 'In Force';
            }
            
            updateExpiredInForcePolicies.add(policy);
        }
    if(!updateExpiredInForcePolicies.isEmpty()){
            Database.update(updateExpiredInForcePolicies);  
        }
    }
}


Thanks In advance

Best Answer chosen by Srinivas
CharuDuttCharuDutt
Hii Srinivas
Try Below  Code
global class updatePolicyStatusSchedule implements Schedulable {
    global void execute(SchedulableContext ctx) {
        updatePolicyStatus();
    }
    
    public void updatePolicyStatus() {
        List<Policy__c> expiredInForcePolicies = [SELECT Id, Status__c, Policy_End_Date__c, Policy_Effective_Date__c
                                                  FROM Policy__c
                                                  WHERE (Policy_End_Date__c <= TODAY AND Status__c != 'Expired' AND Status__c != 'Terminated')
                                                  OR (Policy_Effective_Date__c <= TODAY AND Policy_End_Date__c > TODAY AND Status__c NOT IN ('In Force','In-Force - Non-Renewing'))];

        List<Policy__c> updateExpiredInForcePolicies = new List<Policy__c>();
        

        for(Policy__c policy : expiredInForcePolicies){
            if((policy.Policy_End_Date__c<=System.today() && policy.Status__c!='Expired' && policy.Status__c!='Terminated') && !(policy.Policy_Effective_Date__c <= System.today() && policy.Policy_End_Date__c > System.today() && (policy.Status__c!='In Force' || policy.Status__c!='In-Force - Non-Renewing'))){
                policy.Status__c = 'Expired';
            }

            if(!(policy.Policy_End_Date__c<=System.today() && policy.Status__c!='Expired' && policy.Status__c!='Terminated') && (policy.Policy_Effective_Date__c <= System.today() && policy.Policy_End_Date__c > System.today() && (policy.Status__c!='In Force' || policy.Status__c!='In-Force - Non-Renewing'))){
                policy.Status__c = 'In Force';
            }
            
            updateExpiredInForcePolicies.add(policy);
        }
    if(!updateExpiredInForcePolicies.isEmpty()){
	try {
 
            Database.update(updateExpiredInForcePolicies);  
		} catch(DmlException e) {
			System.debug('The following exception has occurred: ' + e.getMessage());
		}
	
        }
    }
}
Please Mark It As Best Answer If It Helps
Thank You! 
Hitesh KhannaHitesh Khanna 
"User cannot change status to invoicing if previous status was Pharma Payment, Member Payout, Payment Processing, or Complete".......(these are the picklist values) .


I tried this..but its not working.


IF(ISPICKVAL(Status__c,'Invoicing'), 
    ISPICKVAL(Status__c, 'Pharma Payment') ||
    ISPICKVAL(Status__c, 'Member Payout') ||
    ISPICKVAL(Status__c, 'Payment Processing') ||
    ISPICKVAL(Status__c, 'Complete')
 ,
false )



Response will be appreciated.


 
Best Answer chosen by Hitesh Khanna
CharuDuttCharuDutt
Hii Hitesh
Try Below Validation Rule
AND(ISPICKVAL(Status__c,'Invoicing') ,
OR( 
NOT(ISPICKVAL(PRIORVALUE(Status__c),'Pharma Payment')), 
NOT(ISPICKVAL(PRIORVALUE(Status__c),''Member Payout')),
NOT(ISPICKVAL(PRIORVALUE(Status__c),'Payment Processing')),
NOT(ISPICKVAL(PRIORVALUE(Status__c),'Complete'))))
Please Mark It As Best Answer If It Helps
Thank You! 
Best Answer chosen by Raghav T
CharuDuttCharuDutt
Hii Raghav
Try  Below Trigger
trigger SumAmountOpp on Opportunity (After Insert,After Update,After Delete) {
 List<Account> accList=new List<Account>();

    Set<Id> setAccIds = new Set<Id>();
    if(Trigger.isInsert){
         if(trigger.isAfter){
        for(Opportunity con : Trigger.new){
            if(con.AccountId != null && && Con.StageName != 'Closed Won' && con.StageName != 'Closed Lost' && con.StageName != 'Cancelled'){
            setAccIds.add(con.AccountId);
            	}
			}
		}
    } 
    system.debug('setAccIds ==> '+setAccIds);
    if(Trigger.isUpdate){
         if(trigger.isAfter){
        for(Opportunity con : Trigger.new){ 
            if(con.AccountId!=Trigger.oldMap.get(con.Id).AccountId && Con.StageName != 'Closed Won' && con.StageName != 'Closed Lost' && con.StageName != 'Cancelled'){
               	setAccIds.add(con.AccountId);
                setAccIds.add(Trigger.oldMap.get(con.Id).AccountId);
            	}
            
			}        
        }
    }
    if(Trigger.isDelete){
        if(trigger.isAfter){
        for(Opportunity con : Trigger.old) { 
            if(con.AccountId != null && con.StageName != 'Closed Won' && con.StageName != 'Closed Lost' && con.StageName != 'Cancelled'){
            setAccIds.add(con.AccountId);
            	}
        	}
        }
    }    
    for(Account acc :[Select id,Total_opp__c ,(Select id,Name,Amount from Opportunities where StageName != 'Closed Won' AND StageName != 'Closed Lost' AND StageName != 'Cancelled') from Account where Id in : setAccIds]){
			
        acc.Total_opp__c = acc.Opportunities.size();
        acclist.add(acc);
        
    }
    if(acclist.size()>0){
        update accList;     
    }
    
}
Please Mark It As Best Answer If It Helps
Thank You! 
Maok kinesleMaok kinesle 
Original code:
global class LightningForgotPasswordController {

    public LightningForgotPasswordController() {

    }

    @AuraEnabled
    public static String forgotPassword(String username, String checkEmailUrl) {
        try {
            Site.forgotPassword(username);
            ApexPages.PageReference checkEmailRef = new PageReference(checkEmailUrl);
            if(!Site.isValidUsername(username)) {
                return Label.Site.invalid_email;
            }
            aura.redirect(checkEmailRef);
            return null;
        }
        catch (Exception ex) {
            return ex.getMessage();
        }
    }

    @AuraEnabled
    global static String setExperienceId(String expId) {    
        // Return null if there is no error, else it will return the error message 
        try {
            if (expId != null) {
                Site.setExperienceId(expId);               
            }
            return null; 
        } catch (Exception ex) {
            return ex.getMessage();            
        }        
    } 
}

Test class:
@IsTest(SeeAllData = true)
public with sharing class LightningForgotPasswordControllerTest {

 /* Verifies that ForgotPasswordController handles invalid usernames appropriately */
 @IsTest
 static void testLightningForgotPasswordControllerInvalidUserName() {
  System.assertEquals(LightningForgotPasswordController.forgotPassword('fakeUser', 'http://a.com'), Label.Site.invalid_email);
  System.assertEquals(LightningForgotPasswordController.forgotPassword(null, 'http://a.com'), Label.Site.invalid_email);
  System.assertEquals(LightningForgotPasswordController.forgotPassword('a', '/home/home.jsp'), Label.Site.invalid_email);
 }

 /* Verifies that null checkEmailRef url throws proper exception. */
 @IsTest
 static void testLightningForgotPasswordControllerWithNullCheckEmailRef() {
  System.assertEquals(LightningForgotPasswordController.forgotPassword('a', null), 'Argument 1 cannot be null');
  System.assertEquals(LightningForgotPasswordController.forgotPassword('a@salesforce.com', null), 'Argument 1 cannot be null');
 }

 /* Verifies that LightningForgotPasswordController object is instantiated correctly. */
 @IsTest
 static void LightningForgotPasswordControllerInstantiation() {
  LightningForgotPasswordController controller = new LightningForgotPasswordController();
  System.assertNotEquals(controller, null);
 }
}
Best Answer chosen by Maok kinesle
CharuDuttCharuDutt
Hii Moak
Try Below Test Class 88% Coverage
@IsTest(SeeAllData = true)
public with sharing class LightningForgotPasswordControllerTest {

 /* Verifies that ForgotPasswordController handles invalid usernames appropriately */
 @IsTest
 static void testLightningForgotPasswordControllerInvalidUserName() {
  System.assertEquals(LightningForgotPasswordController.forgotPassword('fakeUser', 'http://a.com'), Label.Site.invalid_email);
  System.assertEquals(LightningForgotPasswordController.forgotPassword(null, 'http://a.com'), Label.Site.invalid_email);
  System.assertEquals(LightningForgotPasswordController.forgotPassword('a', '/home/home.jsp'), Label.Site.invalid_email);
     
     
   LightningForgotPasswordController.setExperienceId('FakeString');
 }

 /* Verifies that null checkEmailRef url throws proper exception. */
 @IsTest
 static void testLightningForgotPasswordControllerWithNullCheckEmailRef() {
  System.assertEquals(LightningForgotPasswordController.forgotPassword('a', null), 'Argument 1 cannot be null');
  System.assertEquals(LightningForgotPasswordController.forgotPassword('a@salesforce.com', null), 'Argument 1 cannot be null');
      LightningForgotPasswordController.setExperienceId(null);
 }

 /* Verifies that LightningForgotPasswordController object is instantiated correctly. */
 @IsTest
 static void LightningForgotPasswordControllerInstantiation() {
  LightningForgotPasswordController controller = new LightningForgotPasswordController();
  System.assertNotEquals(controller, null);
 }
}
Please Mark It As Best Answer If It Helps
Thank You! 

 
praveenreddy gaddam 10praveenreddy gaddam 10 
public static void UpdateCreatedBy(list<Visit> vst){
        Set<Id> ownerIdSet = new Set<Id>();
        for(Visit c : vst){
            ownerIdSet.add(c.OwnerId);
        }
        Map<Id,User> userMap = new  Map<Id,User>([Select Id,userrole.developername From User Where Id =: ownerIdSet]); 
        for (visit Vs: vst){
            if(userMap.containsKey(vs.OwnerId)){
                string roleName = userMap.get(vs.OwnerId).UserRole.developername;
                if(string.isBlank(roleName) || roleName == null) continue;
                if(roleName.contains('FSO')){
                    vs.CREATED_BY_retail__c     ='Retail FSO';
                }
                else if(roleName.contains('SO')){
                    vs.CREATED_BY_retail__c     ='Retail SO';
                }
                
               
            }
        }
    }
Best Answer chosen by praveenreddy gaddam 10
CharuDuttCharuDutt
Hii Praveenreddy
Try Below Test Class
@isTest
public class UpdateCreatedByTest {
    @isTest
    public static void unitTest(){
	list<Visit> lstVisit = new list<Visit>();
	 Profile p = [SELECT Id FROM Profile WHERE Name='Office Profile'];
        UserRole roleId  = [SELECT Id, Name FROM UserRole where Name = 'CEO'];
        User usr = new User(LastName = 'sample',
                            FirstName='sam',
                            Alias = 'simplSam',
                            Email = 'ssamsimple@asdf.com',
                            Username = 'ssamsimple@asdf.com',
                            ProfileId = p.id,
                            TimeZoneSidKey = 'GMT',
                            LanguageLocaleKey = 'en_US',
                            EmailEncodingKey = 'UTF-8',
                            LocaleSidKey = 'en_US',
                            UserRoleId = roleId
                           );
      
        insert usr;
        system.runAs(usr){
	
    Visit v = new Visit();
	/*fill required Fields*/
	lstVisit.Add(v);
	insert lstVisit;
	}
	
	ClassName.UpdateCreatedBy(lstVisit);
	
    }
}
Please Mark It As Best Answer If It Helps
Thank You! 
SambitNayakSambitNayak 
Hi,
I have added opportunity as a lookup in contact. I want my description on contact to be updated with the related opportunity's stage name. My following code is not working. Please let me know where I went wrong:

trigger populateOppStage on Contact (before insert, before update) {
   Set<ID> opps = New Set<ID>();
    for (contact con:trigger.new){
        opps.add(con.opportunity__r.Id);
    }
    Map<Id, String> mapOppToStage = New Map<Id, String>();
    for(opportunity opp:[SELECT ID, stagename 
                      FROM opportunity WHERE ID IN:opps]){
        mapOppToStage.put(opp.id, opp.stagename);
    }

    for (contact c:trigger.new){
        if(mapOppToStage.containsKey(c.opportunity__r.Id)){
                c.Description= mapOppToStage.get(c.Opportunity__r.id);
        }
    }
}
Best Answer chosen by SambitNayak
Maharajan CMaharajan C
Hi Nayak,

From trigger.new you can access only the current record references but you can't get the parent record details.

opportunity__r.Id  ==>  It's referring the parent details. So based on your code it will be null.

Simply you have to use the opportunity__c in code because this is will return the lookup parent id . 

Please try the below code:
 
trigger populateOppStage on Contact (before insert, before update) {
    Set<ID> opps = New Set<ID>();
    for (contact con:trigger.new){
        if(con.opportunity__c != null)
        	opps.add(con.opportunity__c);
    }
    Map<Id, String> mapOppToStage = New Map<Id, String>();
    for(opportunity opp:[SELECT ID, stagename 
                         FROM opportunity WHERE ID IN:opps]){
                             mapOppToStage.put(opp.id, opp.stagename);
                         }
    
    for (contact c:trigger.new){
        if(mapOppToStage.containsKey(c.opportunity__c)){
            c.Description= mapOppToStage.get(c.opportunity__c);
        }
    }  
}

Thanks,
Maharajan.C
kumar 197kumar 197 
<apex:page controller="FlightController">
    <apex:pageBlock title="Select Flights">
      <apex:form >
        <apex:pageBlockSection >
       <apex:pageBlockSectionItem >
       <apex:outputText value="Flights"/>
        <apex:selectList size="1" value="{! fosId }">
        <apex:selectOptions value="{! fosList }"/>
        <apex:actionSupport event="onchange" reRender="FL01"/>
         </apex:selectList>
        </apex:pageBlockSectionItem>
         </apex:pageBlockSection>
         </apex:form>   
         </apex:pageBlock>
          <apex:pageBlock id="FL01">
        <apex:detail subject="{!fosId}" relatedlist="True"/>
       <apex:relatedList list="Booking__c"/>      
    </apex:pageBlock>
</apex:page>
--------------------------------------------
public class FlightController {

    public List<SelectOption> flights = new List<SelectOption>();
    public Id fosId {get;set;}
    
    public List<SelectOption> getfosList(){
        for(Flight__c fos : [SELECT Id, Name,(SELECT Name,Id FROM Bookings__r  ORDER BY BoardingDate__c DESC) FROM Flight__c]){
            flights.add(new SelectOption(fos.Id, fos.Name));
        }
        return flights;
    }
}
Best Answer chosen by kumar 197
kumar 197kumar 197
Hi  CharuDutt i made few Changes and now i am getting 100% coverage.

@isTest
private class FlightControllerTest {
    @isTest static void myTest() {
        Flight__c f = new Flight__c();
        f.Name = 'Test Flight';
        insert f;
        Customer__c c = new Customer__c();
        c.Name = 'Testc';
        insert c;
        Booking__c b =new Booking__c();
        //  b.Name='Test Bookings';
        b.Flight__c = f.Id;
        b.Customer__c= c.Id;
        Insert b;
        pagereference testPage=page.FlightController;
        FlightController fc = new FlightController();
        fc.fosId = f.Id;
        fc.getfosList();
        
    }
}
kumar 197kumar 197 
trigger ContactCount on Contact (after insert, after update, after delete, after undelete) {
    
    if(Trigger.isinsert || Trigger.isupdate || trigger.isdelete || Trigger.isundelete){
       
        ContactCount.countcontacts(trigger.new,trigger.old);
        
    }
}

-----------
public class ContactCount {
    public static void countcontacts(List<contact> newcontact,List<contact> oldcontact){
     
        set<id> accids= new set<id>();
                try{
        if(newcontact !=null){
            for(Contact c:newcontact){
                if(c.AccountId!=null){
                accids.add(c.accountid);
                }
            }      
       }if(oldcontact!=null){
            for(Contact c:oldcontact){
                accids.add(c.accountid);
            }
       }
     List<Account> acc = [Select id, Number_of_Contacts__c,(Select id from Contacts) from Account where id IN: accids];
        if(acc!=null){
        for(Account accValue:acc){
            accValue.Number_of_Contacts__c = accValue.Contacts.size();
        } 
        }
        if(!acc.isempty()){
        update acc;
        }
        }
        catch(exception e){
            System.debug('Get Message'+e.getMessage());
        }
    } 
}
Best Answer chosen by kumar 197
CharuDuttCharuDutt
Hii Kumar
Try Below Test Class 100% Coverage!
@isTest
public class ContactCount Test {
@isTest
    public Static Void UnitTest(){
        list<Contact>lstCon = new list<Contact>();
        Account Acc = new account();
        Acc.name ='test';
        insert Acc;
        
        Account Acc2 = new account();
        Acc2.name ='test2';
        insert Acc2;
        
        for(Integer i=0;i<5;i++){
        Contact Con = new Contact();
        Con.LastName = 'TestCon'+i;
        Con.AccountId = Acc.Id;
            lstCon.add(Con);
        }
        Contact Con = new Contact();
        Con.LastName = 'TestCon';
        Con.AccountId = Acc.Id;
        Insert Con;
        insert lstCon;
      
        list<account> sacc  = [select id,Number_of_Contacts__cfrom Account where id = :Acc.Id];
         system.debug(sacc);
        Con.AccountId = Acc2.Id;
       
       
      	Update Con;
        
        list<account> sacc2  = [select id,Number_of_Contacts__cfrom Account where id = :Acc2.Id];
         system.debug(sacc2);
        list<account> sacc4  = [select id,Number_of_Contacts__cfrom Account where id = :Acc.Id];
         system.debug(sacc4);
Delete Con;
         list<account> sacc3 = [select id,Number_of_Contacts__cfrom Account where id = :Acc2.Id];
        system.debug(sacc3);
       
        
    }
}
Please Mark It As Best Answer If It Helps
Thank You!
EdCodeEdCode 
Could someone please confirm if Salesforce visibility works like in the following example and why? (By "why" I mean could you please explain Salesforce's rational underneath this behaviour?):

See this scenario/example below:
  1. John is the owner of an Opportunity record.
  2. OWD on Opportunity and Account is = Private.
  3. John shares, today, such Opportunity record with Amanda so that she has Read/Write access to that record.
  4. Next week the System Admin transfers John's Opportunity records (including the one shared with Amanda) to another user who is going to be John's successor (because John is moving on to work at another company).
  5. As soon as John stops being the owner of that Opportunity record that he shared, Amanda loses access to that record as well!
Could you please explain why is Salesforce behaving in such a way?
I mean, the fact that John is moving on to work for a different company and that his Accounts/Opportunities are transfered to a different Owner does not mean that Amanda stops being interested in accessing the records that John shared with here.

For a record to continue being manually shared with a user, is it necessary that the Owner who actually shared that record continue being the owner of that record?

Is this documented somewhere in SF Documentation?

Thank you very much.
 
Best Answer chosen by EdCode
EdCodeEdCode
I just found the answer on SF Documentation (https://help.salesforce.com/s/articleView?id=sf.granting_access_to_records.htm&type=5). 

I specifically says "If a user transfers ownership of a record, Salesforce deletes any manual shares created by the original record owner, which can cause users to lose access. When account ownership is transferred, manual shares created by the original account owner on child records, such as opportunities and cases, are also deleted."