'Get the ID of the target record of a S3Request
@param r: the S3Request'

@staticmethod
def _record_id(r):

    master_id = r.id
    if r.component:
        component = r.component
        component_id = r.component_id
        link = r.link
        if ((not component.multiple) and (not component_id)):
            table = component.table
            pkey = table._id.name
            component.load(start=0, limit=1)
            if len(component):
                component_id = component.records().first()[pkey]
                if (link and master_id):
                    r.link_id = link.link_id(master_id, component_id)
                r.component_id = component_id
                component.add_filter((table._id == component_id))
        if ((not link) or r.actuate_link()):
            return component_id
        else:
            return r.link_id
    else:
        return master_id
    return None
